Browse Source

Finish Godot scraper

Thibaut Courouble 8 years ago
parent
commit
854cebd257

BIN
assets/images/docs-2.png


BIN
assets/images/docs-2@2x.png


+ 3 - 0
assets/javascripts/news.json

@@ -1,5 +1,8 @@
 [
   [
+    "2017-07-23",
+    "New documentation: <a href=\"/godot/\">Godot</a>"
+  ], [
     "2017-06-04",
     "New documentations: <a href=\"/electron/\">Electron</a>, <a href=\"/pug/\">Pug</a>, and <a href=\"/falcon/\">Falcon</a>"
   ], [

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

@@ -268,6 +268,11 @@ credits = [
     'Google, Inc.',
     'CC BY',
     'https://creativecommons.org/licenses/by/3.0/'
+  ], [
+    'Godot',
+    '2014-2017 Juan Linietsky, Ariel Manzur, Godot Engine contributors',
+    'MIT',
+    'https://raw.githubusercontent.com/godotengine/godot/master/LICENSE.txt'
   ], [
     'Grunt',
     'GruntJS Team',

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

@@ -175,3 +175,4 @@
 ._icon-pug:before           { background-position: -1rem -2rem; @extend %doc-icon-2; }
 ._icon-electron:before      { background-position: -2rem -2rem; @extend %doc-icon-2; }
 ._icon-falcon:before        { background-position: -3rem -2rem; @extend %doc-icon-2; }
+._icon-godot:before         { background-position: -4rem -2rem; @extend %doc-icon-2; }

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

@@ -3,6 +3,7 @@
 
   .admonition { @extend %note; }
   .admonition.warning { @extend %note-orange; }
+  .admonition.tip { @extend %note-green; }
   .admonition-title {
     margin: 0 0 .25rem;
     font-weight: $boldFontWeight;

+ 17 - 1
lib/docs/filters/godot/clean_html.rb

@@ -2,7 +2,23 @@ module Docs
   class Godot
     class CleanHtmlFilter < Filter
       def call
-        @doc = at_css('.document .section')
+        if root_page?
+          at_css('h1').content = 'Godot Engine'
+          at_css('.admonition.tip').remove
+        end
+
+        css('ul[id].simple li:first-child:last-child').each do |node|
+          heading = Nokogiri::XML::Node.new 'h3', doc
+          heading['id'] = node.parent['id']
+          heading.children = node.children
+          node.parent.before(heading).remove
+        end
+
+        css('h3 strong').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('a.reference').remove_attr('class')
 
         doc
       end

+ 22 - 12
lib/docs/filters/godot/entries.rb

@@ -2,33 +2,43 @@ module Docs
   class Godot
     class EntriesFilter < Docs::EntriesFilter
       def get_name
-        name = at_css('.document h1').content
+        name = at_css('h1').content
         name.remove! "\u{00B6}" # Remove the pilcrow
         name
       end
 
+      TYPE_BY_LEARNING_PATH = {
+        'step_by_step' => 'Guides: Step by step',
+        'editor' => 'Guides: Editor',
+        'features' => 'Guides: Engine features',
+        'scripting' => 'Guides: Scripting',
+        'workflow' => 'Guides: Project workflow'
+      }
+
       def get_type
         if slug.start_with?('learning')
-          'Learning'
+          TYPE_BY_LEARNING_PATH[slug.split('/')[1]]
         else
-          'API Reference'
+          name
         end
       end
 
       def additional_entries
         return [] unless slug.start_with?('classes')
-        class_name = at_css('h1').content
-        class_name.remove! "\u{00B6}" # Remove the pilcrow
-        entries = []
 
-        # Each page represents a class, and class methods are defined in
-        # individual sections.
-        css('.simple[id]').each do |node|
-          fn_name = node.at_css('strong')
-          entries << [class_name + '.' + fn_name + '()', node['id']]
+        css('.simple[id]').each_with_object [] do |node, entries|
+          name = node.at_css('strong').content
+          next if name == self.name
+          name.prepend "#{self.name}."
+          name << '()'
+          entries << [name, node['id']] unless entries.any? { |entry| entry[0] == name }
         end
+      end
 
-        entries
+      def include_default_entry?
+        return false if subpath.start_with?('learning') && subpath.end_with?('index.html')
+        return false if subpath == 'classes/index.html'
+        true
       end
     end
   end

+ 1 - 3
lib/docs/filters/sphinx/clean_html.rb

@@ -87,9 +87,7 @@ module Docs
           node.remove_attribute 'cellspacing'
         end
 
-        css('code[class]').each do |node|
-          node.remove_attribute 'class'
-        end
+        css('code', 'tr').remove_attr('class')
 
         css('h1').each do |node|
           node.content = node.content

+ 17 - 6
lib/docs/scrapers/godot.rb

@@ -8,18 +8,29 @@ module Docs
 
     html_filters.push 'godot/entries', 'godot/clean_html', 'sphinx/clean_html'
 
-    # `learning/` contains the guided learning materials, and `classes/`
-    # contains the API reference.
+    options[:download_images] = false
+    options[:container] = '.document .section'
+
     options[:only_patterns] = [/\Alearning\//, /\Aclasses\//]
+    options[:skip] = %w(classes/class_@global\ scope.html)
 
-    options[:attribution] = <<-HTML
-      &copy; Copyright 2014&ndash;2017, Juan Linietsky, Ariel Manzur and the Godot community (CC-BY 3.0).
-    HTML
+    options[:attribution] = ->(filter) do
+      if filter.subpath.start_with?('classes')
+         <<-HTML
+          &copy; 2014&ndash;2017 Juan Linietsky, Ariel Manzur, Godot Engine contributors<br>
+          Licensed under the MIT License.
+        HTML
+      else
+        <<-HTML
+          &copy; 2014&ndash;2017 Juan Linietsky, Ariel Manzur and the Godot community<br>
+          Licensed under the Creative Commons Attribution Unported License v3.0.
+        HTML
+      end
+    end
 
     version '2.1' do
       self.release = '2.1'
       self.base_url = "http://docs.godotengine.org/en/#{self.version}/"
     end
-
   end
 end

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


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