go.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module Docs
  2. class Go < UrlScraper
  3. self.type = 'go'
  4. self.release = '1.15'
  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. def get_latest_version(opts)
  23. doc = fetch_doc('https://golang.org/project/', opts)
  24. doc.at_css('#page ul > li > a').text[3..-1]
  25. end
  26. private
  27. def parse(response) # Hook here because Nokogori removes whitespace from textareas
  28. response.body.gsub! %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>'
  29. super
  30. end
  31. end
  32. end