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
204204 'https://raw.githubusercontent.com/apache/cordova-docs/master/LICENSE'
205205 ], [
206206 'Crystal',
207− '2012-2021 Manas Technology Solutions',
207+ '2012-2022 Manas Technology Solutions',
208208 'Apache',
209209 'https://raw.githubusercontent.com/crystal-lang/crystal/master/LICENSE'
210210 ], [
lib/docs/filters/crystal/clean_html.rb+2−2
@@ -2,7 +2,7 @@ module Docs · 1 unmodified line
22 class Crystal
33 class CleanHtmlFilter < Filter
44 def call
5− slug.start_with?('reference') ? book : api
5+ current_url.path.start_with?('/reference/') ? book : api
66 doc
77 end
88
@@ -21,7 +21,7 @@ module Docs · 12 unmodified lines
2121 def api
2222 @doc = at_css('.main-content')
2323
24− at_css('h1 + p').remove if root_page?
24+ at_css('h1 + p').remove if current_url.path == "/api/#{release}/index.html"
2525
2626 css('.method-permalink', '.doc + br', 'hr', 'a > br', 'div + br').remove
2727
lib/docs/filters/crystal/entries.rb+7−6
@@ -2,11 +2,11 @@ module Docs · 1 unmodified line
22 class Crystal
33 class EntriesFilter < Docs::EntriesFilter
44 def get_name
5− if slug.start_with?('reference/')
5+ if current_url.path.start_with?('/reference/')
66 name = at_css('main h1').content.strip
77 name.remove! '¶'
88
9− if slug.start_with?('reference/syntax_and_semantics')
9+ if current_url.path.start_with?('/reference/') && slug.match?('syntax_and_semantics')
1010 name.prepend "#{slug.split('/')[2].titleize}: " if slug.split('/').length > 3
1111 elsif slug.split('/').length > 1
1212 chapter = slug.split('/')[1].titleize.capitalize
@@ -15,6 +15,7 @@ module Docs · 2 unmodified lines
1515
1616 name
1717 else
18+ return at_css('h1').content.strip unless at_css('.type-name')
1819 name = at_css('.type-name').children.last.content.strip
1920 name.remove! %r{\(.*\)}
2021 name
@@ -22,11 +23,11 @@ module Docs · 1 unmodified line
2223 end
2324
2425 def get_type
25− return if root_page?
26+ return if current_url.path == "/api/#{release}/index.html"
2627
27− if slug.start_with?('reference/syntax_and_semantics')
28+ if current_url.path.start_with?('/reference/') && slug.match?('syntax_and_semantics')
2829 'Book: Language'
29− elsif slug.start_with?('reference/')
30+ elsif current_url.path.start_with?('/reference/')
3031 'Book'
3132 else
3233 hierarchy = at_css('.superclass-hierarchy')
@@ -44,7 +45,7 @@ module Docs · 11 unmodified lines
4445 end
4546
4647 def additional_entries
47− return [] unless slug.start_with?('api')
48+ return [] unless current_url.path.start_with?('/api/')
4849 entries = []
4950
5051 css('.entry-detail[id$="class-method"]').each do |node|
lib/docs/scrapers/crystal.rb+13−15
@@ -1,8 +1,17 @@
11 module Docs
22 class Crystal < UrlScraper
3+ include MultipleBaseUrls
34 self.type = 'crystal'
4− self.base_url = 'https://crystal-lang.org/'
5− self.initial_paths = %w(reference/index.html)
5+ self.release = '1.3.0'
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+
615 self.links = {
716 home: 'https://crystal-lang.org/',
817 code: 'https://github.com/crystal-lang/crystal'
@@ -11,7 +20,7 @@ module Docs · 2 unmodified lines
1120 html_filters.push 'crystal/entries', 'crystal/clean_html'
1221
1322 options[:attribution] = ->(filter) {
14− if filter.slug.start_with?('reference')
23+ if filter.current_url.path.start_with?('/reference/')
1524 <<-HTML
1625 To the extent possible under law, the persons who contributed to this work
1726 have waived<br>all copyright and related or neighboring rights to this work
@@ -19,23 +28,12 @@ module Docs · 1 unmodified line
1928 HTML
2029 else
2130 <<-HTML
22− &copy; 2012&ndash;2021 Manas Technology Solutions.<br>
31+ &copy; 2012&ndash;2022 Manas Technology Solutions.<br>
2332 Licensed under the Apache License, Version 2.0.
2433 HTML
2534 end
2635 }
2736
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−
3937 def get_latest_version(opts)
4038 doc = fetch_doc('https://crystal-lang.org/', opts)
4139 doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]