1
0

angular.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. module Docs
  2. class Angular < UrlScraper
  3. self.type = 'angular'
  4. self.root_path = 'api/'
  5. self.links = {
  6. home: 'https://angular.io/',
  7. code: 'https://github.com/angular/angular'
  8. }
  9. html_filters.push 'angular/entries', 'angular/clean_html'
  10. options[:skip_patterns] = [/deprecated/, /VERSION-let/]
  11. options[:skip] = %w(
  12. index.html
  13. styleguide.html
  14. quickstart.html
  15. cheatsheet.html
  16. guide/cheatsheet.html
  17. guide/style-guide.html)
  18. options[:replace_paths] = {
  19. 'testing/index.html' => 'guide/testing.html',
  20. 'guide/glossary.html' => 'glossary.html',
  21. 'tutorial' => 'tutorial/',
  22. 'api' => 'api/'
  23. }
  24. options[:fix_urls] = -> (url) do
  25. url.sub! %r{\A(https://(?:v2\.)?angular\.io/docs/.+/)index\.html\z}, '\1'
  26. url
  27. end
  28. options[:attribution] = <<-HTML
  29. &copy; 2010&ndash;2017 Google, Inc.<br>
  30. Licensed under the Creative Commons Attribution License 4.0.
  31. HTML
  32. stub 'api/' do
  33. base_url = URL.parse(self.base_url)
  34. capybara = load_capybara_selenium
  35. capybara.app_host = base_url.origin
  36. capybara.visit(base_url.path + 'api/')
  37. capybara.execute_script('return document.body.innerHTML')
  38. end
  39. version '4 TypeScript' do
  40. self.release = '4.0.3'
  41. self.base_url = 'https://angular.io/docs/ts/latest/'
  42. end
  43. version '2 TypeScript' do
  44. self.release = '2.4.10'
  45. self.base_url = 'https://v2.angular.io/docs/ts/latest/'
  46. end
  47. private
  48. def parse(response)
  49. response.body.gsub! '<code-example', '<pre'
  50. response.body.gsub! '</code-example', '</pre'
  51. response.body.gsub! '<code-pane', '<pre'
  52. response.body.gsub! '</code-pane', '</pre'
  53. response.body.gsub! '<live-example></live-example>', 'live example'
  54. response.body.gsub! '<live-example', '<span'
  55. response.body.gsub! '</live-example', '</span'
  56. super
  57. end
  58. end
  59. end