History

Update HTTP documentation and bring back RFC entries

Closes #578.

Thibaut Courouble committed 9 years ago

Commit a64d8f31 parent 7e51d082 files · +95 −3Browse files

Showing the changes to lib/docs (2 of 2 files). Show all

Unified · Split

2 files
  1. lib/docs/filters/http/entries.rb +91 −3
  2. lib/docs/scrapers/http.rb +4 −0
lib/docs/filters/http/entries.rb+91−3
@@ -6,9 +6,9 @@ module Docs · 5 unmodified lines
66 name = at_css('h1').content
77 name.remove! %r{\A.+\:}
88 name.remove! %r{\A.+\-\-}
9− rfc = slug.sub('rfc', 'RFC ')
9+ name = 'WebDAV' if name.include?('WebDAV')
1010 "#{rfc}: #{name.strip}"
11− elsif slug.start_with?('Status')
11+ elsif slug.start_with?('Status/')
1212 at_css('code').content
1313 else
1414 name = super
@@ -22,7 +22,7 @@ module Docs · 7 unmodified lines
2222 end
2323
2424 def get_type
25− return 'RFC' if current_url.host == 'tools.ietf.org'
25+ return name if current_url.host == 'tools.ietf.org'
2626
2727 if slug.start_with?('Headers/Content-Security-Policy')
2828 'CSP'
@@ -38,6 +38,94 @@ module Docs · 9 unmodified lines
3838 'Guides'
3939 end
4040 end
41+
42+ def rfc
43+ slug.sub('rfc', 'RFC ')
44+ end
45+
46+ SECTIONS = {
47+ 'rfc2616' => [
48+ [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15],
49+ [14],
50+ []
51+ ],
52+ 'rfc4918' => [
53+ [],
54+ [11],
55+ []
56+ ],
57+ 'rfc7230' => [
58+ (2..9).to_a,
59+ [],
60+ []
61+ ],
62+ 'rfc7231' => [
63+ [3, 8, 9],
64+ [],
65+ [4, 5, 6, 7]
66+ ],
67+ 'rfc7232' => [
68+ [5, 6, 7, 8],
69+ [2, 3, 4],
70+ []
71+ ],
72+ 'rfc7233' => [
73+ [5, 6],
74+ [2, 3, 4],
75+ []
76+ ],
77+ 'rfc7234' => [
78+ [3, 6, 7, 8],
79+ [4, 5],
80+ []
81+ ],
82+ 'rfc7235' => [
83+ [2, 5, 6],
84+ [3, 4],
85+ []
86+ ]
87+ }
88+
89+ LEVEL_1 = /\A(\d+)\z/
90+ LEVEL_2 = /\A(\d+)\.\d+\z/
91+ LEVEL_3 = /\A(\d+)\.\d+\.\d+\z/
92+
93+ def additional_entries
94+ return [] unless current_url.host == 'tools.ietf.org'
95+ type = nil
96+
97+ css('a[href^="#section-"]').each_with_object([]) do |node, entries|
98+ id = node['href'].remove('#')
99+ break entries if entries.any? { |e| e[1] == id }
100+
101+ content = node.next.content.strip
102+ content.remove! %r{\s*\.+\d*\z}
103+ content.remove! %r{\A[\.\s]+}
104+
105+ name = "#{content} (#{rfc})"
106+ number = node.content.strip
107+
108+ if number =~ LEVEL_1
109+ if SECTIONS[slug][0].include?($1.to_i)
110+ entries << [name, id, self.name]
111+ end
112+
113+ type = content.sub(/\ Definitions\z/, 's')
114+ if type.include?('Header Fields')
115+ type = 'Headers'
116+ elsif type.include?('Status Codes')
117+ type = 'Status'
118+ elsif type.include?('Methods')
119+ type = 'Methods'
120+ else
121+ type = self.name
122+ end
123+ elsif (number =~ LEVEL_2 && SECTIONS[slug][1].include?($1.to_i)) ||
124+ (number =~ LEVEL_3 && SECTIONS[slug][2].include?($1.to_i))
125+ entries << [name, id, (name =~ /\A\d\d\d/ ? 'Status' : type )]
126+ end
127+ end
128+ end
41129 end
42130 end
43131 end
lib/docs/scrapers/http.rb+4−0
@@ -17,6 +17,10 @@ module Docs · 16 unmodified lines
1717 options[:skip_links] = ->(filter) {
1818 filter.current_url.host == 'tools.ietf.org' ? true : false
1919 }
20+ options[:fix_urls] = ->(url) {
21+ url.sub! %r{(Status/\d\d\d)_[A-Z].+}, '\1'
22+ url
23+ }
2024 options[:attribution] = ->(filter) {
2125 if filter.current_url.host == 'tools.ietf.org'
2226 "&copy; document authors. All rights reserved."