History

Update Elixir documentation (1.16 and 1.17)

The guides have moved from a separate page into the same documentation system. This required shuffling of the cleanup functions, which is subtly incompatible with the docs of the older versions, or would have required if/else in various places. For legibility, I thus opted to remove old versions.

Stefan Breunig committed 2 years ago

Commit e5fc6c21 parent 313a0553 files · +32 −205Browse files

Unified · Split

3 files
  1. lib/docs/filters/elixir/clean_html.rb +7 −22
  2. lib/docs/filters/elixir/entries.rb +14 −24
  3. lib/docs/scrapers/elixir.rb +11 −159
lib/docs/filters/elixir/clean_html.rb+7−22
@@ -2,32 +2,12 @@ module Docs · 1 unmodified line
2 class Elixir2 class Elixir
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 if current_url.path.start_with?('/getting-started')5 api
6 guide
7 else
8 api
9 end
10 doc6 doc
11 end7 end
12 8
13 def guide
14 @doc = at_css('#content article')
15
16 css('pre > code').each do |node|
17 node.parent.content = node.content
18 end
19
20 css('div > pre.highlight').each do |node|
21 node.content = node.content
22 node['data-language'] = node.parent['class'][/language-(\w+)/, 1]
23 node.parent.before(node).remove
24 end
25 end
26
27 def api9 def api
28 css('.hover-link', 'footer', ':not(.detail-header) > .view-source').remove10 css('.top-search').remove
29
30 css('h1 .settings').remove
31 11
32 css('.summary').each do |node|12 css('.summary').each do |node|
33 node.name = 'dl'13 node.name = 'dl'
@@ -65,6 +45,11 @@ module Docs · 31 unmodified lines
65 end45 end
66 end46 end
67 47
48 css('h1 a.icon-action[title="View Source"]').each do |node|
49 node['class'] = 'source'
50 node.content = "Source"
51 end
52
68 css('pre').each do |node|53 css('pre').each do |node|
69 node['data-language'] = 'elixir'54 node['data-language'] = 'elixir'
70 node.content = node.content55 node.content = node.content
lib/docs/filters/elixir/entries.rb+14−24
@@ -3,25 +3,21 @@ module Docs · 2 unmodified lines
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def get_name4 def get_name
5 css('h1 .app-vsn').remove5 css('h1 .app-vsn').remove
6 name = (at_css('h1 > span') or at_css('h1')).content.strip6 (at_css('h1 > span') or at_css('h1')).content.strip
7
8 if current_url.path.start_with?('/getting-started')
9 name.remove(/\.\z/)
10 else
11 name = name.split(' ').first unless name.start_with?('mix ') # ecto
12 name
13 end
14 end7 end
15 8
16 def get_type9 def get_type
17 if current_url.path.start_with?('/getting-started')10 section = at_css('h1 a.source').attr('href').match('elixir/pages/([^/]+)/')&.captures&.first
18 if subpath.start_with?('mix-otp')11 if section == "mix-and-otp"
19 'Guide: Mix & OTP'12 return "Mix & OTP"
20 elsif subpath.start_with?('meta')13 elsif section
21 'Guide: Metaprogramming'14 return section.gsub("-", " ").capitalize
22 else15 end
23 'Guide'16
24 end17 name = at_css('h1 span').text
18 case name.split(' ').first
19 when 'mix' then 'Mix Tasks'
20 when 'Changelog' then 'References'
25 else21 else
26 case at_css('h1 small').try(:content)22 case at_css('h1 small').try(:content)
27 when 'exception'23 when 'exception'
@@ -29,19 +25,13 @@ module Docs · 1 unmodified line
29 when 'protocol'25 when 'protocol'
30 'Protocols'26 'Protocols'
31 else27 else
32 if name.start_with?('Phoenix')28 name
33 name.split('.')[0..2].join('.')
34 elsif name.start_with?('mix ')
35 'Mix Tasks'
36 else
37 name.split('.').first
38 end
39 end29 end
40 end30 end
41 end31 end
42 32
43 def additional_entries33 def additional_entries
44 return [] if type == 'Exceptions' || type == 'Guide' || root_page?34 return [] if root_page?
45 35
46 css('.detail-header').map do |node|36 css('.detail-header').map do |node|
47 id = node['id']37 id = node['id']
lib/docs/scrapers/elixir.rb+11−159
@@ -4,7 +4,7 @@ module Docs · 3 unmodified lines
4 4
5 self.name = 'Elixir'5 self.name = 'Elixir'
6 self.type = 'elixir'6 self.type = 'elixir'
7 self.root_path = 'api-reference.html'7 self.root_path = 'introduction.html'
8 self.links = {8 self.links = {
9 home: 'https://elixir-lang.org/',9 home: 'https://elixir-lang.org/',
10 code: 'https://github.com/elixir-lang/elixir'10 code: 'https://github.com/elixir-lang/elixir'
@@ -12,193 +12,45 @@ module Docs · 1 unmodified line
12 12
13 html_filters.push 'elixir/clean_html', 'elixir/entries', 'title'13 html_filters.push 'elixir/clean_html', 'elixir/entries', 'title'
14 14
15 options[:container] = ->(filter) {15 options[:container] = '#content'
16 filter.current_url.path.start_with?('/getting-started') ? '#main' : '#content'
17 }
18 options[:title] = false16 options[:title] = false
19 options[:root_title] = 'Elixir'17 options[:root_title] = 'Elixir'
20 18
21 options[:attribution] = <<-HTML19 options[:attribution] = <<-HTML
22 &copy; 2012 Plataformatec<br>20 &copy; 2012 - 2024 The Elixir Team<br>
23 Licensed under the Apache License, Version 2.0.21 Licensed under the Apache License, Version 2.0.
24 HTML22 HTML
25 23
26 def initial_urls24 def initial_urls
27 [ "https://hexdocs.pm/elixir/#{self.class.release}/api-reference.html",25 [ "https://hexdocs.pm/elixir/#{self.class.release}/introduction.html",
28 "https://hexdocs.pm/eex/#{self.class.release}/EEx.html",26 "https://hexdocs.pm/eex/#{self.class.release}/EEx.html",
29 "https://hexdocs.pm/ex_unit/#{self.class.release}/ExUnit.html",27 "https://hexdocs.pm/ex_unit/#{self.class.release}/ExUnit.html",
30 "https://hexdocs.pm/iex/#{self.class.release}/IEx.html",28 "https://hexdocs.pm/iex/#{self.class.release}/IEx.html",
31 "https://hexdocs.pm/logger/#{self.class.release}/Logger.html",29 "https://hexdocs.pm/logger/#{self.class.release}/Logger.html",
32 "https://hexdocs.pm/mix/#{self.class.release}/Mix.html",30 "https://hexdocs.pm/mix/#{self.class.release}/Mix.html" ]
33 "https://elixir-lang.org/getting-started/introduction.html" ]
34 end
35
36 version '1.15' do
37 self.release = '1.15.4'
38 self.base_urls = [
39 "https://hexdocs.pm/elixir/#{release}/",
40 "https://hexdocs.pm/eex/#{release}/",
41 "https://hexdocs.pm/ex_unit/#{release}/",
42 "https://hexdocs.pm/iex/#{release}/",
43 "https://hexdocs.pm/logger/#{release}/",
44 "https://hexdocs.pm/mix/#{release}/",
45 'https://elixir-lang.org/getting-started/'
46 ]
47 end
48
49 version '1.14' do
50 self.release = '1.14.1'
51 self.base_urls = [
52 "https://hexdocs.pm/elixir/#{release}/",
53 "https://hexdocs.pm/eex/#{release}/",
54 "https://hexdocs.pm/ex_unit/#{release}/",
55 "https://hexdocs.pm/iex/#{release}/",
56 "https://hexdocs.pm/logger/#{release}/",
57 "https://hexdocs.pm/mix/#{release}/",
58 'https://elixir-lang.org/getting-started/'
59 ]
60 end
61
62 version '1.13' do
63 self.release = '1.13.4'
64 self.base_urls = [
65 "https://hexdocs.pm/elixir/#{release}/",
66 "https://hexdocs.pm/eex/#{release}/",
67 "https://hexdocs.pm/ex_unit/#{release}/",
68 "https://hexdocs.pm/iex/#{release}/",
69 "https://hexdocs.pm/logger/#{release}/",
70 "https://hexdocs.pm/mix/#{release}/",
71 'https://elixir-lang.org/getting-started/'
72 ]
73 end
74
75 version '1.12' do
76 self.release = '1.12.0'
77 self.base_urls = [
78 "https://hexdocs.pm/elixir/#{release}/",
79 "https://hexdocs.pm/eex/#{release}/",
80 "https://hexdocs.pm/ex_unit/#{release}/",
81 "https://hexdocs.pm/iex/#{release}/",
82 "https://hexdocs.pm/logger/#{release}/",
83 "https://hexdocs.pm/mix/#{release}/",
84 'https://elixir-lang.org/getting-started/'
85 ]
86 end
87
88 version '1.11' do
89 self.release = '1.11.2'
90 self.base_urls = [
91 "https://hexdocs.pm/elixir/#{release}/",
92 "https://hexdocs.pm/eex/#{release}/",
93 "https://hexdocs.pm/ex_unit/#{release}/",
94 "https://hexdocs.pm/iex/#{release}/",
95 "https://hexdocs.pm/logger/#{release}/",
96 "https://hexdocs.pm/mix/#{release}/",
97 'https://elixir-lang.org/getting-started/'
98 ]
99 end
100
101 version '1.10' do
102 self.release = '1.10.4'
103 self.base_urls = [
104 "https://hexdocs.pm/elixir/#{release}/",
105 "https://hexdocs.pm/eex/#{release}/",
106 "https://hexdocs.pm/ex_unit/#{release}/",
107 "https://hexdocs.pm/iex/#{release}/",
108 "https://hexdocs.pm/logger/#{release}/",
109 "https://hexdocs.pm/mix/#{release}/",
110 'https://elixir-lang.org/getting-started/'
111 ]
112 end
113
114 version '1.9' do
115 self.release = '1.9.4'
116 self.base_urls = [
117 "https://hexdocs.pm/elixir/#{release}/",
118 "https://hexdocs.pm/eex/#{release}/",
119 "https://hexdocs.pm/ex_unit/#{release}/",
120 "https://hexdocs.pm/iex/#{release}/",
121 "https://hexdocs.pm/logger/#{release}/",
122 "https://hexdocs.pm/mix/#{release}/",
123 'https://elixir-lang.org/getting-started/'
124 ]
125 end
126
127 version '1.8' do
128 self.release = '1.8.2'
129 self.base_urls = [
130 "https://hexdocs.pm/elixir/#{release}/",
131 "https://hexdocs.pm/eex/#{release}/",
132 "https://hexdocs.pm/ex_unit/#{release}/",
133 "https://hexdocs.pm/iex/#{release}/",
134 "https://hexdocs.pm/logger/#{release}/",
135 "https://hexdocs.pm/mix/#{release}/",
136 'https://elixir-lang.org/getting-started/'
137 ]
138 end
139
140 version '1.7' do
141 self.release = '1.7.4'
142 self.base_urls = [
143 "https://hexdocs.pm/elixir/#{release}/",
144 "https://hexdocs.pm/eex/#{release}/",
145 "https://hexdocs.pm/ex_unit/#{release}/",
146 "https://hexdocs.pm/iex/#{release}/",
147 "https://hexdocs.pm/logger/#{release}/",
148 "https://hexdocs.pm/mix/#{release}/",
149 'https://elixir-lang.org/getting-started/'
150 ]
151 end
152
153 version '1.6' do
154 self.release = '1.6.6'
155 self.base_urls = [
156 "https://hexdocs.pm/elixir/#{release}/",
157 "https://hexdocs.pm/eex/#{release}/",
158 "https://hexdocs.pm/ex_unit/#{release}/",
159 "https://hexdocs.pm/iex/#{release}/",
160 "https://hexdocs.pm/logger/#{release}/",
161 "https://hexdocs.pm/mix/#{release}/",
162 'https://elixir-lang.org/getting-started/'
163 ]
164 end
165
166 version '1.5' do
167 self.release = '1.5.3'
168 self.base_urls = [
169 "https://hexdocs.pm/elixir/#{release}/",
170 "https://hexdocs.pm/eex/#{release}/",
171 "https://hexdocs.pm/ex_unit/#{release}/",
172 "https://hexdocs.pm/iex/#{release}/",
173 "https://hexdocs.pm/logger/#{release}/",
174 "https://hexdocs.pm/mix/#{release}/",
175 'https://elixir-lang.org/getting-started/'
176 ]
177 end31 end
178 32
179 version '1.4' do33 version '1.17' do
180 self.release = '1.4.5'34 self.release = '1.17.0'
181 self.base_urls = [35 self.base_urls = [
182 "https://hexdocs.pm/elixir/#{release}/",36 "https://hexdocs.pm/elixir/#{release}/",
183 "https://hexdocs.pm/eex/#{release}/",37 "https://hexdocs.pm/eex/#{release}/",
184 "https://hexdocs.pm/ex_unit/#{release}/",38 "https://hexdocs.pm/ex_unit/#{release}/",
185 "https://hexdocs.pm/iex/#{release}/",39 "https://hexdocs.pm/iex/#{release}/",
186 "https://hexdocs.pm/logger/#{release}/",40 "https://hexdocs.pm/logger/#{release}/",
187 "https://hexdocs.pm/mix/#{release}/",41 "https://hexdocs.pm/mix/#{release}/"
188 'https://elixir-lang.org/getting-started/'
189 ]42 ]
190 end43 end
191 44
192 version '1.3' do45 version '1.16' do
193 self.release = '1.3.4'46 self.release = '1.16.3'
194 self.base_urls = [47 self.base_urls = [
195 "https://hexdocs.pm/elixir/#{release}/",48 "https://hexdocs.pm/elixir/#{release}/",
196 "https://hexdocs.pm/eex/#{release}/",49 "https://hexdocs.pm/eex/#{release}/",
197 "https://hexdocs.pm/ex_unit/#{release}/",50 "https://hexdocs.pm/ex_unit/#{release}/",
198 "https://hexdocs.pm/iex/#{release}/",51 "https://hexdocs.pm/iex/#{release}/",
199 "https://hexdocs.pm/logger/#{release}/",52 "https://hexdocs.pm/logger/#{release}/",
200 "https://hexdocs.pm/mix/#{release}/",53 "https://hexdocs.pm/mix/#{release}/"
201 'https://elixir-lang.org/getting-started/'
202 ]54 ]
203 end55 end
204 56