Unified · Split
| @@ -2,52 +2,24 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Coffeescript |
| 3 | 3 | class CleanHtmlFilter < Filter |
| 4 | 4 | def call |
| 5 | − css('#top', '.minibutton', '.clear').remove | |
| 5 | + @doc = at_css('main') | |
| 6 | 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 | |
| 7 | + css('> header', '#resources', '#changelog').remove | |
| 35 | 8 | |
| 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 | |
| 42 | 12 | end |
| 43 | 13 | |
| 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 | |
| 47 | 16 | end |
| 48 | 17 | |
| 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') | |
| 51 | 23 | end |
| 52 | 24 | |
| 53 | 25 | css('.code pre:first-child').each do |node| |
| @@ -58,8 +30,12 @@ module Docs · 4 unmodified lines | ||
| 58 | 30 | node['data-language'] = 'javascript' |
| 59 | 31 | end |
| 60 | 32 | |
| 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 | |
| 63 | 39 | end |
| 64 | 40 | |
| 65 | 41 | doc |
| @@ -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 | |
| @@ -2,12 +2,9 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Coffeescript |
| 3 | 3 | class EntriesFilter < Docs::EntriesFilter |
| 4 | 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'], | |
| 5 | + ['coffee command', 'cli', 'Miscellaneous'], | |
| 6 | + ['->', 'functions', 'Statements'], | |
| 7 | + ['await', 'async-functions', 'Statements'], | |
| 11 | 8 | ['if...then...else', 'conditionals', 'Statements'], |
| 12 | 9 | ['unless', 'conditionals', 'Statements'], |
| 13 | 10 | ['... splats', 'splats', 'Language'], |
| @@ -19,56 +16,58 @@ module Docs · 5 unmodified lines | ||
| 19 | 16 | ['until', 'loops', 'Statements'], |
| 20 | 17 | ['loop', 'loops', 'Statements'], |
| 21 | 18 | ['do', 'loops', 'Statements'], |
| 22 | − ['Array slicing and splicing', 'slices', 'Language'], | |
| 23 | 19 | ['Ranges', 'slices', 'Language'], |
| 24 | − ['Expressions', 'expressions', 'Language'], | |
| 25 | 20 | ['?', 'existential-operator', 'Operators'], |
| 26 | 21 | ['?=', 'existential-operator', 'Operators'], |
| 27 | 22 | ['?.', 'existential-operator', 'Operators'], |
| 28 | 23 | ['class', 'classes', 'Statements'], |
| 29 | − ['extends', 'classes', 'Operators'], | |
| 24 | + ['extends', 'classes', 'Statements'], | |
| 30 | 25 | ['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'], | |
| 35 | 27 | ['=>', 'fat-arrow', 'Statements'], |
| 36 | − ['yield', 'fat-arrow', 'Statements'], | |
| 37 | − ['for...from', 'fat-arrow', 'Statements'], | |
| 38 | − ['Embedded JavaScript', 'embedded', 'Language'], | |
| 28 | + ['yield', 'generators', 'Statements'], | |
| 39 | 29 | ['switch...when...else', 'switch', 'Statements'], |
| 40 | − ['try...catch...finally', 'try-catch', 'Statements'], | |
| 41 | − ['Chained comparisons', 'comparisons', 'Language'], | |
| 30 | + ['try...catch...finally', 'try', 'Statements'], | |
| 42 | 31 | ['#{} interpolation', 'strings', 'Language'], |
| 43 | 32 | ['Block strings', 'strings', 'Language'], |
| 44 | 33 | ['"""', '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'], | |
| 49 | 36 | ['///', 'regexes', 'Language'], |
| 50 | − ['Modules', 'modules', 'Language'], | |
| 51 | 37 | ['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'] | |
| 56 | 39 | ] |
| 57 | 40 | |
| 58 | 41 | def additional_entries |
| 59 | − entries = ENTRIES.dup | |
| 42 | + entries = [] | |
| 60 | 43 | |
| 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 | |
| 69 | 58 | end |
| 70 | 59 | 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 | 71 | entries |
| 73 | 72 | end |
| 74 | 73 | |
| @@ -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 | |
| @@ -2,22 +2,33 @@ module Docs · 1 unmodified line | ||
| 2 | 2 | class Coffeescript < UrlScraper |
| 3 | 3 | self.name = 'CoffeeScript' |
| 4 | 4 | self.type = 'coffeescript' |
| 5 | − self.release = '1.12.6' | |
| 6 | − self.base_url = 'http://coffeescript.org' | |
| 7 | 5 | self.links = { |
| 8 | 6 | home: 'http://coffeescript.org', |
| 9 | 7 | code: 'https://github.com/jashkenas/coffeescript' |
| 10 | 8 | } |
| 11 | 9 | |
| 12 | − html_filters.push 'coffeescript/clean_html', 'coffeescript/entries', 'title' | |
| 13 | − | |
| 14 | 10 | options[:title] = 'CoffeeScript' |
| 15 | − options[:container] = '.container' | |
| 16 | 11 | options[:skip_links] = true |
| 17 | 12 | |
| 18 | 13 | options[:attribution] = <<-HTML |
| 19 | 14 | © 2009–2017 Jeremy Ashkenas<br> |
| 20 | 15 | Licensed under the MIT License. |
| 21 | 16 | 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 | 33 | end |
| 23 | 34 | end |