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 @@
11 [
22 [
3+ "2017-07-23",
4+ "New documentation: <a href=\"/godot/\">Godot</a>"
5+ ], [
36 "2017-06-04",
47 "New documentations: <a href=\"/electron/\">Electron</a>, <a href=\"/pug/\">Pug</a>, and <a href=\"/falcon/\">Falcon</a>"
58 ], [
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -268,6 +268,11 @@ credits = [ · 267 unmodified lines
268268 'Google, Inc.',
269269 'CC BY',
270270 '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'
271276 ], [
272277 'Grunt',
273278 'GruntJS Team',
assets/stylesheets/global/_icons.scss+1−0
@@ -175,3 +175,4 @@ · 174 unmodified lines
175175 ._icon-pug:before { background-position: -1rem -2rem; @extend %doc-icon-2; }
176176 ._icon-electron:before { background-position: -2rem -2rem; @extend %doc-icon-2; }
177177 ._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
33
44 .admonition { @extend %note; }
55 .admonition.warning { @extend %note-orange; }
6+ .admonition.tip { @extend %note-green; }
67 .admonition-title {
78 margin: 0 0 .25rem;
89 font-weight: $boldFontWeight;
lib/docs/filters/godot/clean_html.rb+17−1
@@ -2,7 +2,23 @@ module Docs · 1 unmodified line
22 class Godot
33 class CleanHtmlFilter < Filter
44 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')
622
723 doc
824 end
lib/docs/filters/godot/entries.rb+22−12
@@ -2,33 +2,43 @@ module Docs · 1 unmodified line
22 class Godot
33 class EntriesFilter < Docs::EntriesFilter
44 def get_name
5− name = at_css('.document h1').content
5+ name = at_css('h1').content
66 name.remove! "\u{00B6}" # Remove the pilcrow
77 name
88 end
99
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+
1018 def get_type
1119 if slug.start_with?('learning')
12− 'Learning'
20+ TYPE_BY_LEARNING_PATH[slug.split('/')[1]]
1321 else
14− 'API Reference'
22+ name
1523 end
1624 end
1725
1826 def additional_entries
1927 return [] unless slug.start_with?('classes')
20− class_name = at_css('h1').content
21− class_name.remove! "\u{00B6}" # Remove the pilcrow
22− entries = []
2328
24− # Each page represents a class, and class methods are defined in
25− # individual sections.
26− css('.simple[id]').each do |node|
27− fn_name = node.at_css('strong')
28− entries << [class_name + '.' + fn_name + '()', node['id']]
29+ css('.simple[id]').each_with_object [] do |node, entries|
30+ name = node.at_css('strong').content
31+ next if name == self.name
32+ name.prepend "#{self.name}."
33+ name << '()'
34+ entries << [name, node['id']] unless entries.any? { |entry| entry[0] == name }
2935 end
36+ end
3037
31− entries
38+ 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
3242 end
3343 end
3444 end
lib/docs/filters/sphinx/clean_html.rb+1−3
@@ -87,9 +87,7 @@ module Docs · 86 unmodified lines
8787 node.remove_attribute 'cellspacing'
8888 end
8989
90− css('code[class]').each do |node|
91− node.remove_attribute 'class'
92− end
90+ css('code', 'tr').remove_attr('class')
9391
9492 css('h1').each do |node|
9593 node.content = node.content
lib/docs/scrapers/godot.rb+17−6
@@ -8,18 +8,29 @@ module Docs · 7 unmodified lines
88
99 html_filters.push 'godot/entries', 'godot/clean_html', 'sphinx/clean_html'
1010
11− # `learning/` contains the guided learning materials, and `classes/`
12− # contains the API reference.
11+ options[:download_images] = false
12+ options[:container] = '.document .section'
13+
1314 options[:only_patterns] = [/\Alearning\//, /\Aclasses\//]
15+ options[:skip] = %w(classes/class_@global\ scope.html)
1416
15− options[:attribution] = <<-HTML
16− &copy; Copyright 2014&ndash;2017, Juan Linietsky, Ariel Manzur and the Godot community (CC-BY 3.0).
17− HTML
17+ options[:attribution] = ->(filter) do
18+ if filter.subpath.start_with?('classes')
19+ <<-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
1830
1931 version '2.1' do
2032 self.release = '2.1'
2133 self.base_url = "http://docs.godotengine.org/en/#{self.version}/"
2234 end
23−
2435 end
2536 end
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.