crystal.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.31' do
  26. self.release = '0.31.1'
  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.30' do
  36. self.release = '0.30.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. def get_latest_version(opts)
  46. doc = fetch_doc('https://crystal-lang.org/', opts)
  47. doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]
  48. end
  49. end
  50. end