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
2 class Coffeescript2 class Coffeescript
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 css('#top', '.minibutton', '.clear').remove5 @doc = at_css('main')
6 6
7 # Set id attributes on actual elements instead of an empty <span>7 css('> header', '#resources', '#changelog').remove
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 8
36 # Remove "examples can be run" paragraph9 css('section').each do |node|
37 css('i').each do |node|10 node.first_element_child['id'] = node['id']
38 if node.content =~ /examples can be run/i11 node.before(node.children).remove
39 node.parent.remove
40 break
41 end
42 end12 end
43 13
44 # Remove code highlighting14 css('.uneditable-code-block').each do |node|
45 css('pre').each do |node|15 node.before(node.children).remove
46 node.content = node.content
47 end16 end
48 17
49 css('blockquote > pre:first-child:last-child').each do |node|18 css('aside.code-example').each do |node|
50 node.parent.before(node).remove19 node.name = 'div'
20 node['class'] = 'code'
21 node.children = node.css('pre')
22 node.remove_attribute('data-example')
51 end23 end
52 24
53 css('.code pre:first-child').each do |node|25 css('.code pre:first-child').each do |node|
@@ -58,8 +30,12 @@ module Docs · 4 unmodified lines
58 node['data-language'] = 'javascript'30 node['data-language'] = 'javascript'
59 end31 end
60 32
61 css('tt').each do |node|33 css('pre').each do |node|
62 node.name = 'code'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
63 end39 end
64 40
65 doc41 doc
lib/docs/filters/coffeescript/clean_html_v1.rb+69−0
@@ -0,0 +1,69 @@
1module 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
69end
lib/docs/filters/coffeescript/entries.rb+35−36
@@ -2,12 +2,9 @@ module Docs · 1 unmodified line
2 class Coffeescript2 class Coffeescript
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 ENTRIES = [4 ENTRIES = [
5 ['coffee command', 'usage', 'Miscellaneous'],5 ['coffee command', 'cli', 'Miscellaneous'],
6 ['Literate mode', 'literate', 'Miscellaneous'],6 ['->', 'functions', 'Statements'],
7 ['Functions', 'literals', 'Language'],7 ['await', 'async-functions', 'Statements'],
8 ['->', 'literals', 'Statements'],
9 ['Objects and arrays', 'objects_and_arrays', 'Language'],
10 ['Lexical scoping', 'lexical-scope', 'Language'],
11 ['if...then...else', 'conditionals', 'Statements'],8 ['if...then...else', 'conditionals', 'Statements'],
12 ['unless', 'conditionals', 'Statements'],9 ['unless', 'conditionals', 'Statements'],
13 ['... splats', 'splats', 'Language'],10 ['... splats', 'splats', 'Language'],
@@ -19,56 +16,58 @@ module Docs · 5 unmodified lines
19 ['until', 'loops', 'Statements'],16 ['until', 'loops', 'Statements'],
20 ['loop', 'loops', 'Statements'],17 ['loop', 'loops', 'Statements'],
21 ['do', 'loops', 'Statements'],18 ['do', 'loops', 'Statements'],
22 ['Array slicing and splicing', 'slices', 'Language'],
23 ['Ranges', 'slices', 'Language'],19 ['Ranges', 'slices', 'Language'],
24 ['Expressions', 'expressions', 'Language'],
25 ['?', 'existential-operator', 'Operators'],20 ['?', 'existential-operator', 'Operators'],
26 ['?=', 'existential-operator', 'Operators'],21 ['?=', 'existential-operator', 'Operators'],
27 ['?.', 'existential-operator', 'Operators'],22 ['?.', 'existential-operator', 'Operators'],
28 ['class', 'classes', 'Statements'],23 ['class', 'classes', 'Statements'],
29 ['extends', 'classes', 'Operators'],24 ['extends', 'classes', 'Statements'],
30 ['super', 'classes', 'Statements'],25 ['super', 'classes', 'Statements'],
31 ['::', 'classes', 'Operators'],26 ['::', 'prototypal-inheritance', 'Operators'],
32 ['Destructuring assignment', 'destructuring', 'Language'],
33 ['Bound Functions', 'fat-arrow', 'Language'],
34 ['Generator Functions', 'fat-arrow', 'Language'],
35 ['=>', 'fat-arrow', 'Statements'],27 ['=>', 'fat-arrow', 'Statements'],
36 ['yield', 'fat-arrow', 'Statements'],28 ['yield', 'generators', 'Statements'],
37 ['for...from', 'fat-arrow', 'Statements'],
38 ['Embedded JavaScript', 'embedded', 'Language'],
39 ['switch...when...else', 'switch', 'Statements'],29 ['switch...when...else', 'switch', 'Statements'],
40 ['try...catch...finally', 'try-catch', 'Statements'],30 ['try...catch...finally', 'try', 'Statements'],
41 ['Chained comparisons', 'comparisons', 'Language'],
42 ['#{} interpolation', 'strings', 'Language'],31 ['#{} interpolation', 'strings', 'Language'],
43 ['Block strings', 'strings', 'Language'],32 ['Block strings', 'strings', 'Language'],
44 ['"""', 'strings', 'Language'],33 ['"""', 'strings', 'Language'],
45 ['Block comments', 'strings', 'Language'],34 ['###', 'comments', 'Language'],
46 ['###', 'strings', 'Language'],35 ['###::', 'type-annotations', 'Language'],
47 ['Tagged Template Literals', 'tagged-template-literals', 'Language'],
48 ['Block regexes', 'regexes', 'Language'],
49 ['///', 'regexes', 'Language'],36 ['///', 'regexes', 'Language'],
50 ['Modules', 'modules', 'Language'],
51 ['import', 'modules', 'Language'],37 ['import', 'modules', 'Language'],
52 ['export', 'modules', 'Language'],38 ['export', 'modules', 'Language']
53 ['cake command', 'cake', 'Miscellaneous'],
54 ['Cakefile', 'cake', 'Miscellaneous'],
55 ['Source maps', 'source-maps', 'Miscellaneous']
56 ]39 ]
57 40
58 def additional_entries41 def additional_entries
59 entries = ENTRIES.dup42 entries = []
60 43
61 # Operators44 ENTRIES.each do |entry|
62 at_css('#operators ~ table').css('td:first-child > code').each do |node|45 raise "entry not found: #{entry.inspect}" unless at_css("[id='#{entry[1]}']")
63 node.content.split(', ').each do |name|46 entries << entry
64 next if %w(true false yes no on off this).include?(name)47 end
65 name.sub! %r{\Aa (.+) b\z}, '\1'48
66 id = name_to_id(name)49 css('.navbar > nav > .nav-link').each do |node|
67 node['id'] = id50 name = node.content.strip
68 entries << [name, id, 'Operators']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
69 end58 end
70 end59 end
71 60
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
72 entries71 entries
73 end72 end
74 73
lib/docs/filters/coffeescript/entries_v1.rb+86−0
@@ -0,0 +1,86 @@
1module 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
86end
lib/docs/scrapers/coffeescript.rb+16−5
@@ -2,22 +2,33 @@ module Docs · 1 unmodified line
2 class Coffeescript < UrlScraper2 class Coffeescript < UrlScraper
3 self.name = 'CoffeeScript'3 self.name = 'CoffeeScript'
4 self.type = 'coffeescript'4 self.type = 'coffeescript'
5 self.release = '1.12.6'
6 self.base_url = 'http://coffeescript.org'
7 self.links = {5 self.links = {
8 home: 'http://coffeescript.org',6 home: 'http://coffeescript.org',
9 code: 'https://github.com/jashkenas/coffeescript'7 code: 'https://github.com/jashkenas/coffeescript'
10 }8 }
11 9
12 html_filters.push 'coffeescript/clean_html', 'coffeescript/entries', 'title'
13
14 options[:title] = 'CoffeeScript'10 options[:title] = 'CoffeeScript'
15 options[:container] = '.container'
16 options[:skip_links] = true11 options[:skip_links] = true
17 12
18 options[:attribution] = <<-HTML13 options[:attribution] = <<-HTML
19 &copy; 2009&ndash;2017 Jeremy Ashkenas<br>14 &copy; 2009&ndash;2017 Jeremy Ashkenas<br>
20 Licensed under the MIT License.15 Licensed under the MIT License.
21 HTML16 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
22 end33 end
23end34end