Showing the changes to lib/docs (5 of 16 files). Show all
Unified · Split
| @@ -0,0 +1,37 @@ | |||
| 1 | module Docs | ||
| 2 | class C | ||
| 3 | class CleanHtmlFilter < Filter | ||
| 4 | def call | ||
| 5 | if root_page? | ||
| 6 | doc.inner_html = ' ' | ||
| 7 | return doc | ||
| 8 | end | ||
| 9 | |||
| 10 | css('#siteSub', '#contentSub', '.printfooter', '.t-navbar', '.editsection', '#toc', '.t-dsc-sep', '.t-dcl-sep', | ||
| 11 | '#catlinks', '.ambox-notice', '.mw-cite-backlink', '.t-sdsc-sep:first-child:last-child').remove | ||
| 12 | |||
| 13 | css('#bodyContent', '.mw-content-ltr', 'span[style]').each do |node| | ||
| 14 | node.before(node.children).remove | ||
| 15 | end | ||
| 16 | |||
| 17 | css('h2 > span[id]', 'h3 > span[id]', 'h4 > span[id]', 'h5 > span[id]', 'h6 > span[id]').each do |node| | ||
| 18 | node.parent['id'] = node['id'] | ||
| 19 | node.before(node.children).remove | ||
| 20 | end | ||
| 21 | |||
| 22 | css('table[style]', 'th[style]', 'td[style]').remove_attr('style') | ||
| 23 | |||
| 24 | css('.t-dsc-hitem > td', '.t-dsc-header > td').each do |node| | ||
| 25 | node.name = 'th' | ||
| 26 | node.content = ' ' if node.content.empty? | ||
| 27 | end | ||
| 28 | |||
| 29 | css('tt').each do |node| | ||
| 30 | node.name = 'code' | ||
| 31 | end | ||
| 32 | |||
| 33 | doc | ||
| 34 | end | ||
| 35 | end | ||
| 36 | end | ||
| 37 | end | ||
| @@ -0,0 +1,44 @@ | |||
| 1 | module Docs | ||
| 2 | class C | ||
| 3 | class EntriesFilter < Docs::EntriesFilter | ||
| 4 | ADDITIONAL_NAMES = { | ||
| 5 | 'Conditional inclusion' => %w(if else elif ifdef ifndef endif).map { |s| "##{s} directive" }, | ||
| 6 | 'Function specifiers' => ['inline specifier', '_Noreturn specifier'] } | ||
| 7 | |||
| 8 | REPLACE_NAMES = { | ||
| 9 | 'Error directive' => '#error directive', | ||
| 10 | 'Filename and line information' => '#line directive', | ||
| 11 | 'Implementation defined behavior control' => '#pragma directive', | ||
| 12 | 'Replacing text macros' => '#define directive', | ||
| 13 | 'Source file inclusion' => '#include directive', | ||
| 14 | 'Warning directive' => '#warning directive' } | ||
| 15 | |||
| 16 | def get_name | ||
| 17 | name = at_css('#firstHeading').content.strip | ||
| 18 | name.sub! 'C keywords: ', '' | ||
| 19 | name.sub! %r{\s\(.+\)}, '' | ||
| 20 | name = name.split(',').first | ||
| 21 | REPLACE_NAMES[name] || name | ||
| 22 | end | ||
| 23 | |||
| 24 | def get_type | ||
| 25 | if type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content) | ||
| 26 | type.strip! | ||
| 27 | type.sub! ' library', '' | ||
| 28 | type.sub! ' utilities', '' | ||
| 29 | type | ||
| 30 | end | ||
| 31 | end | ||
| 32 | |||
| 33 | def additional_entries | ||
| 34 | names = at_css('#firstHeading').content.split(',')[1..-1] | ||
| 35 | names.concat ADDITIONAL_NAMES[name] || [] | ||
| 36 | names.map { |name| [name] } | ||
| 37 | end | ||
| 38 | |||
| 39 | def include_default_entry? | ||
| 40 | at_css '.t-navbar > div:nth-child(4) > a' | ||
| 41 | end | ||
| 42 | end | ||
| 43 | end | ||
| 44 | end | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | module Docs | ||
| 2 | class C | ||
| 3 | class FixCodeFilter < Filter | ||
| 4 | def call | ||
| 5 | css('div > span.source-c').each do |node| | ||
| 6 | node.inner_html = node.inner_html.gsub(/<br>\n?/, "\n").gsub("\n</p>\n", "</p>\n") | ||
| 7 | node.parent.name = 'pre' | ||
| 8 | node.parent['class'] = 'source-c' | ||
| 9 | node.parent.content = node.content | ||
| 10 | end | ||
| 11 | |||
| 12 | nbsp = Nokogiri::HTML(' ').text | ||
| 13 | css('pre').each do |node| | ||
| 14 | node.content = node.content.gsub(nbsp, ' ') | ||
| 15 | end | ||
| 16 | |||
| 17 | doc | ||
| 18 | end | ||
| 19 | end | ||
| 20 | end | ||
| 21 | end | ||
| @@ -0,0 +1,11 @@ | |||
| 1 | module Docs | ||
| 2 | class C | ||
| 3 | class FixUrlsFilter < Filter | ||
| 4 | def call | ||
| 5 | html.gsub! File.join(C.base_url, C.root_path), C.base_url[0..-2] | ||
| 6 | html.gsub! %r{#{C.base_url}([^"']+?)\.html}, "#{C.base_url}\\1" | ||
| 7 | html | ||
| 8 | end | ||
| 9 | end | ||
| 10 | end | ||
| 11 | end | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | module Docs | ||
| 2 | class C < FileScraper | ||
| 3 | self.type = 'c' | ||
| 4 | self.dir = '/Users/Thibaut/DevDocs/Docs/C/en/c' | ||
| 5 | self.base_url = 'http://en.cppreference.com/w/c/' | ||
| 6 | self.root_path = 'header.html' | ||
| 7 | |||
| 8 | html_filters.insert_before 'clean_html', 'c/fix_code' | ||
| 9 | html_filters.push 'c/entries', 'c/clean_html', 'title' | ||
| 10 | text_filters.push 'c/fix_urls' | ||
| 11 | |||
| 12 | options[:container] = '#content' | ||
| 13 | options[:title] = false | ||
| 14 | options[:root_title] = 'C Programming Language' | ||
| 15 | options[:skip] = %w(language/history.html) | ||
| 16 | |||
| 17 | options[:attribution] = <<-HTML | ||
| 18 | © cppreference.com<br> | ||
| 19 | Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0. | ||
| 20 | HTML | ||
| 21 | end | ||
| 22 | end | ||