crystal.rb 1.6 KB

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