ソースを参照

Finish CodeceptJS scraper

Thibaut Courouble 9 年 前
コミット
193db39f9b

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 documentations: <a href=\"/sqlite/\">SQLite</a> and <a href=\"/codeception/\">Codeception</a>"
+    "New documentations: <a href=\"/sqlite/\">SQLite</a>, <a href=\"/codeception/\">Codeception</a> and <a href=\"/codeceptjs/\">CodeceptJS</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

@@ -159,6 +159,11 @@ credits = [
     '2011-2016 Michael Bodnarchuk and contributors',
     'MIT',
     'https://raw.githubusercontent.com/Codeception/Codeception/master/LICENSE'
+  ], [
+    'CodeceptJS',
+    '2015 DavertMik',
+    'MIT',
+    'https://raw.githubusercontent.com/Codeception/CodeceptJS/master/LICENSE'
   ], [
     'CodeIgniter',
     '2014-2016 British Columbia Institute of Technology',

+ 0 - 9
assets/javascripts/views/pages/codeceptjs.coffee

@@ -1,9 +0,0 @@
-#= require views/pages/base
-
-class app.views.CodeceptjsPage extends app.views.BasePage
-
-  prepare: ->
-    for el in @findAll('pre > code')
-      if /js/i.test(el.className)
-          @highlightCode(el, 'javascript')
-    return

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

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

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

@@ -40,7 +40,6 @@
         'pages/cakephp',
         'pages/clojure',
         'pages/codeception',
-        'pages/codeceptjs',
         'pages/coffeescript',
         'pages/cordova',
         'pages/crystal',

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

@@ -40,7 +40,6 @@
         'pages/cakephp',
         'pages/clojure',
         'pages/codeception',
-        'pages/codeceptjs',
         'pages/coffeescript',
         'pages/cordova',
         'pages/crystal',

+ 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-codeceptjs:before    { background-position: -3rem 0; }
 ._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; }

+ 0 - 3
assets/stylesheets/pages/_codeceptjs.scss

@@ -1,3 +0,0 @@
-._codeceptjs {
-  @extend %simple;
-}

+ 1 - 0
assets/stylesheets/pages/_simple.scss

@@ -20,6 +20,7 @@
 ._apache_pig,
 ._bower,
 ._chai,
+._codeceptjs,
 ._docker,
 ._fish,
 ._gnu,

+ 21 - 8
lib/docs/filters/codeceptjs/clean_html.rb

@@ -2,16 +2,29 @@ module Docs
   class Codeceptjs
     class CleanHtmlFilter < Filter
       def call
-        root_page? ? root : other
-        doc
-      end
+        if root_page?
+          doc.inner_html = ' '
+          return doc
+        end
 
-      def root
-        doc.inner_html = ' '
-      end
+        @doc = doc.at_css('div.reference div[role=main]')
+
+        css('hr').remove
+
+        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
+
+        css('pre > code').each do |node|
+          node.parent['data-language'] = node['class'] if node['class']
+          node.parent.content = node.parent.content
+        end
 
-      def other
-        @doc = doc.at_css('div.reference').xpath('//div[@role="main"]')
         doc
       end
     end

+ 14 - 11
lib/docs/filters/codeceptjs/entries.rb

@@ -2,26 +2,29 @@ module Docs
   class Codeceptjs
     class EntriesFilter < Docs::EntriesFilter
       def get_name
-          (at_css('h1') || at_css('h2')).content
+        at_css('h1').content
       end
 
       def get_type
-          return "Reference" if %w(commands configuration reports translation).include? subpath.scan(/\w+/).first
-          return "Guides" unless slug.camelize =~ /Helpers::.+/
-          "Helpers::" + (at_css('h1') || at_css('h2')).content
+        if subpath == 'helpers/'
+          'Helpers'
+        elsif subpath.start_with?('helpers')
+          "Helpers: #{name}"
+        elsif subpath.in? %w(commands/ configuration/ reports/ translation/)
+          'Reference'
+        else
+          'Guide'
+        end
       end
 
       def additional_entries
-        return [] unless type =~ /Helpers::.*/
+        return [] unless subpath.start_with?('helpers') && subpath != 'helpers/'
 
-        helper = type.sub(/Helpers::/, '')+ '::'
-
-        css('h2').map do |node|
+        css('h2').each_with_object [] do |node, entries|
           next if node['id'] == 'access-from-helpers'
-          [helper + node.content, node['id']]
-        end.compact
+          entries << ["#{node.content} (#{name})", node['id']]
+        end
       end
-
     end
   end
 end

+ 4 - 4
lib/docs/scrapers/codeceptjs.rb

@@ -3,7 +3,7 @@ module Docs
     self.name = 'CodeceptJS'
     self.type = 'codeceptjs'
     self.root_path = 'index.html'
-    self.release = '0.4'
+    self.release = '0.4.9'
     self.base_url = 'http://codecept.io/'
     self.links = {
       home: 'http://codecept.io/',
@@ -14,11 +14,11 @@ module Docs
 
     options[:root_title] = 'CodeceptJS'
     options[:title] = false
-    options[:skip_links] = ->(filter) { !filter.initial_page? }
-    options[:skip_patterns] = [/changelog/, /quickstart$/]
+    options[:skip_links] = ->(filter) { !filter.root_page? }
+    options[:skip_patterns] = [/changelog/, /quickstart\z/]
 
     options[:attribution] = <<-HTML
-      &copy; 2015–2016 Michael Bodnarchuk and Contributors<br>
+      &copy; 2015 DavertMik &lt;davert@codegyre.com&gt; (http://codegyre.com)<br>
       Licensed under the MIT License.
     HTML
   end

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


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