eigen3.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. module Docs
  2. class Eigen3 < UrlScraper
  3. self.name = 'Eigen3'
  4. self.type = 'eigen3'
  5. self.slug = 'eigen3'
  6. self.base_url = 'https://eigen.tuxfamily.org/dox/'
  7. self.root_path = 'index.html'
  8. self.initial_paths = [
  9. "modules.html"
  10. ]
  11. self.release = '3.4.0'
  12. self.links = {
  13. home: 'https://eigen.tuxfamily.org',
  14. code: 'https://gitlab.com/libeigen/eigen'
  15. }
  16. html_filters.push 'eigen3/entries', 'eigen3/clean_html'
  17. # Remove the `clean_text` because Doxygen are actually creating empty
  18. # anchor such as <a id="asd"></a> to do anchor link.. and that anchor
  19. # will be removed by clean_text
  20. self.text_filters = FilterStack.new
  21. text_filters.push 'images', 'inner_html', 'attribution'
  22. def get_latest_version(opts)
  23. tags = get_gitlab_tags("https://gitlab.com", "libeigen", "eigen", opts)
  24. tags[0]['name']
  25. end
  26. options[:attribution] = <<-HTML
  27. &copy; Eigen.<br>
  28. Licensed under the MPL2 License.
  29. HTML
  30. # Skip source code since it doesn't provide any useful docs
  31. options[:skip_patterns] = [/_source/, /-members/, /__Reference\.html/, /_chapter\.html/,]
  32. # TODO: replace cppreference
  33. # options[:replace_urls] = { 'http://en.cppreference.com/w/cpp/' => 'cpp/' }
  34. def parse(response) # Hook here because Nokogori removes whitespace from code fragments
  35. last_idx = 0
  36. # Process nested <div>s inside code fragment div.
  37. while not (last_idx = response.body.index('<div class="fragment">', last_idx)).nil?
  38. # enter code fragment <div>
  39. level = 1
  40. while not (last_idx = response.body.index(/<\/?div/, last_idx+1)).nil?
  41. # skip nested divs inside.
  42. if response.body[last_idx..last_idx+3] == '<div'
  43. level += 1
  44. else
  45. level -= 1
  46. end
  47. break if level == 0 # exit code fragment
  48. end
  49. if not last_idx.nil? and response.body[last_idx..last_idx+5] == '</div>'
  50. response.body[last_idx..last_idx+5] = '</pre>'
  51. end
  52. end
  53. response.body.gsub! /[\r\n\s]*<div class="ttc"[^>]*>.*<\/div>[\r\n\s]*/, ""
  54. response.body.gsub! /<div class="line">(.*?)<\/div>/m, "\\1"
  55. response.body.gsub! '<div class="fragment">', '<pre class="fragment" data-language="cpp">'
  56. super
  57. end
  58. end
  59. end