crystal.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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;2020 Manas Technology Solutions.<br>
  21. Licensed under the Apache License, Version 2.0.
  22. HTML
  23. end
  24. }
  25. version do
  26. self.release = '0.35.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. def get_latest_version(opts)
  36. doc = fetch_doc('https://crystal-lang.org/', opts)
  37. doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]
  38. end
  39. end
  40. end