1
0

kotlin.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.7' do
  30. self.release = '1.7.0'
  31. end
  32. version '1.6' do
  33. self.release = '1.6.20'
  34. end
  35. version '1.4' do
  36. self.release = '1.4.10'
  37. end
  38. def get_latest_version(opts)
  39. get_latest_github_release('JetBrains', 'kotlin', opts)
  40. end
  41. private
  42. def process_response?(response)
  43. return false unless super
  44. response.body !~ /http-equiv="refresh"/i
  45. end
  46. def parse(response)
  47. response.body.gsub! %r{<div\ class="code-block" data-lang="([^"]+)"[^>]*>([\W\w]+?)</div>}, '<pre class="code" data-language="\1">\2</pre>'
  48. super
  49. end
  50. end
  51. end