History

Update nodejs to 16.1 and update previous version

Enoc committed 5 years ago

Commit 1ac3dd91 parent 1eaf12b5 files · +147 −86Browse files

Unified · Split

5 files
  1. assets/stylesheets/pages/_node.scss +3 −1
  2. lib/docs/filters/node/clean_html.rb +15 −0
  3. lib/docs/filters/node/entries.rb +12 −78
  4. lib/docs/filters/node/old_entries.rb +104 −0
  5. lib/docs/scrapers/node.rb +13 −7
assets/stylesheets/pages/_node.scss+3−1
@@ -10,6 +10,9 @@ · 9 unmodified lines
10 > h4 { @extend %block-label; }10 > h4 { @extend %block-label; }
11 > h2 + h2, > h3 + h3 { margin-top: 0; }11 > h2 + h2, > h3 + h3 { margin-top: 0; }
12 12
13 h3 { @extend %block-label, %label-blue}
14 h4 { @extend %block-label }
15
13 p > code, li > code, .type {16 p > code, li > code, .type {
14 white-space: normal;17 white-space: normal;
15 @extend %label;18 @extend %label;
@@ -24,4 +27,3 @@ · 8 unmodified lines
24 .srclink { float: right; }27 .srclink { float: right; }
25 details > table { margin: 0; }28 details > table { margin: 0; }
26}29}
27
lib/docs/filters/node/clean_html.rb+15−0
@@ -15,6 +15,8 @@ module Docs · 14 unmodified lines
15 end15 end
16 16
17 css('pre').each do |node|17 css('pre').each do |node|
18 next unless node.at_css('code')
19
18 if lang = node.at_css('code')['class']20 if lang = node.at_css('code')['class']
19 node['data-language'] = lang.remove(%r{lang(uage)?-})21 node['data-language'] = lang.remove(%r{lang(uage)?-})
20 end22 end
@@ -22,6 +24,19 @@ module Docs · 1 unmodified line
22 node.content = node.content24 node.content = node.content
23 end25 end
24 26
27 css('h3 > code, h4 > code, h5 > code').each do |node|
28 tmp = node.content
29 has_parethesis = true if tmp =~ /\(/
30 tmp.gsub!(/\(.*\)/, '')
31
32 if has_parethesis
33 tmp << '()'
34 end
35
36 node.parent['id'] = tmp
37
38 end
39
25 doc40 doc
26 end41 end
27 end42 end
lib/docs/filters/node/entries.rb+12−78
@@ -1,104 +1,38 @@
1module Docs1module Docs
2 class Node2 class Node
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 REPLACE_NAMES = {
5 'addons' => 'C/C++ Addons',
6 'debugger' => 'Debugger',
7 'deprecations' => 'Deprecated APIs',
8 'modules' => 'module' }
9
10 REPLACE_TYPES = {
11 'C++ Addons' => 'Miscellaneous',
12 'C/C++ Addons' => 'Miscellaneous',
13 'Debugger' => 'Miscellaneous',
14 'Deprecated APIs' => 'Miscellaneous',
15 'Tracing' => 'Miscellaneous',
16 'os' => 'OS',
17 'StringDecoder' => 'String Decoder',
18 'TLS (SSL)' => 'TLS/SSL',
19 'UDP / Datagram Sockets' => 'UDP/Datagram',
20 'VM (Executing JavaScript)' => 'VM',
21 'Executing JavaScript' => 'VM' }
22 4
23 def get_name5 def get_name
24 REPLACE_NAMES[slug] || slug6 type
25 end7 end
26 8
27 def get_type9 def get_type
28 type = at_css('h1').content.strip10 at_css('h2').content.strip
29 type.remove! %r{\[.*\]}
30 REPLACE_TYPES[type] || "#{type.first.upcase}#{type[1..-1]}"
31 end11 end
32 12
33 def additional_entries13 def additional_entries
34 return [] if type == 'Miscellaneous'
35
36 klass = nil
37 entries = []14 entries = []
38 15
39 css('> [id]').each do |node|16 css('h3 > code, h4 > code, h5 > code').each do |node|
40 next if node.name == 'h1'
41
42 klass = nil if node.name == 'h2'
43 name = node.content.strip
44 name.remove! %r{\s*\[src\]}
45
46 # Skip constructors
47 if name.start_with? 'new '
48 next
49 end
50
51 # Ignore most global objects (found elsewhere)
52 if type == 'Global Objects'
53 entries << [name, node['id']] if name.start_with?('_') || name == 'global'
54 next
55 end
56 17
57 # Classes18 case node.parent.child.content
58 if name.gsub! 'Class: ', ''19 when /Class/
59 name.remove! 'events.' # EventEmitter20 entries << ["Class #{node.parent['id']}", node.parent['id'], type]
60 klass = name21 when /Event/
61 entries << [name, node['id']]22 entries << ["Event #{node.parent['id']}", node.parent['id'], type]
62 next
63 end23 end
64 24
65 # Events25 if node.parent.child.is_a?(Nokogiri::XML::Text)
66 if name.sub! %r{\AEvent: '(.+)'\z}, '\1'
67 name << " event (#{klass || type})"
68 entries << [name, node['id']]
69 next26 next
27 else
28 entries << [node.parent['id'], node.parent['id'], type]
70 end29 end
71 30
72 name.gsub! %r{\(.*?\);?}, '()'
73 name.gsub! %r{\[.+?\]}, '[]'
74 name.remove! 'assert(), ' # assert/assert.ok
75
76 # Skip all that start with an uppercase letter ("Example") or include a space ("exports alias")
77 next unless (name.first.upcase! && !name.include?(' ')) || name.start_with?('Class Method')
78
79 # Differentiate server classes (http, https, net, etc.)
80 name.sub!('server.') { "#{(klass || 'https').sub('.', '_').downcase}." }
81 # Differentiate socket classes (net, dgram, etc.)
82 name.sub!('socket.') { "#{klass.sub('.', '_').downcase}." }
83
84 name.remove! 'Class Method:'
85 name.sub! 'buf.', 'buffer.'
86 name.sub! 'buf[', 'buffer['
87 name.sub! 'child.', 'childprocess.'
88 name.sub! 'decoder.', 'stringdecoder.'
89 name.sub! 'emitter.', 'eventemitter.'
90 name.sub! %r{\Arl\.}, 'interface.'
91 name.sub! 'rs.', 'readstream.'
92 name.sub! 'ws.', 'writestream.'
93
94 # Skip duplicates (listen, connect, etc.)
95 unless name == entries[-1].try(:first) || name == entries[-2].try(:first)
96 entries << [name, node['id']]
97 end
98 end31 end
99 32
100 entries33 entries
101 end34 end
35
102 end36 end
103 end37 end
104end38end
lib/docs/filters/node/old_entries.rb+104−0
@@ -0,0 +1,104 @@
1module Docs
2 class Node
3 class OldEntriesFilter < Docs::EntriesFilter
4 REPLACE_NAMES = {
5 'addons' => 'C/C++ Addons',
6 'debugger' => 'Debugger',
7 'deprecations' => 'Deprecated APIs',
8 'modules' => 'module' }
9
10 REPLACE_TYPES = {
11 'C++ Addons' => 'Miscellaneous',
12 'C/C++ Addons' => 'Miscellaneous',
13 'Debugger' => 'Miscellaneous',
14 'Deprecated APIs' => 'Miscellaneous',
15 'Tracing' => 'Miscellaneous',
16 'os' => 'OS',
17 'StringDecoder' => 'String Decoder',
18 'TLS (SSL)' => 'TLS/SSL',
19 'UDP / Datagram Sockets' => 'UDP/Datagram',
20 'VM (Executing JavaScript)' => 'VM',
21 'Executing JavaScript' => 'VM' }
22
23 def get_name
24 REPLACE_NAMES[slug] || slug
25 end
26
27 def get_type
28 type = at_css('h1').content.strip
29 type.remove! %r{\[.*\]}
30 REPLACE_TYPES[type] || "#{type.first.upcase}#{type[1..-1]}"
31 end
32
33 def additional_entries
34 return [] if type == 'Miscellaneous'
35
36 klass = nil
37 entries = []
38
39 css('> [id]').each do |node|
40 next if node.name == 'h1'
41
42 klass = nil if node.name == 'h2'
43 name = node.content.strip
44 name.remove! %r{\s*\[src\]}
45
46 # Skip constructors
47 if name.start_with? 'new '
48 next
49 end
50
51 # Ignore most global objects (found elsewhere)
52 if type == 'Global Objects'
53 entries << [name, node['id']] if name.start_with?('_') || name == 'global'
54 next
55 end
56
57 # Classes
58 if name.gsub! 'Class: ', ''
59 name.remove! 'events.' # EventEmitter
60 klass = name
61 entries << [name, node['id']]
62 next
63 end
64
65 # Events
66 if name.sub! %r{\AEvent: '(.+)'\z}, '\1'
67 name << " event (#{klass || type})"
68 entries << [name, node['id']]
69 next
70 end
71
72 name.gsub! %r{\(.*?\);?}, '()'
73 name.gsub! %r{\[.+?\]}, '[]'
74 name.remove! 'assert(), ' # assert/assert.ok
75
76 # Skip all that start with an uppercase letter ("Example") or include a space ("exports alias")
77 next unless (name.first.upcase! && !name.include?(' ')) || name.start_with?('Class Method')
78
79 # Differentiate server classes (http, https, net, etc.)
80 name.sub!('server.') { "#{(klass || 'https').sub('.', '_').downcase}." }
81 # Differentiate socket classes (net, dgram, etc.)
82 name.sub!('socket.') { "#{klass.sub('.', '_').downcase}." }
83
84 name.remove! 'Class Method:'
85 name.sub! 'buf.', 'buffer.'
86 name.sub! 'buf[', 'buffer['
87 name.sub! 'child.', 'childprocess.'
88 name.sub! 'decoder.', 'stringdecoder.'
89 name.sub! 'emitter.', 'eventemitter.'
90 name.sub! %r{\Arl\.}, 'interface.'
91 name.sub! 'rs.', 'readstream.'
92 name.sub! 'ws.', 'writestream.'
93
94 # Skip duplicates (listen, connect, etc.)
95 unless name == entries[-1].try(:first) || name == entries[-2].try(:first)
96 entries << [name, node['id']]
97 end
98 end
99
100 entries
101 end
102 end
103 end
104end
lib/docs/scrapers/node.rb+13−7
@@ -14,6 +14,7 @@ module Docs · 13 unmodified lines
14 options[:root_title] = 'Node.js'14 options[:root_title] = 'Node.js'
15 options[:container] = '#apicontent'15 options[:container] = '#apicontent'
16 options[:skip] = %w(index.html all.html documentation.html synopsis.html)16 options[:skip] = %w(index.html all.html documentation.html synopsis.html)
17 # options[:only] = ['addons.html']
17 18
18 options[:attribution] = <<-HTML19 options[:attribution] = <<-HTML
19 &copy; Joyent, Inc. and other Node contributors<br>20 &copy; Joyent, Inc. and other Node contributors<br>
@@ -23,38 +24,43 @@ module Docs · 3 unmodified lines
23 HTML24 HTML
24 25
25 version do26 version do
26 self.release = '15.5.0'27 self.release = '16.1.0'
27 self.base_url = 'https://nodejs.org/dist/latest-v15.x/docs/api/'28 self.base_url = 'https://nodejs.org/api/'
28 end29 end
29 30
30 version '14 LTS' do31 version '14 LTS' do
31 self.release = '14.15.3'32 self.release = '14.17.0'
32 self.base_url = 'https://nodejs.org/dist/latest-v14.x/docs/api/'33 self.base_url = 'https://nodejs.org/dist/latest-v14.x/docs/api/'
33 end34 end
34 35
35 version '12 LTS' do36 version '12 LTS' do
36 self.release = '12.19.0'37 self.release = '12.22.1'
37 self.base_url = 'https://nodejs.org/dist/latest-v12.x/docs/api/'38 self.base_url = 'https://nodejs.org/dist/latest-v12.x/docs/api/'
39 html_filters.replace('node/entries', 'node/old_entries')
38 end40 end
39 41
40 version '10 LTS' do42 version '10 LTS' do
41 self.release = '10.16.3'43 self.release = '10.24.1'
42 self.base_url = 'https://nodejs.org/dist/latest-v10.x/docs/api/'44 self.base_url = 'https://nodejs.org/dist/latest-v10.x/docs/api/'
45 html_filters.replace('node/entries', 'node/old_entries')
43 end46 end
44 47
45 version '8 LTS' do48 version '8 LTS' do
46 self.release = '8.16.1'49 self.release = '8.17.0'
47 self.base_url = 'https://nodejs.org/dist/latest-v8.x/docs/api/'50 self.base_url = 'https://nodejs.org/dist/latest-v8.x/docs/api/'
51 html_filters.replace('node/entries', 'node/old_entries')
48 end52 end
49 53
50 version '6 LTS' do54 version '6 LTS' do
51 self.release = '6.14.4'55 self.release = '6.17.1'
52 self.base_url = 'https://nodejs.org/dist/latest-v6.x/docs/api/'56 self.base_url = 'https://nodejs.org/dist/latest-v6.x/docs/api/'
57 html_filters.replace('node/entries', 'node/old_entries')
53 end58 end
54 59
55 version '4 LTS' do60 version '4 LTS' do
56 self.release = '4.9.1'61 self.release = '4.9.1'
57 self.base_url = 'https://nodejs.org/dist/latest-v4.x/docs/api/'62 self.base_url = 'https://nodejs.org/dist/latest-v4.x/docs/api/'
63 html_filters.replace('node/entries', 'node/old_entries')
58 end64 end
59 65
60 def get_latest_version(opts)66 def get_latest_version(opts)