C/C++ update
Unified · Split
| @@ -39,7 +39,7 @@ · 38 unmodified lines | ||
| 39 | 39 | 'pages/async', |
| 40 | 40 | 'pages/bash', |
| 41 | 41 | 'pages/bootstrap', |
| 42 | − 'pages/c', | |
| 42 | + 'pages/cppref', | |
| 43 | 43 | 'pages/cakephp', |
| 44 | 44 | 'pages/clojure', |
| 45 | 45 | 'pages/codeception', |
| @@ -1,4 +1,4 @@ | ||
| 1 | −._c { | |
| 1 | +._cppref { | |
| 2 | 2 | > h2, > h3 { @extend %block-heading; } |
| 3 | 3 | > h4 { @extend %block-label, %label-blue; } |
| 4 | 4 | .fmbox { @extend %note; } |
| @@ -22,6 +22,9 @@ module Docs · 21 unmodified lines | ||
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 24 | def get_type |
| 25 | + | |
| 26 | + return "C keywords" if slug =~ /keyword/ | |
| 27 | + | |
| 25 | 28 | type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content) |
| 26 | 29 | type.strip! |
| 27 | 30 | type.remove! ' library' |
| @@ -1,11 +0,0 @@ | ||
| 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 | |
| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | module Docs |
| 2 | 2 | class Cpp |
| 3 | 3 | class EntriesFilter < Docs::EntriesFilter |
| 4 | + @@duplicate_names = [] | |
| 5 | + | |
| 4 | 6 | REPLACE_NAMES = { |
| 5 | 7 | 'Error directive' => '#error directive', |
| 6 | 8 | 'Filename and line information' => '#line directive', |
| @@ -11,7 +13,8 @@ module Docs · 4 unmodified lines | ||
| 11 | 13 | def get_name |
| 12 | 14 | name = at_css('#firstHeading').content.strip |
| 13 | 15 | name = format_name(name) |
| 14 | − name.split(',').first | |
| 16 | + name = name.split(',').first | |
| 17 | + name | |
| 15 | 18 | end |
| 16 | 19 | |
| 17 | 20 | def get_type |
| @@ -61,6 +64,21 @@ module Docs · 43 unmodified lines | ||
| 61 | 64 | |
| 62 | 65 | REPLACE_NAMES[name] || name |
| 63 | 66 | end |
| 67 | + | |
| 68 | + # Avoid duplicate pages, these duplicate page are the same page for | |
| 69 | + # multiple functions that are organized in the same page because provide | |
| 70 | + # similar behavior but have different name. | |
| 71 | + def entries | |
| 72 | + entries = [] | |
| 73 | + | |
| 74 | + if !(@@duplicate_names.include?(name)) | |
| 75 | + @@duplicate_names.push(name) | |
| 76 | + entries << default_entry if root_page? || include_default_entry? | |
| 77 | + entries.concat(additional_entries) | |
| 78 | + build_entries(entries) | |
| 79 | + end | |
| 80 | + end | |
| 81 | + | |
| 64 | 82 | end |
| 65 | 83 | end |
| 66 | 84 | end |
| @@ -1,11 +0,0 @@ | ||
| 1 | −module Docs | |
| 2 | − class Cpp | |
| 3 | − class FixUrlsFilter < Filter | |
| 4 | − def call | |
| 5 | − html.gsub! File.join(Cpp.base_url, Cpp.root_path), Cpp.base_url[0..-2] | |
| 6 | − html.gsub! %r{#{Cpp.base_url}([^"']+?)\.html}, "#{Cpp.base_url}\\1" | |
| 7 | − html | |
| 8 | − end | |
| 9 | − end | |
| 10 | − end | |
| 11 | −end | |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | module Docs |
| 2 | − class C | |
| 2 | + class Cppref | |
| 3 | 3 | class CleanHtmlFilter < Filter |
| 4 | 4 | def call |
| 5 | 5 | css('h1').remove if root_page? |
| @@ -109,6 +109,20 @@ module Docs · 103 unmodified lines | ||
| 109 | 109 | node['src'] = node['src'].sub! %r{http://en.cppreference.com/common/([^"']+?)\.svg}, 'http://upload.cppreference.com/mwiki/\1.svg' |
| 110 | 110 | end |
| 111 | 111 | |
| 112 | + # temporary solution due lack of mathjax/mathml support | |
| 113 | + css('.t-mfrac').each do |node| | |
| 114 | + fraction = Nokogiri::XML::Node.new('span', doc) | |
| 115 | + | |
| 116 | + node.css('td').each do |node| | |
| 117 | + fraction.add_child("<span>#{node.content}</span>") | |
| 118 | + end | |
| 119 | + | |
| 120 | + fraction.last_element_child().before("<span>/</span>") | |
| 121 | + | |
| 122 | + node.before(fraction) | |
| 123 | + node.remove | |
| 124 | + end | |
| 125 | + | |
| 112 | 126 | doc |
| 113 | 127 | end |
| 114 | 128 | end |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | module Docs |
| 2 | − class C | |
| 2 | + class Cppref | |
| 3 | 3 | class FixCodeFilter < Filter |
| 4 | 4 | def call |
| 5 | 5 | css('div > span.source-c', 'div > span.source-cpp').each do |node| |
| @@ -1,42 +0,0 @@ | ||
| 1 | −module Docs | |
| 2 | − class C < FileScraper | |
| 3 | − self.type = 'c' | |
| 4 | − self.base_url = 'http://en.cppreference.com/w/c/' | |
| 5 | − self.root_path = 'header.html' | |
| 6 | − | |
| 7 | − html_filters.insert_before 'clean_html', 'c/fix_code' | |
| 8 | − html_filters.push 'c/entries', 'c/clean_html', 'title' | |
| 9 | − text_filters.push 'c/fix_urls' | |
| 10 | − | |
| 11 | − options[:decode_and_clean_paths] = true | |
| 12 | − options[:container] = '#content' | |
| 13 | − options[:title] = false | |
| 14 | − options[:root_title] = 'C Programming Language' | |
| 15 | − options[:skip] = %w(language/history.html) | |
| 16 | − options[:skip_patterns] = [/experimental/] | |
| 17 | − | |
| 18 | − options[:fix_urls] = ->(url) do | |
| 19 | − url.sub! %r{\A.+/http%3A/}, 'http://' | |
| 20 | − url.sub! 'http://en.cppreference.com/upload.cppreference.com', 'http://upload.cppreference.com' | |
| 21 | − url | |
| 22 | − end | |
| 23 | − | |
| 24 | − options[:attribution] = <<-HTML | |
| 25 | − © cppreference.com<br> | |
| 26 | − Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0. | |
| 27 | − HTML | |
| 28 | − | |
| 29 | − def get_latest_version(opts) | |
| 30 | − doc = fetch_doc('https://en.cppreference.com/w/Cppreference:Archives', opts) | |
| 31 | − link = doc.at_css('a[title^="File:"]') | |
| 32 | − date = link.content.scan(/(\d+)\./)[0][0] | |
| 33 | − DateTime.strptime(date, '%Y%m%d').to_time.to_i | |
| 34 | − end | |
| 35 | − | |
| 36 | − private | |
| 37 | − | |
| 38 | − def file_path_for(*) | |
| 39 | − URI.unescape(super) | |
| 40 | − end | |
| 41 | − end | |
| 42 | −end | |
| @@ -1,52 +0,0 @@ | ||
| 1 | −module Docs | |
| 2 | − class Cpp < FileScraper | |
| 3 | − self.name = 'C++' | |
| 4 | − self.slug = 'cpp' | |
| 5 | − self.type = 'c' | |
| 6 | − self.base_url = 'http://en.cppreference.com/w/cpp/' | |
| 7 | − self.root_path = 'header.html' | |
| 8 | − | |
| 9 | − html_filters.insert_before 'clean_html', 'c/fix_code' | |
| 10 | − html_filters.push 'cpp/entries', 'c/clean_html', 'title' | |
| 11 | − text_filters.push 'cpp/fix_urls' | |
| 12 | − | |
| 13 | − options[:decode_and_clean_paths] = true | |
| 14 | − options[:container] = '#content' | |
| 15 | − options[:title] = false | |
| 16 | − options[:root_title] = 'C++ Programming Language' | |
| 17 | − options[:skip] = %w( | |
| 18 | − language/extending_std.html | |
| 19 | − language/history.html | |
| 20 | − regex/ecmascript.html | |
| 21 | − regex/regex_token_iterator/operator_cmp.html | |
| 22 | − ) | |
| 23 | − options[:skip_patterns] = [/experimental/] | |
| 24 | − options[:only_patterns] = [/\.html\z/] | |
| 25 | − | |
| 26 | − options[:fix_urls] = ->(url) do | |
| 27 | − url = CGI.unescape(url) | |
| 28 | − url.sub! %r{\A.+/http%3A/}, 'http://' | |
| 29 | − url.sub! 'http://en.cppreference.com/upload.cppreference.com', 'http://upload.cppreference.com' | |
| 30 | − url | |
| 31 | − end | |
| 32 | − | |
| 33 | − options[:attribution] = <<-HTML | |
| 34 | − © cppreference.com<br> | |
| 35 | − Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0. | |
| 36 | − HTML | |
| 37 | − | |
| 38 | − # Same as get_latest_version in lib/docs/scrapers/c.rb | |
| 39 | − def get_latest_version(opts) | |
| 40 | − doc = fetch_doc('https://en.cppreference.com/w/Cppreference:Archives', opts) | |
| 41 | − link = doc.at_css('a[title^="File:"]') | |
| 42 | − date = link.content.scan(/(\d+)\./)[0][0] | |
| 43 | − DateTime.strptime(date, '%Y%m%d').to_time.to_i | |
| 44 | − end | |
| 45 | − | |
| 46 | − private | |
| 47 | − | |
| 48 | − def file_path_for(*) | |
| 49 | − URI.unescape(super) | |
| 50 | − end | |
| 51 | − end | |
| 52 | −end | |
| @@ -0,0 +1,12 @@ | ||
| 1 | +module Docs | |
| 2 | + class C < Cppref | |
| 3 | + self.name = 'c' | |
| 4 | + self.slug = 'c' | |
| 5 | + self.base_url = 'https://en.cppreference.com/w/c/' | |
| 6 | + | |
| 7 | + html_filters.insert_before 'cppref/clean_html', 'c/entries' | |
| 8 | + | |
| 9 | + options[:root_title] = 'C Programming Language' | |
| 10 | + | |
| 11 | + end | |
| 12 | +end | |
| @@ -0,0 +1,19 @@ | ||
| 1 | +module Docs | |
| 2 | + class Cpp < Cppref | |
| 3 | + self.name = 'C++' | |
| 4 | + self.slug = 'cpp' | |
| 5 | + self.base_url = 'https://en.cppreference.com/w/cpp/' | |
| 6 | + | |
| 7 | + html_filters.insert_before 'cppref/clean_html', 'cpp/entries' | |
| 8 | + | |
| 9 | + options[:root_title] = 'C++ Programming Language' | |
| 10 | + | |
| 11 | + options[:skip] = %w( | |
| 12 | + language/extending_std.html | |
| 13 | + language/history.html | |
| 14 | + regex/ecmascript.html | |
| 15 | + regex/regex_token_iterator/operator_cmp.html | |
| 16 | + ) | |
| 17 | + | |
| 18 | + end | |
| 19 | +end | |
| @@ -0,0 +1,33 @@ | ||
| 1 | +module Docs | |
| 2 | + class Cppref < UrlScraper | |
| 3 | + self.abstract = true | |
| 4 | + self.type = 'cppref' | |
| 5 | + self.root_path = 'header' | |
| 6 | + | |
| 7 | + html_filters.insert_before 'clean_html', 'cppref/fix_code' | |
| 8 | + html_filters.push 'cppref/clean_html', 'title' | |
| 9 | + | |
| 10 | + options[:decode_and_clean_paths] = true | |
| 11 | + options[:container] = '#content' | |
| 12 | + options[:title] = false | |
| 13 | + options[:skip] = %w(language/history.html) | |
| 14 | + | |
| 15 | + options[:skip_patterns] = [ | |
| 16 | + /experimental/ | |
| 17 | + ] | |
| 18 | + | |
| 19 | + options[:attribution] = <<-HTML | |
| 20 | + © cppreference.com<br> | |
| 21 | + Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0. | |
| 22 | + HTML | |
| 23 | + | |
| 24 | + # Check if the 'headers' page has changed | |
| 25 | + def get_latest_version(opts) | |
| 26 | + doc = fetch_doc(self.base_url + self.root_path, opts) | |
| 27 | + date = doc.at_css('#footer-info-lastmod').content | |
| 28 | + date = date.match(/[[:digit:]]{1,2} .* [[:digit:]]{4}/).to_s | |
| 29 | + date = DateTime.strptime(date, '%e %B %Y').to_time.to_i | |
| 30 | + end | |
| 31 | + | |
| 32 | + end | |
| 33 | +end | |