History

Merge branch 'edno-master'

* edno-master: Add PHPUnit documentation (4.3)

Thibaut committed 11 years ago

Commit b77a16d2 parents acd915e f73f89c7 files · +136 −-2Browse files

Unified · Split

7 files
  1. assets/stylesheets/application.css.scss +1 −0
  2. assets/stylesheets/pages/_phpunit.scss +21 −0
  3. lib/docs/filters/phpunit/clean_html.rb +65 −0
  4. lib/docs/filters/phpunit/entries.rb +20 −0
  5. lib/docs/scrapers/phpunit.rb +31 −0
  6. public/icons/docs/phpunit/16.png +0 −0
  7. public/icons/docs/phpunit/16@2.png +0 −0
assets/stylesheets/application.css.scss+1−0
@@ -54,6 +54,7 @@ · 53 unmodified lines
54 'pages/nginx',54 'pages/nginx',
55 'pages/node',55 'pages/node',
56 'pages/php',56 'pages/php',
57 'pages/phpunit',
57 'pages/postgres',58 'pages/postgres',
58 'pages/rdoc',59 'pages/rdoc',
59 'pages/redis',60 'pages/redis',
assets/stylesheets/pages/_phpunit.scss+21−0
@@ -0,0 +1,21 @@
1._phpunit {
2 h1 {
3 margin-top: 0;
4 @extend %lined-heading;
5 }
6
7 h2.title {
8 @extend %block-heading;
9 }
10
11 .programlisting > pre { white-space: normal; }
12
13 .literal {
14 padding: 2px 4px;
15 color: #c7254e;
16 background-color: #f9f2f4;
17 border-radius: 4px;
18 }
19
20 div.warning { @extend %note, %note-red; }
21}
lib/docs/filters/phpunit/clean_html.rb+65−0
@@ -0,0 +1,65 @@
1module Docs
2 class Phpunit
3 class CleanHtmlFilter < Filter
4 def call
5 root_page? ? root : other
6 doc
7 end
8
9 def root
10 doc.inner_html = <<-HTML
11 <p>PHPUnit is a programmer-oriented testing framework for PHP.<br>
12 It is an instance of the xUnit architecture for unit testing frameworks.</p>
13 HTML
14 end
15
16 def other
17 # set root on appendix
18 @doc = doc.at_css('div.appendix')
19
20 # remove attributes 'style'
21 css('*').remove_attr('style')
22
23 # clean titles
24 css('div.titlepage').each do |node|
25 title = node.at_css('.title')
26 case title.name
27 when 'h1'
28 # remove 'Appendix X.' from top title
29 nodetitle = title.content
30 title.content = nodetitle.gsub(/Appendix \w+\. /, '')
31 when 'h2'
32 # set link anchors in entries (title level 2)
33 anchor = Nokogiri::XML::Node.new "a", @doc
34 anchor.content = title.content
35 anchor['id'] = title.content.downcase.gsub(/[^a-z]/, '')
36 title.content = ''
37 anchor.parent = title
38 end
39 node.replace title
40 end
41
42 # set anchor for internal references
43 css('p.title').each do |node|
44 anchor = Nokogiri::XML::Node.new "a", @doc
45 anchor.content = node.content
46 anchor['id'] = anchor.content[/\w+ [A-z0-9.]+/].downcase.parameterize
47 node.content = ''
48 anchor.parent = node
49 end
50
51 # clean internal references
52 css('a').each do |node|
53 page = node['href'][/([A-z.-]+)?#/, 1] if node['href']
54 if page then
55 page = page + '.html' unless page[/.*\.html/]
56 if Phpunit.initial_paths.include? page
57 node['href'] = node['href'].gsub(/#[A-z.-]+/, '#' + node.content.downcase.parameterize)
58 end
59 end
60 end
61
62 end
63 end
64 end
65end
lib/docs/filters/phpunit/entries.rb+20−0
@@ -0,0 +1,20 @@
1module Docs
2 class Phpunit
3 class EntriesFilter < Docs::EntriesFilter
4 def additional_entries
5 entries = []
6
7 if at_css('h1')
8 type = at_css('h1').content.gsub(/Appendix \w+\. /, '')
9
10 css('h2').each do |node|
11 name = node.content
12 id = name.parameterize
13 entries << [name, id, type]
14 end
15 end
16 entries
17 end
18 end
19 end
20end
lib/docs/scrapers/phpunit.rb+31−0
@@ -0,0 +1,31 @@
1module Docs
2 class Phpunit < UrlScraper
3 self.name = 'PHPUnit'
4 self.type = 'phpunit'
5 self.slug = 'phpunit'
6 self.version = '4.3'
7 self.base_url = 'https://phpunit.de/manual/4.3/en/'
8 self.initial_paths = %w(appendixes.assertions.html appendixes.annotations.html)
9
10 html_filters.push 'phpunit/entries', 'phpunit/clean_html', 'title'
11
12 options[:skip_links] = true
13
14 options[:title] = false
15 options[:root_title] = "#{self.name} #{self.version}"
16
17 options[:fix_urls] = ->(url) do
18 if self.initial_paths.include? url[/\/([A-z.-]+)#/, 1]
19 url = url[/#(.+)/, 1].downcase
20 url.gsub! /(\w+\.\w+)\.(\w+)/, '\1#\2'
21 end
22 url
23 end
24
25
26 options[:attribution] = <<-HTML
27 &copy; 2005&ndash;2014 Sebastian Bergmann<br>
28 Licensed under the Creative Commons Attribution 3.0 Unported License.
29 HTML
30 end
31end
public/icons/docs/phpunit/16.png+0−0

Binary file not shown.

public/icons/docs/phpunit/16@2.png+0−0

Binary file not shown.