forked from freeCodeCamp/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathangular.rb
More file actions
296 lines (247 loc) · 9.3 KB
/
Copy pathangular.rb
File metadata and controls
296 lines (247 loc) · 9.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
require 'yajl/json_gem'
module Docs
class Angular < UrlScraper
self.type = 'angular'
self.links = {
home: 'https://angular.dev/',
code: 'https://github.com/angular/angular'
}
self.base_url = 'https://angular.io/'
self.root_path = 'docs'
options[:max_image_size] = 256_000
options[:attribution] = <<-HTML
Super-powered by Google ©2010–2025.<br />
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
HTML
options[:follow_links] = false
options[:only_patterns] = [/\Aguide/, /\Aapi/, /\Acli/]
options[:fix_urls_before_parse] = ->(url) do
url.sub! %r{\Aguide/}, '/guide/'
url.sub! %r{\Aapi/}, '/api/'
url.sub! %r{\cli/}, '/cli/'
url.sub! %r{\Agenerated/}, '/generated/'
url
end
module JsonNavigation
private
def initial_urls
initial_urls = []
Request.run "#{self.class.base_url}generated/navigation.json" do |response|
data = JSON.parse(response.body)
dig = ->(entry) do
initial_urls << url_for("generated/docs/#{entry['url']}.json") if entry['url'] && entry['url'] != 'api'
entry['children'].each(&dig) if entry['children']
end
data['SideNav'].each(&dig)
end
Request.run "#{self.class.base_url}generated/docs/api/api-list.json" do |response|
data = JSON.parse(response.body)
dig = ->(entry) do
initial_urls << url_for("generated/docs/#{entry['path']}.json") if entry['path']
initial_urls << url_for("generated/docs/api/#{entry['name']}.json") if entry['name'] && !entry['path']
entry['items'].each(&dig) if entry['items']
end
data.each(&dig)
end
initial_urls
end
def handle_response(response)
if response.mime_type.include?('json')
begin
json = JSON.parse(response.body)
response.options[:response_body] = json['contents']
response.url.path = response.url.path.gsub(/generated\/docs\/.*/, json['id'])
response.effective_url.path = response.effective_url.path.gsub(/generated\/docs\/.*/, json['id'])
rescue JSON::ParserError
response.options[:response_body] = ''
end
response.headers['Content-Type'] = 'text/html'
end
super
end
end
module Since12
def url_for(path)
# See encodeToLowercase im aio/tools/transforms/angular-base-package/processors/disambiguateDocPaths.js
path = path.gsub(/[A-Z_]/) {|s| s.downcase + '_'}
super
end
include Docs::Angular::JsonNavigation
end
module Since18
def self.handle_redirects(version)
lambda do |url|
url.sub! '/guide/templates/reference-variables', '/guide/templates/variables#template-reference-variables'
url.sub! '/guide/signals/inputs', '/guide/components/inputs'
url.sub! '/guide/defer', '/guide/templates/defer'
url.sub! '/guide/templates/class-binding', '/guide/templates/binding#css-class-and-style-property-bindings'
url.sub! %r{/guide/components$}, '/guide/components/anatomy-of-components'
url.sub! '/guide/templates/property-binding', '/guide/templates/binding#binding-dynamic-properties-and-attributes'
url.sub! %r{/guide/ngmodules$}, '/guide/ngmodules/overview'
url.sub! '/guide/components/importing', '/guide/components/anatomy-of-components#using-components'
url.sub! '/guide/components/anatomy-of-components', '/guide/components' if version == '20'
url
end
end
end
version do
self.release = '20.3.4'
self.base_url = 'https://angular.dev/'
self.root_path = 'overview'
options[:follow_links] = true
options[:container] = '.docs-app-main-content'
options[:fix_urls] = Since18.handle_redirects(self.version)
html_filters.push 'angular/entries', 'angular/clean_html_v18'
include Docs::Angular::Since18
end
version '19' do
self.release = '19.2.15'
self.base_url = 'https://v19.angular.dev/'
self.root_path = 'overview'
options[:follow_links] = true
options[:container] = '.docs-app-main-content'
options[:fix_urls] = Since18.handle_redirects(self.version)
html_filters.push 'angular/entries', 'angular/clean_html_v18'
include Docs::Angular::Since18
end
version '18' do
self.release = '18.2.14'
self.base_url = 'https://v18.angular.dev/'
self.root_path = 'overview'
options[:follow_links] = true
options[:container] = '.docs-app-main-content'
options[:fix_urls] = Since18.handle_redirects(self.version)
html_filters.push 'angular/entries', 'angular/clean_html_v18'
include Docs::Angular::Since18
end
version '17' do
self.release = '17.0.8'
self.base_url = 'https://v17.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::Since12
end
version '16' do
self.release = '16.2.12'
self.base_url = 'https://v16.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::Since12
end
version '15' do
self.release = '15.2.9'
self.base_url = 'https://v15.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::Since12
end
version '14' do
self.release = '14.2.12'
self.base_url = 'https://v14.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::Since12
end
version '13' do
self.release = '13.3.8'
self.base_url = 'https://v13.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::Since12
end
version '12' do
self.release = '12.2.13'
self.base_url = 'https://v12.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::Since12
end
version '11' do
self.release = '11.2.14'
self.base_url = 'https://v11.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::JsonNavigation
end
version '10' do
self.release = '10.2.3'
self.base_url = 'https://v10.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::JsonNavigation
end
version '9' do
self.release = '9.1.12'
self.base_url = 'https://v9.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::JsonNavigation
end
version '8' do
self.release = '8.2.14'
self.base_url = 'https://v8.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::JsonNavigation
end
version '7' do
self.release = '7.2.15'
self.base_url = 'https://v7.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::JsonNavigation
end
version '6' do
self.release = '6.1.10'
self.base_url = 'https://v6.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::JsonNavigation
end
version '5' do
self.release = '5.2.11'
self.base_url = 'https://v5.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::JsonNavigation
end
version '4' do
self.release = '4.4.6'
self.base_url = 'https://v4.angular.io/'
html_filters.push 'angular/clean_html', 'angular/entries'
include Docs::Angular::JsonNavigation
end
version '2' do
self.release = '2.4.10'
self.base_url = 'https://v2.angular.io/docs/ts/latest/'
self.root_path = 'api/'
html_filters.push 'angular/entries_v2', 'angular/clean_html_v2'
stub 'api/' do
base_url = URL.parse(self.base_url)
capybara = load_capybara_selenium
capybara.app_host = base_url.origin
capybara.visit(base_url.path + 'api/')
capybara.execute_script('return document.body.innerHTML')
end
options[:skip_patterns] = [/deprecated/, /VERSION-let/]
options[:skip] = %w(
index.html
styleguide.html
quickstart.html
cheatsheet.html
guide/cheatsheet.html
guide/style-guide.html)
options[:replace_paths] = {
'testing/index.html' => 'guide/testing.html',
'guide/glossary.html' => 'glossary.html',
'tutorial' => 'tutorial/',
'api' => 'api/'
}
options[:fix_urls] = -> (url) do
url.sub! %r{\A(https://(?:v2\.)?angular\.io/docs/.+/)index\.html\z}, '\1'
url
end
end
def get_latest_version(opts)
get_npm_version('@angular/core', opts)
end
private
def parse(response)
response.body.gsub! '<code-example', '<pre'
response.body.gsub! '</code-example', '</pre'
response.body.gsub! '<code-pane', '<pre'
response.body.gsub! '</code-pane', '</pre'
response.body.gsub! '<live-example></live-example>', 'live example'
response.body.gsub! '<live-example', '<span'
response.body.gsub! '</live-example', '</span'
super
end
end
end