rust.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module Docs
  2. class Rust < UrlScraper
  3. self.type = 'rust'
  4. self.release = '1.15.0'
  5. self.base_url = 'https://doc.rust-lang.org/'
  6. self.root_path = 'book/index.html'
  7. self.initial_paths = %w(
  8. reference.html
  9. collections/index.html
  10. std/index.html
  11. error-index.html)
  12. self.links = {
  13. home: 'https://www.rust-lang.org/',
  14. code: 'https://github.com/rust-lang/rust'
  15. }
  16. html_filters.push 'rust/entries', 'rust/clean_html'
  17. options[:only_patterns] = [
  18. /\Abook\//,
  19. /\Acollections\//,
  20. /\Astd\// ]
  21. options[:skip] = %w(book/README.html)
  22. options[:skip_patterns] = [/(?<!\.html)\z/]
  23. options[:fix_urls] = ->(url) do
  24. url.sub! %r{(#{Rust.base_url}.+/)\z}, '\1index.html'
  25. url.sub! '/unicode/u_str', '/unicode/str/'
  26. url
  27. end
  28. options[:attribution] = <<-HTML
  29. &copy; 2010 The Rust Project Developers<br>
  30. Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
  31. HTML
  32. private
  33. REDIRECT_RGX = /http-equiv="refresh"/i
  34. NOT_FOUND_RGX = /<title>Not Found<\/title>/
  35. def process_response?(response)
  36. !(response.body =~ REDIRECT_RGX || response.body =~ NOT_FOUND_RGX || response.body.blank?)
  37. end
  38. end
  39. end