crystal.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. module Docs
  2. class Crystal < UrlScraper
  3. self.type = 'crystal'
  4. self.base_url = 'https://crystal-lang.org/'
  5. self.initial_paths = %w(docs/index.html)
  6. self.links = {
  7. home: 'https://crystal-lang.org/',
  8. code: 'https://github.com/crystal-lang/crystal'
  9. }
  10. html_filters.push 'crystal/entries', 'crystal/clean_html'
  11. options[:attribution] = ->(filter) {
  12. if filter.slug.start_with?('docs')
  13. <<-HTML
  14. To the extent possible under law, the persons who contributed to this work
  15. have waived<br>all copyright and related or neighboring rights to this work
  16. by associating CC0 with it.
  17. HTML
  18. else
  19. <<-HTML
  20. &copy; 2012&ndash;2019 Manas Technology Solutions.<br>
  21. Licensed under the Apache License, Version 2.0.
  22. HTML
  23. end
  24. }
  25. version '0.33' do
  26. self.release = '0.33.0'
  27. self.root_path = "api/#{release}/index.html"
  28. options[:only_patterns] = [/\Adocs\//, /\Aapi\/#{release}\//]
  29. options[:skip_patterns] = [/debug/i]
  30. options[:replace_paths] = {
  31. "api/#{release}/" => "api/#{release}/index.html",
  32. 'docs/' => 'docs/index.html'
  33. }
  34. end
  35. version '0.32' do
  36. self.release = '0.32.1'
  37. self.root_path = "api/#{release}/index.html"
  38. options[:only_patterns] = [/\Adocs\//, /\Aapi\/#{release}\//]
  39. options[:skip_patterns] = [/debug/i]
  40. options[:replace_paths] = {
  41. "api/#{release}/" => "api/#{release}/index.html",
  42. 'docs/' => 'docs/index.html'
  43. }
  44. end
  45. version '0.31' do
  46. self.release = '0.31.1'
  47. self.root_path = "api/#{release}/index.html"
  48. options[:only_patterns] = [/\Adocs\//, /\Aapi\/#{release}\//]
  49. options[:skip_patterns] = [/debug/i]
  50. options[:replace_paths] = {
  51. "api/#{release}/" => "api/#{release}/index.html",
  52. 'docs/' => 'docs/index.html'
  53. }
  54. end
  55. version '0.30' do
  56. self.release = '0.30.1'
  57. self.root_path = "api/#{release}/index.html"
  58. options[:only_patterns] = [/\Adocs\//, /\Aapi\/#{release}\//]
  59. options[:skip_patterns] = [/debug/i]
  60. options[:replace_paths] = {
  61. "api/#{release}/" => "api/#{release}/index.html",
  62. 'docs/' => 'docs/index.html'
  63. }
  64. end
  65. def get_latest_version(opts)
  66. doc = fetch_doc('https://crystal-lang.org/', opts)
  67. doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]
  68. end
  69. end
  70. end