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'
], [
'Crystal',
'2012-2021 Manas Technology Solutions',
'2012-2022 Manas Technology Solutions',
'Apache',
'https://raw.githubusercontent.com/crystal-lang/crystal/master/LICENSE'
], [

@ -2,7 +2,7 @@ module Docs
class Crystal
class CleanHtmlFilter < Filter
def call
slug.start_with?('reference') ? book : api
current_url.path.start_with?('/reference/') ? book : api
doc
end
@ -21,7 +21,7 @@ module Docs
def api
@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

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

@ -1,8 +1,17 @@
module Docs
class Crystal < UrlScraper
include MultipleBaseUrls
self.type = 'crystal'
self.base_url = 'https://crystal-lang.org/'
self.initial_paths = %w(reference/index.html)
self.release = '1.3.0'
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 = {
home: 'https://crystal-lang.org/',
code: 'https://github.com/crystal-lang/crystal'
@ -11,7 +20,7 @@ module Docs
html_filters.push 'crystal/entries', 'crystal/clean_html'
options[:attribution] = ->(filter) {
if filter.slug.start_with?('reference')
if filter.current_url.path.start_with?('/reference/')
<<-HTML
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
@ -19,23 +28,12 @@ module Docs
HTML
else
<<-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.
HTML
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)
doc = fetch_doc('https://crystal-lang.org/', opts)
doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]

Loading…
Cancel
Save