kotlin.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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;2022 JetBrains s.r.o. and Kotlin Programming Language contributors<br>
  27. Licensed under the Apache License, Version 2.0.
  28. HTML
  29. version '1.6' do
  30. self.release = '1.6.20'
  31. end
  32. version '1.4' do
  33. self.release = '1.4.10'
  34. end
  35. def get_latest_version(opts)
  36. get_latest_github_release('JetBrains', 'kotlin', opts)
  37. end
  38. private
  39. def process_response?(response)
  40. return false unless super
  41. response.body !~ /http-equiv="refresh"/i
  42. end
  43. def parse(response)
  44. response.body.gsub! %r{<div\ class="code-block" data-lang="([^"]+)"[^>]*>([\W\w]+?)</div>}, '<pre class="code" data-language="\1">\2</pre>'
  45. super
  46. end
  47. end
  48. end