History

Merge pull request #1606 from MasterEnoc/cpp

C/C++ update

Simon Legner committed 4 years ago

Commit 45d6e222 parents 9b8819a bffc19413 files · +104 −121Browse files

Unified · Split

13 files
  1. assets/stylesheets/application.css.scss +1 −1
  2. assets/stylesheets/pages/_cppref.scss +1 −1
  3. lib/docs/filters/c/entries.rb +3 −0
  4. lib/docs/filters/c/fix_urls.rb +0 −11
  5. lib/docs/filters/cpp/entries.rb +19 −1
  6. lib/docs/filters/cpp/fix_urls.rb +0 −11
  7. lib/docs/filters/cppref/clean_html.rb +15 −1
  8. lib/docs/filters/cppref/fix_code.rb +1 −1
  9. lib/docs/scrapers/c.rb +0 −42
  10. lib/docs/scrapers/cpp.rb +0 −52
  11. lib/docs/scrapers/cppref/c.rb +12 −0
  12. lib/docs/scrapers/cppref/cpp.rb +19 −0
  13. lib/docs/scrapers/cppref/cppref.rb +33 −0
assets/stylesheets/application.css.scss+1−1
@@ -39,7 +39,7 @@ · 38 unmodified lines
3939 'pages/async',
4040 'pages/bash',
4141 'pages/bootstrap',
42− 'pages/c',
42+ 'pages/cppref',
4343 'pages/cakephp',
4444 'pages/clojure',
4545 'pages/codeception',
assets/stylesheets/pages/_cppref.scssrenamed from assets/stylesheets/pages/_c.scss+1−1
@@ -1,4 +1,4 @@
1−._c {
1+._cppref {
22 > h2, > h3 { @extend %block-heading; }
33 > h4 { @extend %block-label, %label-blue; }
44 .fmbox { @extend %note; }
lib/docs/filters/c/entries.rb+3−0
@@ -22,6 +22,9 @@ module Docs · 21 unmodified lines
2222 end
2323
2424 def get_type
25+
26+ return "C keywords" if slug =~ /keyword/
27+
2528 type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content)
2629 type.strip!
2730 type.remove! ' library'
lib/docs/filters/c/fix_urls.rb+0−11
@@ -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
lib/docs/filters/cpp/entries.rb+19−1
@@ -1,6 +1,8 @@
11 module Docs
22 class Cpp
33 class EntriesFilter < Docs::EntriesFilter
4+ @@duplicate_names = []
5+
46 REPLACE_NAMES = {
57 'Error directive' => '#error directive',
68 'Filename and line information' => '#line directive',
@@ -11,7 +13,8 @@ module Docs · 4 unmodified lines
1113 def get_name
1214 name = at_css('#firstHeading').content.strip
1315 name = format_name(name)
14− name.split(',').first
16+ name = name.split(',').first
17+ name
1518 end
1619
1720 def get_type
@@ -61,6 +64,21 @@ module Docs · 43 unmodified lines
6164
6265 REPLACE_NAMES[name] || name
6366 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+
6482 end
6583 end
6684 end
lib/docs/filters/cpp/fix_urls.rb+0−11
@@ -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
lib/docs/filters/cppref/clean_html.rbrenamed from lib/docs/filters/c/clean_html.rb+15−1
@@ -1,5 +1,5 @@
11 module Docs
2− class C
2+ class Cppref
33 class CleanHtmlFilter < Filter
44 def call
55 css('h1').remove if root_page?
@@ -109,6 +109,20 @@ module Docs · 103 unmodified lines
109109 node['src'] = node['src'].sub! %r{http://en.cppreference.com/common/([^"']+?)\.svg}, 'http://upload.cppreference.com/mwiki/\1.svg'
110110 end
111111
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+
112126 doc
113127 end
114128 end
lib/docs/filters/cppref/fix_code.rbrenamed from lib/docs/filters/c/fix_code.rb+1−1
@@ -1,5 +1,5 @@
11 module Docs
2− class C
2+ class Cppref
33 class FixCodeFilter < Filter
44 def call
55 css('div > span.source-c', 'div > span.source-cpp').each do |node|
lib/docs/scrapers/c.rb+0−42
@@ -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− &copy; 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
lib/docs/scrapers/cpp.rb+0−52
@@ -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− &copy; 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
lib/docs/scrapers/cppref/c.rb+12−0
@@ -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
lib/docs/scrapers/cppref/cpp.rb+19−0
@@ -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
lib/docs/scrapers/cppref/cppref.rb+33−0
@@ -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+ &copy; 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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t