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 00000000..15d5ce07 Binary files /dev/null and b/public/icons/docs/phpunit/16.png differ diff --git a/public/icons/docs/phpunit/16@2.png b/public/icons/docs/phpunit/16@2.png new file mode 100644 index 00000000..4c85c431 Binary files /dev/null and b/public/icons/docs/phpunit/16@2.png differ