go.rb 947 B

12345678910111213141516171819202122232425262728293031323334
  1. module Docs
  2. class Go < UrlScraper
  3. self.type = 'go'
  4. self.release = '1.10.1'
  5. self.base_url = 'https://golang.org/pkg/'
  6. self.links = {
  7. home: 'https://golang.org/',
  8. code: 'https://go.googlesource.com/go'
  9. }
  10. html_filters.push 'go/clean_html', 'go/entries'
  11. options[:trailing_slash] = true
  12. options[:container] = '#page .container'
  13. options[:skip] = %w(runtime/msan/)
  14. options[:skip_patterns] = [/\/\//]
  15. options[:fix_urls] = ->(url) do
  16. url.sub 'https://golang.org/pkg//', 'https://golang.org/pkg/'
  17. end
  18. options[:attribution] = <<-HTML
  19. &copy; Google, Inc.<br>
  20. Licensed under the Creative Commons Attribution License 3.0.
  21. HTML
  22. private
  23. def parse(response) # Hook here because Nokogori removes whitespace from textareas
  24. response.body.gsub! %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>'
  25. super
  26. end
  27. end
  28. end