浏览代码

Merge branch 'edno-master'

* edno-master:
  Add PHPUnit documentation (4.3)
Thibaut 11 年之前
父节点
当前提交
b77a16d9c1

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -54,6 +54,7 @@
         'pages/nginx',
         'pages/node',
         'pages/php',
+        'pages/phpunit',
         'pages/postgres',
         'pages/rdoc',
         'pages/redis',

+ 21 - 0
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; }
+}

+ 65 - 0
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
+          <p>PHPUnit is a programmer-oriented testing framework for PHP.<br>
+          It is an instance of the xUnit architecture for unit testing frameworks.</p>
+        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

+ 20 - 0
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

+ 31 - 0
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
+      &copy; 2005&ndash;2014 Sebastian Bergmann<br>
+      Licensed under the Creative Commons Attribution 3.0 Unported License.
+    HTML
+  end
+end

二进制
public/icons/docs/phpunit/16.png


二进制
public/icons/docs/phpunit/16@2.png