crystal.rb 1.4 KB

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