Showing the changes to lib/docs (3 of 14 files). Show all
Unified · Split
| @@ -0,0 +1,46 @@ | ||
| 1 | +module Docs | |
| 2 | + class Go | |
| 3 | + class CleanHtmlFilter < Filter | |
| 4 | + def call | |
| 5 | + if root_page? | |
| 6 | + at_css('h1').content = 'Go Programming Language' | |
| 7 | + | |
| 8 | + # Remove empty columns | |
| 9 | + css('tr:first-child + tr', 'th:first-child + th', 'td:first-child + td').remove | |
| 10 | + | |
| 11 | + # Remove links to unscraped pages | |
| 12 | + css('td + td:empty').each do |node| | |
| 13 | + node.previous_element.content = node.previous_element.content | |
| 14 | + end | |
| 15 | + end | |
| 16 | + | |
| 17 | + css('#plusone', '#nav', '.pkgGopher', '#footer', '.collapsed').remove | |
| 18 | + | |
| 19 | + # Remove triangle character | |
| 20 | + css('h2', '.exampleHeading').each do |node| | |
| 21 | + node.content = node.content.sub("\u25BE", '') | |
| 22 | + node.name = 'h2' | |
| 23 | + end | |
| 24 | + | |
| 25 | + # Turn <dl> into <ul> | |
| 26 | + css('#short-nav', '#manual-nav').each do |node| | |
| 27 | + node.children = node.css('dd').tap { |nodes| nodes.each { |dd| dd.name = 'li' } } | |
| 28 | + node.name = 'ul' | |
| 29 | + end | |
| 30 | + | |
| 31 | + # Remove code highlighting | |
| 32 | + css('pre').each do |node| | |
| 33 | + node.content = node.content | |
| 34 | + end | |
| 35 | + | |
| 36 | + # Fix example markup | |
| 37 | + css('.play').each do |node| | |
| 38 | + node.children = node.at_css('.code').children | |
| 39 | + node.name = 'pre' | |
| 40 | + end | |
| 41 | + | |
| 42 | + doc | |
| 43 | + end | |
| 44 | + end | |
| 45 | + end | |
| 46 | +end | |
| @@ -0,0 +1,33 @@ | ||
| 1 | +module Docs | |
| 2 | + class Go | |
| 3 | + class EntriesFilter < Docs::EntriesFilter | |
| 4 | + def get_name | |
| 5 | + name = at_css('h1').content | |
| 6 | + name.sub! 'Package ', '' | |
| 7 | + name | |
| 8 | + end | |
| 9 | + | |
| 10 | + def get_type | |
| 11 | + subpath[/\A[^\/]+/] | |
| 12 | + end | |
| 13 | + | |
| 14 | + def additional_entries | |
| 15 | + css('#manual-nav a').each_with_object [] do |node, entries| | |
| 16 | + case node.content | |
| 17 | + when /type\ (\w+)/ | |
| 18 | + name = $1 | |
| 19 | + when /func\ (?:\(.+\)\ )?(\w+)\(/ | |
| 20 | + name = "#{$1}()" | |
| 21 | + name.prepend "#{$1}." if node['href'] =~ /#(\w+)\.#{$1}/ | |
| 22 | + end | |
| 23 | + | |
| 24 | + entries << ["#{name} (#{self.name})", node['href'][1..-1]] if name | |
| 25 | + end | |
| 26 | + end | |
| 27 | + | |
| 28 | + def include_default_entry? | |
| 29 | + !at_css('h1 + table.dir') | |
| 30 | + end | |
| 31 | + end | |
| 32 | + end | |
| 33 | +end | |
| @@ -0,0 +1,22 @@ | ||
| 1 | +module Docs | |
| 2 | + class Go < UrlScraper | |
| 3 | + self.type = 'go' | |
| 4 | + self.version = '1.2.1' | |
| 5 | + self.base_url = 'http://golang.org/pkg/' | |
| 6 | + | |
| 7 | + html_filters.push 'go/clean_html', 'go/entries' | |
| 8 | + | |
| 9 | + options[:container] = '#page .container' | |
| 10 | + | |
| 11 | + options[:attribution] = <<-HTML | |
| 12 | + © Google, Inc.<br> | |
| 13 | + Licensed under the Creative Commons Attribution License 3.0. | |
| 14 | + HTML | |
| 15 | + | |
| 16 | + private | |
| 17 | + | |
| 18 | + def parse(html) # Hook here because Nokogori removes whitespace from textareas | |
| 19 | + super html.gsub %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>' | |
| 20 | + end | |
| 21 | + end | |
| 22 | +end | |