From f73f89caddfc9957d6f85903413a41cd9956195c Mon Sep 17 00:00:00 2001 From: edno Date: Thu, 13 Nov 2014 00:40:03 +0530 Subject: [PATCH] Add PHPUnit documentation (4.3) --- assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_phpunit.scss | 21 ++++++++ lib/docs/filters/phpunit/clean_html.rb | 65 ++++++++++++++++++++++++ lib/docs/filters/phpunit/entries.rb | 20 ++++++++ lib/docs/scrapers/phpunit.rb | 31 +++++++++++ public/icons/docs/phpunit/16.png | Bin 0 -> 718 bytes public/icons/docs/phpunit/16@2.png | Bin 0 -> 1866 bytes 7 files changed, 138 insertions(+) create mode 100644 assets/stylesheets/pages/_phpunit.scss create mode 100644 lib/docs/filters/phpunit/clean_html.rb create mode 100644 lib/docs/filters/phpunit/entries.rb create mode 100644 lib/docs/scrapers/phpunit.rb create mode 100644 public/icons/docs/phpunit/16.png create mode 100644 public/icons/docs/phpunit/16@2.png diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 1014a649..eedd9700 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -54,6 +54,7 @@ 'pages/nginx', 'pages/node', 'pages/php', + 'pages/phpunit', 'pages/postgres', 'pages/rdoc', 'pages/redis', diff --git a/assets/stylesheets/pages/_phpunit.scss b/assets/stylesheets/pages/_phpunit.scss new file mode 100644 index 00000000..2cfd1935 --- /dev/null +++ b/assets/stylesheets/pages/_phpunit.scss @@ -0,0 +1,21 @@ +._phpunit { + h1 { + margin-top: 0; + @extend %lined-heading; + } + + h2.title { + @extend %block-heading; + } + + .programlisting > pre { white-space: normal; } + + .literal { + padding: 2px 4px; + color: #c7254e; + background-color: #f9f2f4; + border-radius: 4px; + } + + div.warning { @extend %note, %note-red; } +} diff --git a/lib/docs/filters/phpunit/clean_html.rb b/lib/docs/filters/phpunit/clean_html.rb new file mode 100644 index 00000000..e07901e8 --- /dev/null +++ b/lib/docs/filters/phpunit/clean_html.rb @@ -0,0 +1,65 @@ +module Docs + class Phpunit + class CleanHtmlFilter < Filter + def call + root_page? ? root : other + doc + end + + def root + doc.inner_html = <<-HTML +

PHPUnit is a programmer-oriented testing framework for PHP.
+ It is an instance of the xUnit architecture for unit testing frameworks.

+ HTML + end + + def other + # set root on appendix + @doc = doc.at_css('div.appendix') + + # remove attributes 'style' + css('*').remove_attr('style') + + # clean titles + css('div.titlepage').each do |node| + title = node.at_css('.title') + case title.name + when 'h1' + # remove 'Appendix X.' from top title + nodetitle = title.content + title.content = nodetitle.gsub(/Appendix \w+\. /, '') + when 'h2' + # set link anchors in entries (title level 2) + anchor = Nokogiri::XML::Node.new "a", @doc + anchor.content = title.content + anchor['id'] = title.content.downcase.gsub(/[^a-z]/, '') + title.content = '' + anchor.parent = title + end + node.replace title + end + + # set anchor for internal references + css('p.title').each do |node| + anchor = Nokogiri::XML::Node.new "a", @doc + anchor.content = node.content + anchor['id'] = anchor.content[/\w+ [A-z0-9.]+/].downcase.parameterize + node.content = '' + anchor.parent = node + end + + # clean internal references + css('a').each do |node| + page = node['href'][/([A-z.-]+)?#/, 1] if node['href'] + if page then + page = page + '.html' unless page[/.*\.html/] + if Phpunit.initial_paths.include? page + node['href'] = node['href'].gsub(/#[A-z.-]+/, '#' + node.content.downcase.parameterize) + end + end + end + + end + end + end +end diff --git a/lib/docs/filters/phpunit/entries.rb b/lib/docs/filters/phpunit/entries.rb new file mode 100644 index 00000000..a389b930 --- /dev/null +++ b/lib/docs/filters/phpunit/entries.rb @@ -0,0 +1,20 @@ +module Docs + class Phpunit + class EntriesFilter < Docs::EntriesFilter + def additional_entries + entries = [] + + if at_css('h1') + type = at_css('h1').content.gsub(/Appendix \w+\. /, '') + + css('h2').each do |node| + name = node.content + id = name.parameterize + entries << [name, id, type] + end + end + entries + end + end + end +end diff --git a/lib/docs/scrapers/phpunit.rb b/lib/docs/scrapers/phpunit.rb new file mode 100644 index 00000000..b846df07 --- /dev/null +++ b/lib/docs/scrapers/phpunit.rb @@ -0,0 +1,31 @@ +module Docs + class Phpunit < UrlScraper + self.name = 'PHPUnit' + self.type = 'phpunit' + self.slug = 'phpunit' + self.version = '4.3' + self.base_url = 'https://phpunit.de/manual/4.3/en/' + self.initial_paths = %w(appendixes.assertions.html appendixes.annotations.html) + + html_filters.push 'phpunit/entries', 'phpunit/clean_html', 'title' + + options[:skip_links] = true + + options[:title] = false + options[:root_title] = "#{self.name} #{self.version}" + + options[:fix_urls] = ->(url) do + if self.initial_paths.include? url[/\/([A-z.-]+)#/, 1] + url = url[/#(.+)/, 1].downcase + url.gsub! /(\w+\.\w+)\.(\w+)/, '\1#\2' + end + url + end + + + options[:attribution] = <<-HTML + © 2005–2014 Sebastian Bergmann
+ Licensed under the Creative Commons Attribution 3.0 Unported License. + HTML + end +end diff --git a/public/icons/docs/phpunit/16.png b/public/icons/docs/phpunit/16.png new file mode 100644 index 0000000000000000000000000000000000000000..15d5ce0724b65abd7e475729ab92a7cd6160edb8 GIT binary patch literal 718 zcmV;<0x|uGP)$@ zUr1AN6vxl`-8na>O|M%QowW&pW3&fHP(C=YfzO*Dh!^UDKKdZ}*z{of&H zj}AYXOf|*;;QiJ<$F^E4FageWu;EL;=UKSR=4^5U03uemVgSa@UdiQdv0A9khIKX& zP(wTqbTq3cCzZV`3@a20$3=Uar$%goh6ZSIa`9s1FU>`^}_zP z_Y$wIb?CY-Ns=gvnM?)|4Z{EchKOfp=MIPS`i;=QKu=Fki_iC?tE&?L7-K}_^?C(C zP*v4pu>b&5RaH@LkB!}#nz}bXzwr3c+|ttg#Kgqx?Ci?QN-CAg=kth|N~IPT7m0{z znwHDu8XFt8x3^|y9)A3|x4XM%x7!a64vNL%^73*#9-p3`URzsBr_+eY1VNBxIgv>8 z_V!LrP6mTPMNyK;WP5viHk^<*?FgX}=e_seKmOq#t(PyiPy4==B!Up)95jt`&Vi%HVBg;Z#y9}f z)SMa^&2;$-tN-HKQ&v}5Rnyzs#kv165~Gv>07CGbe&B%nl0-&F9e3{F#H80=Fh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