History

Update Crystal documentation (1.3.0)

Simon Legner committed 4 years ago

Commit 39a74e01 parent 210a1814 files · +23 −24Browse files

Unified · Split

4 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +1 −1
  2. lib/docs/filters/crystal/clean_html.rb +2 −2
  3. lib/docs/filters/crystal/entries.rb +7 −6
  4. lib/docs/scrapers/crystal.rb +13 −15
assets/javascripts/templates/pages/about_tmpl.coffee+1−1
@@ -204,7 +204,7 @@ credits = [ · 203 unmodified lines
204 'https://raw.githubusercontent.com/apache/cordova-docs/master/LICENSE'204 'https://raw.githubusercontent.com/apache/cordova-docs/master/LICENSE'
205 ], [205 ], [
206 'Crystal',206 'Crystal',
207 '2012-2021 Manas Technology Solutions',207 '2012-2022 Manas Technology Solutions',
208 'Apache',208 'Apache',
209 'https://raw.githubusercontent.com/crystal-lang/crystal/master/LICENSE'209 'https://raw.githubusercontent.com/crystal-lang/crystal/master/LICENSE'
210 ], [210 ], [
lib/docs/filters/crystal/clean_html.rb+2−2
@@ -2,7 +2,7 @@ module Docs · 1 unmodified line
2 class Crystal2 class Crystal
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 slug.start_with?('reference') ? book : api5 current_url.path.start_with?('/reference/') ? book : api
6 doc6 doc
7 end7 end
8 8
@@ -21,7 +21,7 @@ module Docs · 12 unmodified lines
21 def api21 def api
22 @doc = at_css('.main-content')22 @doc = at_css('.main-content')
23 23
24 at_css('h1 + p').remove if root_page?24 at_css('h1 + p').remove if current_url.path == "/api/#{release}/index.html"
25 25
26 css('.method-permalink', '.doc + br', 'hr', 'a > br', 'div + br').remove26 css('.method-permalink', '.doc + br', 'hr', 'a > br', 'div + br').remove
27 27
lib/docs/filters/crystal/entries.rb+7−6
@@ -2,11 +2,11 @@ module Docs · 1 unmodified line
2 class Crystal2 class Crystal
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def get_name4 def get_name
5 if slug.start_with?('reference/')5 if current_url.path.start_with?('/reference/')
6 name = at_css('main h1').content.strip6 name = at_css('main h1').content.strip
7 name.remove! '¶'7 name.remove! '¶'
8 8
9 if slug.start_with?('reference/syntax_and_semantics')9 if current_url.path.start_with?('/reference/') && slug.match?('syntax_and_semantics')
10 name.prepend "#{slug.split('/')[2].titleize}: " if slug.split('/').length > 310 name.prepend "#{slug.split('/')[2].titleize}: " if slug.split('/').length > 3
11 elsif slug.split('/').length > 111 elsif slug.split('/').length > 1
12 chapter = slug.split('/')[1].titleize.capitalize12 chapter = slug.split('/')[1].titleize.capitalize
@@ -15,6 +15,7 @@ module Docs · 2 unmodified lines
15 15
16 name16 name
17 else17 else
18 return at_css('h1').content.strip unless at_css('.type-name')
18 name = at_css('.type-name').children.last.content.strip19 name = at_css('.type-name').children.last.content.strip
19 name.remove! %r{\(.*\)}20 name.remove! %r{\(.*\)}
20 name21 name
@@ -22,11 +23,11 @@ module Docs · 1 unmodified line
22 end23 end
23 24
24 def get_type25 def get_type
25 return if root_page?26 return if current_url.path == "/api/#{release}/index.html"
26 27
27 if slug.start_with?('reference/syntax_and_semantics')28 if current_url.path.start_with?('/reference/') && slug.match?('syntax_and_semantics')
28 'Book: Language'29 'Book: Language'
29 elsif slug.start_with?('reference/')30 elsif current_url.path.start_with?('/reference/')
30 'Book'31 'Book'
31 else32 else
32 hierarchy = at_css('.superclass-hierarchy')33 hierarchy = at_css('.superclass-hierarchy')
@@ -44,7 +45,7 @@ module Docs · 11 unmodified lines
44 end45 end
45 46
46 def additional_entries47 def additional_entries
47 return [] unless slug.start_with?('api')48 return [] unless current_url.path.start_with?('/api/')
48 entries = []49 entries = []
49 50
50 css('.entry-detail[id$="class-method"]').each do |node|51 css('.entry-detail[id$="class-method"]').each do |node|
lib/docs/scrapers/crystal.rb+13−15
@@ -1,8 +1,17 @@
1module Docs1module Docs
2 class Crystal < UrlScraper2 class Crystal < UrlScraper
3 include MultipleBaseUrls
3 self.type = 'crystal'4 self.type = 'crystal'
4 self.base_url = 'https://crystal-lang.org/'5 self.release = '1.3.0'
5 self.initial_paths = %w(reference/index.html)6 self.base_urls = [
7 "https://crystal-lang.org/api/#{release}/",
8 "https://crystal-lang.org/reference/#{release[0..2]}/",
9 ]
10 def initial_urls
11 [ "https://crystal-lang.org/api/#{self.class.release}/index.html",
12 "https://crystal-lang.org/reference/#{self.class.release[0..2]}/index.html" ]
13 end
14
6 self.links = {15 self.links = {
7 home: 'https://crystal-lang.org/',16 home: 'https://crystal-lang.org/',
8 code: 'https://github.com/crystal-lang/crystal'17 code: 'https://github.com/crystal-lang/crystal'
@@ -11,7 +20,7 @@ module Docs · 2 unmodified lines
11 html_filters.push 'crystal/entries', 'crystal/clean_html'20 html_filters.push 'crystal/entries', 'crystal/clean_html'
12 21
13 options[:attribution] = ->(filter) {22 options[:attribution] = ->(filter) {
14 if filter.slug.start_with?('reference')23 if filter.current_url.path.start_with?('/reference/')
15 <<-HTML24 <<-HTML
16 To the extent possible under law, the persons who contributed to this work25 To the extent possible under law, the persons who contributed to this work
17 have waived<br>all copyright and related or neighboring rights to this work26 have waived<br>all copyright and related or neighboring rights to this work
@@ -19,23 +28,12 @@ module Docs · 1 unmodified line
19 HTML28 HTML
20 else29 else
21 <<-HTML30 <<-HTML
22 &copy; 2012&ndash;2021 Manas Technology Solutions.<br>31 &copy; 2012&ndash;2022 Manas Technology Solutions.<br>
23 Licensed under the Apache License, Version 2.0.32 Licensed under the Apache License, Version 2.0.
24 HTML33 HTML
25 end34 end
26 }35 }
27 36
28 self.release = '1.2.1'
29 self.root_path = "api/#{release}/index.html"
30
31 options[:only_patterns] = [/\Aapi\/#{release}\//, /\Areference\//]
32 options[:skip_patterns] = [/debug/i]
33
34 options[:replace_paths] = {
35 "api/#{release}/" => "api/#{release}/index.html",
36 'reference/' => 'reference/index.html'
37 }
38
39 def get_latest_version(opts)37 def get_latest_version(opts)
40 doc = fetch_doc('https://crystal-lang.org/', opts)38 doc = fetch_doc('https://crystal-lang.org/', opts)
41 doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]39 doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]