Update Crystal documentation (1.3.0)

pull/1688/head
Simon Legner 3 years ago
parent 210a181491
commit 39a74e09ae

@ -204,7 +204,7 @@ credits = [
'https://raw.githubusercontent.com/apache/cordova-docs/master/LICENSE' 'https://raw.githubusercontent.com/apache/cordova-docs/master/LICENSE'
], [ ], [
'Crystal', 'Crystal',
'2012-2021 Manas Technology Solutions', '2012-2022 Manas Technology Solutions',
'Apache', 'Apache',
'https://raw.githubusercontent.com/crystal-lang/crystal/master/LICENSE' 'https://raw.githubusercontent.com/crystal-lang/crystal/master/LICENSE'
], [ ], [

@ -2,7 +2,7 @@ module Docs
class Crystal class Crystal
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
slug.start_with?('reference') ? book : api current_url.path.start_with?('/reference/') ? book : api
doc doc
end end
@ -21,7 +21,7 @@ module Docs
def api def api
@doc = at_css('.main-content') @doc = at_css('.main-content')
at_css('h1 + p').remove if root_page? at_css('h1 + p').remove if current_url.path == "/api/#{release}/index.html"
css('.method-permalink', '.doc + br', 'hr', 'a > br', 'div + br').remove css('.method-permalink', '.doc + br', 'hr', 'a > br', 'div + br').remove

@ -2,11 +2,11 @@ module Docs
class Crystal class Crystal
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
if slug.start_with?('reference/') if current_url.path.start_with?('/reference/')
name = at_css('main h1').content.strip name = at_css('main h1').content.strip
name.remove! '¶' name.remove! '¶'
if slug.start_with?('reference/syntax_and_semantics') if current_url.path.start_with?('/reference/') && slug.match?('syntax_and_semantics')
name.prepend "#{slug.split('/')[2].titleize}: " if slug.split('/').length > 3 name.prepend "#{slug.split('/')[2].titleize}: " if slug.split('/').length > 3
elsif slug.split('/').length > 1 elsif slug.split('/').length > 1
chapter = slug.split('/')[1].titleize.capitalize chapter = slug.split('/')[1].titleize.capitalize
@ -15,6 +15,7 @@ module Docs
name name
else else
return at_css('h1').content.strip unless at_css('.type-name')
name = at_css('.type-name').children.last.content.strip name = at_css('.type-name').children.last.content.strip
name.remove! %r{\(.*\)} name.remove! %r{\(.*\)}
name name
@ -22,11 +23,11 @@ module Docs
end end
def get_type def get_type
return if root_page? return if current_url.path == "/api/#{release}/index.html"
if slug.start_with?('reference/syntax_and_semantics') if current_url.path.start_with?('/reference/') && slug.match?('syntax_and_semantics')
'Book: Language' 'Book: Language'
elsif slug.start_with?('reference/') elsif current_url.path.start_with?('/reference/')
'Book' 'Book'
else else
hierarchy = at_css('.superclass-hierarchy') hierarchy = at_css('.superclass-hierarchy')
@ -44,7 +45,7 @@ module Docs
end end
def additional_entries def additional_entries
return [] unless slug.start_with?('api') return [] unless current_url.path.start_with?('/api/')
entries = [] entries = []
css('.entry-detail[id$="class-method"]').each do |node| css('.entry-detail[id$="class-method"]').each do |node|

@ -1,8 +1,17 @@
module Docs module Docs
class Crystal < UrlScraper class Crystal < UrlScraper
include MultipleBaseUrls
self.type = 'crystal' self.type = 'crystal'
self.base_url = 'https://crystal-lang.org/' self.release = '1.3.0'
self.initial_paths = %w(reference/index.html) self.base_urls = [
"https://crystal-lang.org/api/#{release}/",
"https://crystal-lang.org/reference/#{release[0..2]}/",
]
def initial_urls
[ "https://crystal-lang.org/api/#{self.class.release}/index.html",
"https://crystal-lang.org/reference/#{self.class.release[0..2]}/index.html" ]
end
self.links = { self.links = {
home: 'https://crystal-lang.org/', home: 'https://crystal-lang.org/',
code: 'https://github.com/crystal-lang/crystal' code: 'https://github.com/crystal-lang/crystal'
@ -11,7 +20,7 @@ module Docs
html_filters.push 'crystal/entries', 'crystal/clean_html' html_filters.push 'crystal/entries', 'crystal/clean_html'
options[:attribution] = ->(filter) { options[:attribution] = ->(filter) {
if filter.slug.start_with?('reference') if filter.current_url.path.start_with?('/reference/')
<<-HTML <<-HTML
To the extent possible under law, the persons who contributed to this work To the extent possible under law, the persons who contributed to this work
have waived<br>all copyright and related or neighboring rights to this work have waived<br>all copyright and related or neighboring rights to this work
@ -19,23 +28,12 @@ module Docs
HTML HTML
else else
<<-HTML <<-HTML
&copy; 2012&ndash;2021 Manas Technology Solutions.<br> &copy; 2012&ndash;2022 Manas Technology Solutions.<br>
Licensed under the Apache License, Version 2.0. Licensed under the Apache License, Version 2.0.
HTML HTML
end end
} }
self.release = '1.2.1'
self.root_path = "api/#{release}/index.html"
options[:only_patterns] = [/\Aapi\/#{release}\//, /\Areference\//]
options[:skip_patterns] = [/debug/i]
options[:replace_paths] = {
"api/#{release}/" => "api/#{release}/index.html",
'reference/' => 'reference/index.html'
}
def get_latest_version(opts) def get_latest_version(opts)
doc = fetch_doc('https://crystal-lang.org/', opts) doc = fetch_doc('https://crystal-lang.org/', opts)
doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0] doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]

Loading…
Cancel
Save