1
0

c.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. module Docs
  2. class C < FileScraper
  3. self.type = 'c'
  4. self.base_url = 'http://en.cppreference.com/w/c/'
  5. self.root_path = 'header.html'
  6. html_filters.insert_before 'clean_html', 'c/fix_code'
  7. html_filters.push 'c/entries', 'c/clean_html', 'title'
  8. text_filters.push 'c/fix_urls'
  9. options[:decode_and_clean_paths] = true
  10. options[:container] = '#content'
  11. options[:title] = false
  12. options[:root_title] = 'C Programming Language'
  13. options[:skip] = %w(language/history.html)
  14. options[:skip_patterns] = [/experimental/]
  15. options[:fix_urls] = ->(url) do
  16. url.sub! %r{\A.+/http%3A/}, 'http://'
  17. url.sub! 'http://en.cppreference.com/upload.cppreference.com', 'http://upload.cppreference.com'
  18. url
  19. end
  20. options[:attribution] = <<-HTML
  21. &copy; cppreference.com<br>
  22. Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
  23. HTML
  24. def get_latest_version(opts)
  25. doc = fetch_doc('https://en.cppreference.com/w/Cppreference:Archives', opts)
  26. link = doc.at_css('a[title^="File:"]')
  27. date = link.content.scan(/(\d+)\./)[0][0]
  28. DateTime.strptime(date, '%Y%m%d').to_time.to_i
  29. end
  30. private
  31. def file_path_for(*)
  32. URI.unescape(super)
  33. end
  34. end
  35. end