1
0

kotlin.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. module Docs
  2. class Kotlin < UrlScraper
  3. self.type = 'kotlin'
  4. self.base_url = 'https://kotlinlang.org/'
  5. self.root_path = 'api/latest/jvm/stdlib/index.html'
  6. self.links = {
  7. home: 'https://kotlinlang.org/',
  8. code: 'https://github.com/JetBrains/kotlin'
  9. }
  10. html_filters.push 'kotlin/entries', 'kotlin/clean_html'
  11. options[:container] = 'article'
  12. options[:only_patterns] = [/\Adocs\//, /\Aapi\/latest\/jvm\/stdlib\//]
  13. options[:skip_patterns] = [/stdlib\/org\./]
  14. options[:skip] = %w(
  15. api/latest/jvm/stdlib/alltypes/index.html
  16. docs/
  17. docs/videos.html
  18. docs/events.html
  19. docs/resources.html
  20. docs/reference/grammar.html)
  21. options[:fix_urls] = ->(url) do
  22. url.sub! %r{/docs/reference/}, '/docs/'
  23. url
  24. end
  25. options[:attribution] = <<-HTML
  26. &copy; 2010&ndash;2023 JetBrains s.r.o. and Kotlin Programming Language contributors<br>
  27. Licensed under the Apache License, Version 2.0.
  28. HTML
  29. version '1.9' do
  30. self.release = '1.9.0'
  31. self.headers = { 'User-Agent' => 'devdocs.io' , 'Cookie' => 'x-ab-test-spring-boot-learning-path=0; userToken=r33dgpe8x3q5vswekg16a' }
  32. end
  33. version '1.8' do
  34. self.release = '1.8.0'
  35. self.headers = { 'User-Agent' => 'devdocs.io' , 'Cookie' => 'x-ab-test-spring-boot-learning-path=0; userToken=r33dgpe8x3q5vswekg16a' }
  36. end
  37. version '1.7' do
  38. self.release = '1.7.20'
  39. end
  40. version '1.6' do
  41. self.release = '1.6.20'
  42. end
  43. version '1.4' do
  44. self.release = '1.4.10'
  45. end
  46. def get_latest_version(opts)
  47. get_latest_github_release('JetBrains', 'kotlin', opts)
  48. end
  49. private
  50. def process_response?(response)
  51. return false unless super
  52. response.body !~ /http-equiv="refresh"/i
  53. end
  54. def parse(response)
  55. response.body.gsub! %r{<div\ class="code-block" data-lang="([^"]+)"[^>]*>([\W\w]+?)</div>}, '<pre class="code" data-language="\1">\2</pre>'
  56. super
  57. end
  58. end
  59. end