History

Finish Godot scraper

Thibaut Courouble committed 9 years ago

Commit 854cebd1 parent d69f4f612 files · +63 −18Browse files

Unified · Split

12 files
  1. assets/images/docs-2.png +0 −0
  2. assets/images/docs-2@2x.png +0 −0
  3. assets/javascripts/news.json +3 −0
  4. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  5. assets/stylesheets/global/_icons.scss +1 −0
  6. assets/stylesheets/pages/_sphinx_simple.scss +1 −0
  7. lib/docs/filters/godot/clean_html.rb +17 −1
  8. lib/docs/filters/godot/entries.rb +22 −12
  9. lib/docs/filters/sphinx/clean_html.rb +1 −3
  10. lib/docs/scrapers/godot.rb +17 −6
  11. public/icons/docs/godot/16.png +0 −0
  12. public/icons/docs/godot/16@2x.png +0 −0
assets/images/docs-2.png+0−0

Binary file not shown.

assets/images/docs-2@2x.png+0−0

Binary file not shown.

assets/javascripts/news.json+3−0
@@ -1,5 +1,8 @@
1[1[
2 [2 [
3 "2017-07-23",
4 "New documentation: <a href=\"/godot/\">Godot</a>"
5 ], [
3 "2017-06-04",6 "2017-06-04",
4 "New documentations: <a href=\"/electron/\">Electron</a>, <a href=\"/pug/\">Pug</a>, and <a href=\"/falcon/\">Falcon</a>"7 "New documentations: <a href=\"/electron/\">Electron</a>, <a href=\"/pug/\">Pug</a>, and <a href=\"/falcon/\">Falcon</a>"
5 ], [8 ], [
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -268,6 +268,11 @@ credits = [ · 267 unmodified lines
268 'Google, Inc.',268 'Google, Inc.',
269 'CC BY',269 'CC BY',
270 'https://creativecommons.org/licenses/by/3.0/'270 'https://creativecommons.org/licenses/by/3.0/'
271 ], [
272 'Godot',
273 '2014-2017 Juan Linietsky, Ariel Manzur, Godot Engine contributors',
274 'MIT',
275 'https://raw.githubusercontent.com/godotengine/godot/master/LICENSE.txt'
271 ], [276 ], [
272 'Grunt',277 'Grunt',
273 'GruntJS Team',278 'GruntJS Team',
assets/stylesheets/global/_icons.scss+1−0
@@ -175,3 +175,4 @@ · 174 unmodified lines
175._icon-pug:before { background-position: -1rem -2rem; @extend %doc-icon-2; }175._icon-pug:before { background-position: -1rem -2rem; @extend %doc-icon-2; }
176._icon-electron:before { background-position: -2rem -2rem; @extend %doc-icon-2; }176._icon-electron:before { background-position: -2rem -2rem; @extend %doc-icon-2; }
177._icon-falcon:before { background-position: -3rem -2rem; @extend %doc-icon-2; }177._icon-falcon:before { background-position: -3rem -2rem; @extend %doc-icon-2; }
178._icon-godot:before { background-position: -4rem -2rem; @extend %doc-icon-2; }
assets/stylesheets/pages/_sphinx_simple.scss+1−0
@@ -3,6 +3,7 @@ · 2 unmodified lines
3 3
4 .admonition { @extend %note; }4 .admonition { @extend %note; }
5 .admonition.warning { @extend %note-orange; }5 .admonition.warning { @extend %note-orange; }
6 .admonition.tip { @extend %note-green; }
6 .admonition-title {7 .admonition-title {
7 margin: 0 0 .25rem;8 margin: 0 0 .25rem;
8 font-weight: $boldFontWeight;9 font-weight: $boldFontWeight;
lib/docs/filters/godot/clean_html.rb+17−1
@@ -2,7 +2,23 @@ module Docs · 1 unmodified line
2 class Godot2 class Godot
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 @doc = at_css('.document .section')5 if root_page?
6 at_css('h1').content = 'Godot Engine'
7 at_css('.admonition.tip').remove
8 end
9
10 css('ul[id].simple li:first-child:last-child').each do |node|
11 heading = Nokogiri::XML::Node.new 'h3', doc
12 heading['id'] = node.parent['id']
13 heading.children = node.children
14 node.parent.before(heading).remove
15 end
16
17 css('h3 strong').each do |node|
18 node.before(node.children).remove
19 end
20
21 css('a.reference').remove_attr('class')
6 22
7 doc23 doc
8 end24 end
lib/docs/filters/godot/entries.rb+22−12
@@ -2,33 +2,43 @@ module Docs · 1 unmodified line
2 class Godot2 class Godot
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def get_name4 def get_name
5 name = at_css('.document h1').content5 name = at_css('h1').content
6 name.remove! "\u{00B6}" # Remove the pilcrow6 name.remove! "\u{00B6}" # Remove the pilcrow
7 name7 name
8 end8 end
9 9
10 TYPE_BY_LEARNING_PATH = {
11 'step_by_step' => 'Guides: Step by step',
12 'editor' => 'Guides: Editor',
13 'features' => 'Guides: Engine features',
14 'scripting' => 'Guides: Scripting',
15 'workflow' => 'Guides: Project workflow'
16 }
17
10 def get_type18 def get_type
11 if slug.start_with?('learning')19 if slug.start_with?('learning')
12 'Learning'20 TYPE_BY_LEARNING_PATH[slug.split('/')[1]]
13 else21 else
14 'API Reference'22 name
15 end23 end
16 end24 end
17 25
18 def additional_entries26 def additional_entries
19 return [] unless slug.start_with?('classes')27 return [] unless slug.start_with?('classes')
20 class_name = at_css('h1').content
21 class_name.remove! "\u{00B6}" # Remove the pilcrow
22 entries = []
23 28
24 # Each page represents a class, and class methods are defined in29 css('.simple[id]').each_with_object [] do |node, entries|
25 # individual sections.30 name = node.at_css('strong').content
26 css('.simple[id]').each do |node|31 next if name == self.name
27 fn_name = node.at_css('strong')32 name.prepend "#{self.name}."
28 entries << [class_name + '.' + fn_name + '()', node['id']]33 name << '()'
34 entries << [name, node['id']] unless entries.any? { |entry| entry[0] == name }
29 end35 end
36 end
30 37
31 entries38 def include_default_entry?
39 return false if subpath.start_with?('learning') && subpath.end_with?('index.html')
40 return false if subpath == 'classes/index.html'
41 true
32 end42 end
33 end43 end
34 end44 end
lib/docs/filters/sphinx/clean_html.rb+1−3
@@ -87,9 +87,7 @@ module Docs · 86 unmodified lines
87 node.remove_attribute 'cellspacing'87 node.remove_attribute 'cellspacing'
88 end88 end
89 89
90 css('code[class]').each do |node|90 css('code', 'tr').remove_attr('class')
91 node.remove_attribute 'class'
92 end
93 91
94 css('h1').each do |node|92 css('h1').each do |node|
95 node.content = node.content93 node.content = node.content
lib/docs/scrapers/godot.rb+17−6
@@ -8,18 +8,29 @@ module Docs · 7 unmodified lines
8 8
9 html_filters.push 'godot/entries', 'godot/clean_html', 'sphinx/clean_html'9 html_filters.push 'godot/entries', 'godot/clean_html', 'sphinx/clean_html'
10 10
11 # `learning/` contains the guided learning materials, and `classes/`11 options[:download_images] = false
12 # contains the API reference.12 options[:container] = '.document .section'
13
13 options[:only_patterns] = [/\Alearning\//, /\Aclasses\//]14 options[:only_patterns] = [/\Alearning\//, /\Aclasses\//]
15 options[:skip] = %w(classes/class_@global\ scope.html)
14 16
15 options[:attribution] = <<-HTML17 options[:attribution] = ->(filter) do
16 &copy; Copyright 2014&ndash;2017, Juan Linietsky, Ariel Manzur and the Godot community (CC-BY 3.0).18 if filter.subpath.start_with?('classes')
17 HTML19 <<-HTML
20 &copy; 2014&ndash;2017 Juan Linietsky, Ariel Manzur, Godot Engine contributors<br>
21 Licensed under the MIT License.
22 HTML
23 else
24 <<-HTML
25 &copy; 2014&ndash;2017 Juan Linietsky, Ariel Manzur and the Godot community<br>
26 Licensed under the Creative Commons Attribution Unported License v3.0.
27 HTML
28 end
29 end
18 30
19 version '2.1' do31 version '2.1' do
20 self.release = '2.1'32 self.release = '2.1'
21 self.base_url = "http://docs.godotengine.org/en/#{self.version}/"33 self.base_url = "http://docs.godotengine.org/en/#{self.version}/"
22 end34 end
23
24 end35 end
25end36end
public/icons/docs/godot/16.png+0−0

Binary file not shown.

public/icons/docs/godot/16@2x.png+0−0

Binary file not shown.