crystal.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. module Docs
  2. class Crystal < UrlScraper
  3. include MultipleBaseUrls
  4. self.type = 'crystal'
  5. self.release = '1.11.1'
  6. self.base_urls = [
  7. "https://crystal-lang.org/api/#{release}/",
  8. "https://crystal-lang.org/reference/#{release[0..2]}/",
  9. ]
  10. def initial_urls
  11. [ "https://crystal-lang.org/api/#{self.class.release}/index.html",
  12. "https://crystal-lang.org/reference/#{self.class.release[0..2]}/index.html" ]
  13. end
  14. self.links = {
  15. home: 'https://crystal-lang.org/',
  16. code: 'https://github.com/crystal-lang/crystal'
  17. }
  18. html_filters.push 'crystal/entries', 'crystal/clean_html'
  19. options[:attribution] = ->(filter) {
  20. if filter.current_url.path.start_with?('/reference/')
  21. <<-HTML
  22. To the extent possible under law, the persons who contributed to this work
  23. have waived<br>all copyright and related or neighboring rights to this work
  24. by associating CC0 with it.
  25. HTML
  26. else
  27. <<-HTML
  28. &copy; 2012&ndash;2024 Manas Technology Solutions.<br>
  29. Licensed under the Apache License, Version 2.0.
  30. HTML
  31. end
  32. }
  33. def get_latest_version(opts)
  34. doc = fetch_doc('https://crystal-lang.org/', opts)
  35. doc.at_css('.latest-release').content.scan(/([0-9.]+)/)[0][0]
  36. end
  37. end
  38. end