History

Update CoffeeScript documentation (2.0.1)

Thibaut Courouble committed 9 years ago

Commit 8e2a9181 parent e4d841d5 files · +224 −83Browse files

Unified · Split

5 files
  1. lib/docs/filters/coffeescript/clean_html.rb +18 −42
  2. lib/docs/filters/coffeescript/clean_html_v1.rb +69 −0
  3. lib/docs/filters/coffeescript/entries.rb +35 −36
  4. lib/docs/filters/coffeescript/entries_v1.rb +86 −0
  5. lib/docs/scrapers/coffeescript.rb +16 −5
lib/docs/filters/coffeescript/clean_html.rb+18−42
@@ -2,52 +2,24 @@ module Docs · 1 unmodified line
22 class Coffeescript
33 class CleanHtmlFilter < Filter
44 def call
5− css('#top', '.minibutton', '.clear').remove
5+ @doc = at_css('main')
66
7− # Set id attributes on actual elements instead of an empty <span>
8− css('.bookmark').each do |node|
9− node.next_element['id'] = node['id']
10− node.remove
11− end
12−
13− # Remove Books, Screencasts, etc.
14− while doc.children.last['id'] != 'resources'
15− doc.children.last.remove
16− end
17− doc.children.last.remove
18−
19− # Make proper headings
20− css('.header').each do |node|
21− node.parent.before(node)
22− node.name = 'h3'
23− node['id'] ||= node.content.strip.parameterize
24− node.remove_attribute 'class'
25− end
26−
27− # Remove "Latest Version" paragraph
28− css('b').each do |node|
29− if node.content =~ /Latest Version/i
30− node.parent.next_element.remove
31− node.parent.remove
32− break
33− end
34− end
7+ css('> header', '#resources', '#changelog').remove
358
36− # Remove "examples can be run" paragraph
37− css('i').each do |node|
38− if node.content =~ /examples can be run/i
39− node.parent.remove
40− break
41− end
9+ css('section').each do |node|
10+ node.first_element_child['id'] = node['id']
11+ node.before(node.children).remove
4212 end
4313
44− # Remove code highlighting
45− css('pre').each do |node|
46− node.content = node.content
14+ css('.uneditable-code-block').each do |node|
15+ node.before(node.children).remove
4716 end
4817
49− css('blockquote > pre:first-child:last-child').each do |node|
50− node.parent.before(node).remove
18+ css('aside.code-example').each do |node|
19+ node.name = 'div'
20+ node['class'] = 'code'
21+ node.children = node.css('pre')
22+ node.remove_attribute('data-example')
5123 end
5224
5325 css('.code pre:first-child').each do |node|
@@ -58,8 +30,12 @@ module Docs · 4 unmodified lines
5830 node['data-language'] = 'javascript'
5931 end
6032
61− css('tt').each do |node|
62− node.name = 'code'
33+ css('pre').each do |node|
34+ content = node.content
35+ node.content = content
36+ unless content.start_with?('coffee ') || content.start_with?('npm ')
37+ node['data-language'] ||= 'coffeescript'
38+ end
6339 end
6440
6541 doc
lib/docs/filters/coffeescript/clean_html_v1.rb+69−0
@@ -0,0 +1,69 @@
1+module Docs
2+ class Coffeescript
3+ class CleanHtmlV1Filter < Filter
4+ def call
5+ css('#top', '.minibutton', '.clear').remove
6+
7+ # Set id attributes on actual elements instead of an empty <span>
8+ css('.bookmark').each do |node|
9+ node.next_element['id'] = node['id']
10+ node.remove
11+ end
12+
13+ # Remove Books, Screencasts, etc.
14+ while doc.children.last['id'] != 'resources'
15+ doc.children.last.remove
16+ end
17+ doc.children.last.remove
18+
19+ # Make proper headings
20+ css('.header').each do |node|
21+ node.parent.before(node)
22+ node.name = 'h3'
23+ node['id'] ||= node.content.strip.parameterize
24+ node.remove_attribute 'class'
25+ end
26+
27+ # Remove "Latest Version" paragraph
28+ css('b').each do |node|
29+ if node.content =~ /Latest Version/i
30+ node.parent.next_element.remove
31+ node.parent.remove
32+ break
33+ end
34+ end
35+
36+ # Remove "examples can be run" paragraph
37+ css('i').each do |node|
38+ if node.content =~ /examples can be run/i
39+ node.parent.remove
40+ break
41+ end
42+ end
43+
44+ # Remove code highlighting
45+ css('pre').each do |node|
46+ node.content = node.content
47+ end
48+
49+ css('blockquote > pre:first-child:last-child').each do |node|
50+ node.parent.before(node).remove
51+ end
52+
53+ css('.code pre:first-child').each do |node|
54+ node['data-language'] = 'coffeescript'
55+ end
56+
57+ css('.code pre:last-child').each do |node|
58+ node['data-language'] = 'javascript'
59+ end
60+
61+ css('tt').each do |node|
62+ node.name = 'code'
63+ end
64+
65+ doc
66+ end
67+ end
68+ end
69+end
lib/docs/filters/coffeescript/entries.rb+35−36
@@ -2,12 +2,9 @@ module Docs · 1 unmodified line
22 class Coffeescript
33 class EntriesFilter < Docs::EntriesFilter
44 ENTRIES = [
5− ['coffee command', 'usage', 'Miscellaneous'],
6− ['Literate mode', 'literate', 'Miscellaneous'],
7− ['Functions', 'literals', 'Language'],
8− ['->', 'literals', 'Statements'],
9− ['Objects and arrays', 'objects_and_arrays', 'Language'],
10− ['Lexical scoping', 'lexical-scope', 'Language'],
5+ ['coffee command', 'cli', 'Miscellaneous'],
6+ ['->', 'functions', 'Statements'],
7+ ['await', 'async-functions', 'Statements'],
118 ['if...then...else', 'conditionals', 'Statements'],
129 ['unless', 'conditionals', 'Statements'],
1310 ['... splats', 'splats', 'Language'],
@@ -19,56 +16,58 @@ module Docs · 5 unmodified lines
1916 ['until', 'loops', 'Statements'],
2017 ['loop', 'loops', 'Statements'],
2118 ['do', 'loops', 'Statements'],
22− ['Array slicing and splicing', 'slices', 'Language'],
2319 ['Ranges', 'slices', 'Language'],
24− ['Expressions', 'expressions', 'Language'],
2520 ['?', 'existential-operator', 'Operators'],
2621 ['?=', 'existential-operator', 'Operators'],
2722 ['?.', 'existential-operator', 'Operators'],
2823 ['class', 'classes', 'Statements'],
29− ['extends', 'classes', 'Operators'],
24+ ['extends', 'classes', 'Statements'],
3025 ['super', 'classes', 'Statements'],
31− ['::', 'classes', 'Operators'],
32− ['Destructuring assignment', 'destructuring', 'Language'],
33− ['Bound Functions', 'fat-arrow', 'Language'],
34− ['Generator Functions', 'fat-arrow', 'Language'],
26+ ['::', 'prototypal-inheritance', 'Operators'],
3527 ['=>', 'fat-arrow', 'Statements'],
36− ['yield', 'fat-arrow', 'Statements'],
37− ['for...from', 'fat-arrow', 'Statements'],
38− ['Embedded JavaScript', 'embedded', 'Language'],
28+ ['yield', 'generators', 'Statements'],
3929 ['switch...when...else', 'switch', 'Statements'],
40− ['try...catch...finally', 'try-catch', 'Statements'],
41− ['Chained comparisons', 'comparisons', 'Language'],
30+ ['try...catch...finally', 'try', 'Statements'],
4231 ['#{} interpolation', 'strings', 'Language'],
4332 ['Block strings', 'strings', 'Language'],
4433 ['"""', 'strings', 'Language'],
45− ['Block comments', 'strings', 'Language'],
46− ['###', 'strings', 'Language'],
47− ['Tagged Template Literals', 'tagged-template-literals', 'Language'],
48− ['Block regexes', 'regexes', 'Language'],
34+ ['###', 'comments', 'Language'],
35+ ['###::', 'type-annotations', 'Language'],
4936 ['///', 'regexes', 'Language'],
50− ['Modules', 'modules', 'Language'],
5137 ['import', 'modules', 'Language'],
52− ['export', 'modules', 'Language'],
53− ['cake command', 'cake', 'Miscellaneous'],
54− ['Cakefile', 'cake', 'Miscellaneous'],
55− ['Source maps', 'source-maps', 'Miscellaneous']
38+ ['export', 'modules', 'Language']
5639 ]
5740
5841 def additional_entries
59− entries = ENTRIES.dup
42+ entries = []
6043
61− # Operators
62− at_css('#operators ~ table').css('td:first-child > code').each do |node|
63− node.content.split(', ').each do |name|
64− next if %w(true false yes no on off this).include?(name)
65− name.sub! %r{\Aa (.+) b\z}, '\1'
66− id = name_to_id(name)
67− node['id'] = id
68− entries << [name, id, 'Operators']
44+ ENTRIES.each do |entry|
45+ raise "entry not found: #{entry.inspect}" unless at_css("[id='#{entry[1]}']")
46+ entries << entry
47+ end
48+
49+ css('.navbar > nav > .nav-link').each do |node|
50+ name = node.content.strip
51+ next if name.in?(%w(Overview Changelog)) || !node['href'].start_with?('#')
52+ entries << [name, node['href'].remove('#'), 'Miscellaneous']
53+
54+ if name == 'Language Reference'
55+ node.next_element.css('.nav-link').each do |n|
56+ entries << [n.content, n['href'].remove('#'), name]
57+ end
6958 end
7059 end
7160
61+ at_css('#operators table').css('td:first-child > code').each do |node|
62+ name = node.content.strip
63+ next if %w(true false yes no on off this).include?(name)
64+ name.sub! %r{\Aa (.+) b\z}, '\1'
65+ name = 'for...from' if name == 'for a from b'
66+ id = name_to_id(name)
67+ node['id'] = id
68+ entries << [name, id, 'Operators']
69+ end
70+
7271 entries
7372 end
7473
lib/docs/filters/coffeescript/entries_v1.rb+86−0
@@ -0,0 +1,86 @@
1+module Docs
2+ class Coffeescript
3+ class EntriesV1Filter < Docs::EntriesFilter
4+ ENTRIES = [
5+ ['coffee command', 'usage', 'Miscellaneous'],
6+ ['Literate mode', 'literate', 'Miscellaneous'],
7+ ['Functions', 'literals', 'Language'],
8+ ['->', 'literals', 'Statements'],
9+ ['Objects and arrays', 'objects-and-arrays', 'Language'],
10+ ['Lexical scoping', 'lexical-scope', 'Language'],
11+ ['if...then...else', 'conditionals', 'Statements'],
12+ ['unless', 'conditionals', 'Statements'],
13+ ['... splats', 'splats', 'Language'],
14+ ['for...in', 'loops', 'Statements'],
15+ ['for...in...by', 'loops', 'Statements'],
16+ ['for...in...when', 'loops', 'Statements'],
17+ ['for...of', 'loops', 'Statements'],
18+ ['while', 'loops', 'Statements'],
19+ ['until', 'loops', 'Statements'],
20+ ['loop', 'loops', 'Statements'],
21+ ['do', 'loops', 'Statements'],
22+ ['Array slicing and splicing', 'slices', 'Language'],
23+ ['Ranges', 'slices', 'Language'],
24+ ['Expressions', 'expressions', 'Language'],
25+ ['?', 'existential-operator', 'Operators'],
26+ ['?=', 'existential-operator', 'Operators'],
27+ ['?.', 'existential-operator', 'Operators'],
28+ ['class', 'classes', 'Statements'],
29+ ['extends', 'classes', 'Operators'],
30+ ['super', 'classes', 'Statements'],
31+ ['::', 'classes', 'Operators'],
32+ ['Destructuring assignment', 'destructuring', 'Language'],
33+ ['Bound Functions', 'fat-arrow', 'Language'],
34+ ['Generator Functions', 'fat-arrow', 'Language'],
35+ ['=>', 'fat-arrow', 'Statements'],
36+ ['yield', 'fat-arrow', 'Statements'],
37+ ['for...from', 'fat-arrow', 'Statements'],
38+ ['Embedded JavaScript', 'embedded', 'Language'],
39+ ['switch...when...else', 'switch', 'Statements'],
40+ ['try...catch...finally', 'try-catch', 'Statements'],
41+ ['Chained comparisons', 'comparisons', 'Language'],
42+ ['#{} interpolation', 'strings', 'Language'],
43+ ['Block strings', 'strings', 'Language'],
44+ ['"""', 'strings', 'Language'],
45+ ['Block comments', 'strings', 'Language'],
46+ ['###', 'strings', 'Language'],
47+ ['Tagged Template Literals', 'tagged-template-literals', 'Language'],
48+ ['Block regexes', 'regexes', 'Language'],
49+ ['///', 'regexes', 'Language'],
50+ ['Modules', 'modules', 'Language'],
51+ ['import', 'modules', 'Language'],
52+ ['export', 'modules', 'Language'],
53+ ['cake command', 'cake', 'Miscellaneous'],
54+ ['Cakefile', 'cake', 'Miscellaneous'],
55+ ['Source maps', 'source-maps', 'Miscellaneous']
56+ ]
57+
58+ def additional_entries
59+ entries = ENTRIES.dup
60+
61+ # Operators
62+ at_css('#operators ~ table').css('td:first-child > code').each do |node|
63+ node.content.split(', ').each do |name|
64+ next if %w(true false yes no on off this).include?(name)
65+ name.sub! %r{\Aa (.+) b\z}, '\1'
66+ id = name_to_id(name)
67+ node['id'] = id
68+ entries << [name, id, 'Operators']
69+ end
70+ end
71+
72+ entries
73+ end
74+
75+ def name_to_id(name)
76+ case name
77+ when '**' then 'pow'
78+ when '//' then 'floor'
79+ when '%%' then 'mod'
80+ when '@' then 'this'
81+ else name.parameterize
82+ end
83+ end
84+ end
85+ end
86+end
lib/docs/scrapers/coffeescript.rb+16−5
@@ -2,22 +2,33 @@ module Docs · 1 unmodified line
22 class Coffeescript < UrlScraper
33 self.name = 'CoffeeScript'
44 self.type = 'coffeescript'
5− self.release = '1.12.6'
6− self.base_url = 'http://coffeescript.org'
75 self.links = {
86 home: 'http://coffeescript.org',
97 code: 'https://github.com/jashkenas/coffeescript'
108 }
119
12− html_filters.push 'coffeescript/clean_html', 'coffeescript/entries', 'title'
13−
1410 options[:title] = 'CoffeeScript'
15− options[:container] = '.container'
1611 options[:skip_links] = true
1712
1813 options[:attribution] = <<-HTML
1914 &copy; 2009&ndash;2017 Jeremy Ashkenas<br>
2015 Licensed under the MIT License.
2116 HTML
17+
18+ version '2' do
19+ self.release = '2.0.1'
20+ self.base_url = 'http://coffeescript.org/'
21+
22+ html_filters.push 'coffeescript/entries', 'coffeescript/clean_html', 'title'
23+ end
24+
25+ version '1' do
26+ self.release = '1.12.6'
27+ self.base_url = 'http://coffeescript.org/v1/'
28+
29+ html_filters.push 'coffeescript/clean_html_v1', 'coffeescript/entries_v1', 'title'
30+
31+ options[:container] = '.container'
32+ end
2233 end
2334 end