crystal.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. module Docs
  2. class Crystal < UrlScraper
  3. self.type = 'crystal'
  4. self.release = '0.27.0'
  5. self.base_url = 'https://crystal-lang.org/'
  6. self.root_path = "api/#{release}/index.html"
  7. self.initial_paths = %w(docs/index.html)
  8. self.links = {
  9. home: 'https://crystal-lang.org/',
  10. code: 'https://github.com/crystal-lang/crystal'
  11. }
  12. html_filters.push 'crystal/entries', 'crystal/clean_html'
  13. options[:only_patterns] = [/\Adocs\//, /\Aapi\/#{release}\//]
  14. options[:skip_patterns] = [/debug/i]
  15. options[:replace_paths] = {
  16. "api/#{release}/" => "api/#{release}/index.html",
  17. 'docs/' => 'docs/index.html'
  18. }
  19. options[:attribution] = ->(filter) {
  20. if filter.slug.start_with?('docs')
  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;2018 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. body = fetch('https://crystal-lang.org/api', opts)
  35. body.scan(/Crystal Docs ([0-9.]+)/)[0][0]
  36. end
  37. end
  38. end