crystal.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. module Docs
  2. class Crystal < UrlScraper
  3. include MultipleBaseUrls
  4. self.type = 'crystal'
  5. self.release = '1.15.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[:skip_patterns] = [
  20. %r{\ACrystal/System/},
  21. %r{\ACrystal/PointerPairingHeap/},
  22. %r{\AIO/Evented.html\z},
  23. %r{\ARegex/PCRE2.html\z}
  24. ]
  25. options[:attribution] = ->(filter) {
  26. if filter.current_url.path.start_with?('/reference/')
  27. <<-HTML
  28. To the extent possible under law, the persons who contributed to this work
  29. have waived<br>all copyright and related or neighboring rights to this work
  30. by associating CC0 with it.
  31. HTML
  32. else
  33. <<-HTML
  34. &copy; 2012&ndash;2025 Manas Technology Solutions.<br>
  35. Licensed under the Apache License, Version 2.0.
  36. HTML
  37. end
  38. }
  39. def get_latest_version(opts)
  40. doc = fetch_doc('https://crystal-lang.org/', opts)
  41. doc.at_css('.latest-release-info > a > strong').content.scan(/([0-9.]+)/)[0][0]
  42. end
  43. end
  44. end