History

Update Kotlin documentation (1.6.0)

Simon Legner committed 4 years ago

Commit 1378b381 parent 2fa27c33 files · +38 −22Browse files

Unified · Split

3 files
  1. lib/docs/filters/kotlin/clean_html.rb +7 −1
  2. lib/docs/filters/kotlin/entries.rb +8 −7
  3. lib/docs/scrapers/kotlin.rb +23 −14
lib/docs/filters/kotlin/clean_html.rb+7−1
@@ -2,7 +2,6 @@ module Docs · 1 unmodified line
22 class Kotlin
33 class CleanHtmlFilter < Filter
44 def call
5− @doc = at_css('.page-content')
65 subpath.start_with?('api') ? api_page : doc_page
76 doc
87 end
@@ -14,6 +13,13 @@ module Docs · 5 unmodified lines
1413 node.parent.before(node.parent.content).remove
1514 end
1615
16+ css('div.code-block').each do |node|
17+ node.name = 'pre'
18+ node['data-language'] = node['data-lang']
19+ node.content = node.content
20+ # FIXME: newlines in code-block are lost because of <div>? (on https://kotlinlang.org/docs/typecasts.html for instance)
21+ end
22+
1723 css('pre').each do |node|
1824 node['data-language'] = 'kotlin' if node.at_css('code.language-kotlin')
1925 node['data-language'] = 'groovy' if node.at_css('code.language-groovy')
lib/docs/filters/kotlin/entries.rb+8−7
@@ -6,25 +6,26 @@ module Docs · 5 unmodified lines
66 breadcrumbs[1..-1].join('.')
77 else
88 node = (at_css('h1') || at_css('h2'))
9− return node.content unless node.nil?
10− subpath[/\/([a-z0-9_-]+)\./][1..-2].titleize.sub('Faq', 'FAQ')
9+ return [breadcrumbs[1..], [node.content]].flatten.join(': ') unless node.nil?
1110 end
1211 end
1312
1413 def get_type
1514 if subpath.start_with?('api')
1615 breadcrumbs[1]
17− elsif subpath.start_with?('docs/tutorials')
18− 'Tutorials'
19− elsif subpath.start_with?('docs/reference')
20− 'Reference'
16+ else
17+ breadcrumbs[0]
2118 end
2219 end
2320
2421 private
2522
2623 def breadcrumbs
27− @breadcrumbs ||= css('.api-docs-breadcrumbs a').map(&:content).map(&:strip)
24+ if subpath.start_with?('api')
25+ @breadcrumbs ||= css('.api-docs-breadcrumbs a').map(&:content).map(&:strip)
26+ else
27+ @breadcrumbs ||= doc.document.at_css('body')['data-breadcrumbs'].split('///')
28+ end
2829 end
2930 end
3031 end
lib/docs/scrapers/kotlin.rb+23−14
@@ -1,7 +1,6 @@
11 module Docs
22 class Kotlin < UrlScraper
33 self.type = 'kotlin'
4− self.release = '1.4.10'
54 self.base_url = 'https://kotlinlang.org/'
65 self.root_path = 'api/latest/jvm/stdlib/index.html'
76 self.links = {
@@ -11,9 +10,8 @@ module Docs · 3 unmodified lines
1110
1211 html_filters.push 'kotlin/entries', 'kotlin/clean_html'
1312
14− options[:container] = '.global-content'
15−
16− options[:only_patterns] = [/\Adocs\/tutorials\//, /\Adocs\/reference\//, /\Aapi\/latest\/jvm\/stdlib\//]
13+ options[:container] = 'article'
14+ options[:only_patterns] = [/\Adocs\//, /\Aapi\/latest\/jvm\/stdlib\//]
1715 options[:skip_patterns] = [/stdlib\/org\./]
1816 options[:skip] = %w(
1917 api/latest/jvm/stdlib/alltypes/index.html
@@ -22,23 +20,34 @@ module Docs · 2 unmodified lines
2220 docs/events.html
2321 docs/resources.html
2422 docs/reference/grammar.html)
25− options[:replace_paths] = {
26− 'api/latest/jvm/stdlib/' => 'api/latest/jvm/stdlib/index.html',
27− 'docs/reference/coroutines.html' => 'docs/reference/coroutines-overview.html',
28− 'api/latest/jvm/stdlib/kotlin/fold.html' => 'api/latest/jvm/stdlib/kotlin.collections/fold.html',
29− 'api/latest/jvm/stdlib/kotlin/get-or-else.html' => 'api/latest/jvm/stdlib/kotlin.collections/get-or-else.html',
30− 'api/latest/jvm/stdlib/kotlin/map.html' => 'api/latest/jvm/stdlib/kotlin.collections/map.html',
31− 'docs/tutorials/native/targeting-multiple-platforms.html' => 'docs/tutorials/native/basic-kotlin-native-app.html',
32− 'api/latest/jvm/stdlib/kotlin/-throwable/print-stack-trace.html' => 'api/latest/jvm/stdlib/kotlin/print-stack-trace.html',
33− }
23+
24+ options[:fix_urls] = ->(url) do
25+ url.sub! %r{/docs/reference/}, '/docs/'
26+ url
27+ end
3428
3529 options[:attribution] = <<-HTML
36− &copy; 2010&ndash;2020 JetBrains s.r.o. and Kotlin Programming Language contributors<br>
30+ &copy; 2010&ndash;2021 JetBrains s.r.o. and Kotlin Programming Language contributors<br>
3731 Licensed under the Apache License, Version 2.0.
3832 HTML
3933
34+ version '1.6' do
35+ self.release = '1.6.0'
36+ end
37+
38+ version '1.4' do
39+ self.release = '1.4.10'
40+ end
41+
4042 def get_latest_version(opts)
4143 get_latest_github_release('JetBrains', 'kotlin', opts)
4244 end
45+
46+ private
47+
48+ def process_response?(response)
49+ return false unless super
50+ response.body !~ /http-equiv="refresh"/i
51+ end
4352 end
4453 end