crystal.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. module Docs
  2. class Crystal < UrlScraper
  3. self.type = 'crystal'
  4. self.base_url = 'https://crystal-lang.org/'
  5. self.initial_paths = %w(reference/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?('reference')
  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;2021 Manas Technology Solutions.<br>
  21. Licensed under the Apache License, Version 2.0.
  22. HTML
  23. end
  24. }
  25. self.release = '1.0.0'
  26. self.root_path = "api/#{release}/index.html"
  27. options[:only_patterns] = [/\Aapi\/#{release}\//, /\Areference\//]
  28. options[:skip_patterns] = [/debug/i]
  29. options[:replace_paths] = {
  30. "api/#{release}/" => "api/#{release}/index.html",
  31. 'reference/' => 'reference/index.html'
  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