crystal.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. module Docs
  2. class Crystal < UrlScraper
  3. self.type = 'crystal'
  4. self.base_url = 'https://crystal-lang.org/'
  5. self.root_path = "api/#{release}/index.html"
  6. self.initial_paths = %w(docs/index.html)
  7. self.links = {
  8. home: 'https://crystal-lang.org/',
  9. code: 'https://github.com/crystal-lang/crystal'
  10. }
  11. html_filters.push 'crystal/entries', 'crystal/clean_html'
  12. options[:only_patterns] = [/\Adocs\//, /\Aapi\/#{release}\//]
  13. options[:skip_patterns] = [/debug/i]
  14. options[:replace_paths] = {
  15. "api/#{release}/" => "api/#{release}/index.html",
  16. 'docs/' => 'docs/index.html'
  17. }
  18. options[:attribution] = ->(filter) {
  19. if filter.slug.start_with?('docs')
  20. <<-HTML
  21. To the extent possible under law, the persons who contributed to this work
  22. have waived<br>all copyright and related or neighboring rights to this work
  23. by associating CC0 with it.
  24. HTML
  25. else
  26. <<-HTML
  27. &copy; 2012&ndash;2019 Manas Technology Solutions.<br>
  28. Licensed under the Apache License, Version 2.0.
  29. HTML
  30. end
  31. }
  32. version '0.31' do
  33. self.release = '0.31.0'
  34. end
  35. version '0.30' do
  36. self.release = '0.30.1'
  37. end
  38. def get_latest_version(opts)
  39. body = fetch('https://crystal-lang.org/api', opts)
  40. body.scan(/Crystal Docs ([0-9.]+)/)[0][0]
  41. end
  42. end
  43. end