فهرست منبع

Finish Codeception scraper

Thibaut Courouble 9 سال پیش
والد
کامیت
802a8d3804

BIN
assets/images/docs.png


BIN
assets/images/docs@2x.png


+ 1 - 1
assets/javascripts/news.json

@@ -1,7 +1,7 @@
 [
   [
     "2016-12-04",
-    "New documentation: <a href=\"/sqlite/\">SQLite</a>"
+    "New documentations: <a href=\"/sqlite/\">SQLite</a> and <a href=\"/codeception/\">Codeception</a>"
   ], [
     "2016-11-20",
     "New documentations: <a href=\"/yarn/\">Yarn</a>, <a href=\"/immutable/\">Immutable.js</a> and <a href=\"/async/\">Async</a>"

+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -154,6 +154,11 @@ credits = [
     '2000-2016 Kitware, Inc.<br>&copy; 2000-2011 Insight Software Consortium',
     'BSD',
     'https://cmake.org/licensing/'
+  ], [
+    'Codeception',
+    '2011-2016 Michael Bodnarchuk and contributors',
+    'MIT',
+    'https://raw.githubusercontent.com/Codeception/Codeception/master/LICENSE'
   ], [
     'CodeIgniter',
     '2014-2016 British Columbia Institute of Technology',

+ 0 - 10
assets/javascripts/views/pages/codeception.coffee

@@ -1,10 +0,0 @@
-#= require views/pages/base
-
-class app.views.CodeceptionPage extends app.views.BasePage
-  LANGUAGE_RGX = /language-(\w+)/
-
-  prepare: ->
-    for el in @findAll('pre > code')
-      if el.className.match(LANGUAGE_RGX)
-          @highlightCode(el, el.className.match(LANGUAGE_RGX)[1])
-    return

+ 1 - 0
assets/javascripts/views/pages/simple.coffee

@@ -14,6 +14,7 @@ app.views.BowerPage =
 app.views.CPage =
 app.views.CakephpPage =
 app.views.ChaiPage =
+app.views.CodeceptionPage =
 app.views.CoffeescriptPage =
 app.views.CordovaPage =
 app.views.CrystalPage =

+ 1 - 0
assets/stylesheets/global/_icons.scss

@@ -56,6 +56,7 @@
 %icon-close-white           { background-position: -2rem -5rem; }
 %icon-back                  { background-position: -3rem -5rem; @extend %darkIconFix !optional; }
 
+._icon-codeception:before   { background-position: -4rem 0; }
 ._icon-sqlite:before        { background-position: -5rem 0; @extend %darkIconFix !optional; }
 ._icon-async:before         { background-position: -6rem 0; @extend %darkIconFix !optional; }
 ._icon-http:before          { background-position: -7rem 0; @extend %darkIconFix !optional; }

+ 2 - 24
assets/stylesheets/pages/_codeception.scss

@@ -1,29 +1,7 @@
 ._codeception {
   @extend %simple;
 
-  .warning, .alert {
-    @extend %note;
-  }
-
-  h4 {
-      @extend %block-label;
-  }
-
+  h4 { @extend %block-label; }
+  .warning, .alert { @extend %note; }
   .alert-danger { @extend %note-red; }
-
-  .language-yaml {
-      @extend .token;
-
-      .c1 {
-          @extend .token.comment;
-      }
-
-      .pi {
-          @extend .token.operator;
-      }
-
-      .s {
-          @extend .token.string;
-      }
-  }
 }

+ 31 - 8
lib/docs/filters/codeception/clean_html.rb

@@ -2,17 +2,40 @@ module Docs
   class Codeception
     class CleanHtmlFilter < Filter
       def call
-        root_page? ? root : other
-        doc
-      end
+        @doc = doc.at_css('div.page, div.content')
 
-      def root
-        doc.inner_html = ' '
-      end
+        while doc.element_children.length == 1
+          doc.first_element_child.before(doc.first_element_child.children).remove
+        end
+
+        if root_page?
+          at_css('h1').content = 'Codeception Documentation'
+        end
+
+        unless at_css('h1')
+          at_css('h2').name = 'h1'
+        end
+
+        unless at_css('h2')
+          css('h3').each { |node| node.name = 'h2' }
+          css('h4').each { |node| node.name = 'h3' }
+        end
 
-      def other
-        @doc = doc.at_css('div.page, div.content')
         css('.btn-group').remove
+
+        css('.alert:last-child').each do |node|
+          node.remove if node.content.include?('taken from the source code')
+        end
+
+        css('.highlight').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('pre > code').each do |node|
+          node.parent['data-language'] = node['data-lang']
+          node.parent.content = node.parent.content
+        end
+
         doc
       end
     end

+ 23 - 21
lib/docs/filters/codeception/entries.rb

@@ -2,46 +2,48 @@ module Docs
   class Codeception
     class EntriesFilter < Docs::EntriesFilter
       def get_name
-          (subpath.scan(/\d\d/).first || '') + ' ' + (at_css('h1') || at_css('h2')).content
-      end
+        name = (at_css('h1') || at_css('h2')).content
 
-      def get_type
-          return 'Module::' +  (at_css('h1') || at_css('h2')).content if subpath.start_with?('modules')
-          return 'Guides' if subpath =~ /\d\d/
-          (at_css('h1') || at_css('h2')).content
+        if number = subpath[/\A\d+/]
+          name.prepend "#{number.to_i}. "
+        end
+
+        name
       end
 
-      def include_default_entry?
-        return true if %w(Guides).include? type
-        return true if type =~ /(Module)|(Util)/
-        false
+      def get_type
+        if subpath =~ /\d\d/
+          'Guides'
+        elsif subpath.start_with?('modules')
+          "Module: #{name}"
+        elsif name.include?('Util')
+          "Util Class: #{name.split('\\').last}"
+        else
+          "Reference: #{name}"
+        end
       end
 
       def additional_entries
-
         if type =~ /Module/
-          prefix = type.sub(/Module::/, '')+ '::'
+          prefix = "#{name}::"
           pattern = '#actions ~ h4'
         elsif type =~ /Functions/
           prefix = ''
-          pattern = 'h4'
-        elsif type =~ /Util/
-          prefix = type.sub(/Codeception\/Util/, '')+ '::'
+          pattern = '#page h4'
+        elsif name =~ /Util/
+          prefix = "#{name.remove('Codeception\\Util\\')}::"
           pattern = 'h3'
         elsif type =~ /(Commands)|(Configuration)/
-         prefix = ''
-         pattern = 'h2'
-        else
           prefix = ''
-          pattern = 'none'
+          pattern = 'h2'
         end
 
+        return [] unless pattern
+
         css(pattern).map do |node|
           [prefix + node.content, node['id']]
         end.compact
-
       end
-
     end
   end
 end

+ 4 - 6
lib/docs/scrapers/codeception.rb

@@ -2,22 +2,20 @@ module Docs
   class Codeception < UrlScraper
     self.name = 'Codeception'
     self.type = 'codeception'
-    self.root_path = 'index.html'
-    self.release = '2.2'
+    self.release = '2.2.6'
     self.base_url = 'http://codeception.com/docs/'
+    self.root_path = 'index.html'
     self.links = {
       home: 'http://codeception.com/',
       code: 'https://github.com/codeception/codeception'
     }
 
-    html_filters.push 'codeception/clean_html', 'codeception/entries', 'title'
+    html_filters.push 'codeception/entries', 'codeception/clean_html'
 
-    options[:root_title] = 'Codeception'
-    options[:title] = false
     options[:skip_patterns] = [/install/]
 
     options[:attribution] = <<-HTML
-      &copy; 2011–2016 Michael Bodnarchuk and Contributors<br>
+      &copy; 2011&ndash;2016 Michael Bodnarchuk and contributors<br>
       Licensed under the MIT License.
     HTML
   end

BIN
public/icons/docs/codeception/16.png


BIN
public/icons/docs/codeception/16@2x.png