angular.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. guide/cheatsheet.html
  16. guide/style-guide.html)
  17. options[:replace_paths] = {
  18. 'testing/index.html' => 'guide/testing.html',
  19. 'guide/glossary.html' => 'glossary.html',
  20. 'tutorial' => 'tutorial/',
  21. 'api' => 'api/'
  22. }
  23. options[:fix_urls] = -> (url) do
  24. url.sub! %r{\A(https://angular\.io/docs/.+/)index\.html\z}, '\1'
  25. url
  26. end
  27. options[:attribution] = <<-HTML
  28. &copy; 2010&ndash;2016 Google, Inc.<br>
  29. Licensed under the Creative Commons Attribution License 4.0.
  30. HTML
  31. stub 'api/' do
  32. capybara = load_capybara_selenium
  33. capybara.app_host = 'https://angular.io'
  34. capybara.visit(URL.parse(self.base_url).path + 'api/')
  35. capybara.execute_script('return document.body.innerHTML')
  36. end
  37. version '2 TypeScript' do
  38. self.release = '2.4.3'
  39. self.base_url = 'https://angular.io/docs/ts/latest/'
  40. end
  41. version '2 Dart' do
  42. self.release = '2.2.4'
  43. self.base_url = 'https://angular.io/docs/dart/latest/'
  44. options[:skip_patterns] += [/angular2\.compiler/]
  45. options[:skip_link] = ->(link) do
  46. link.parent['class'].try(:include?, 'inherited') || link.parent.parent['class'].try(:include?, 'inherited')
  47. end
  48. end
  49. private
  50. def parse(string)
  51. string.gsub! '<code-example', '<pre'
  52. string.gsub! '</code-example', '</pre'
  53. string.gsub! '<code-pane', '<pre'
  54. string.gsub! '</code-pane', '</pre'
  55. string.gsub! '<live-example></live-example>', 'live example'
  56. string.gsub! '<live-example', '<span'
  57. string.gsub! '</live-example', '</span'
  58. super string
  59. end
  60. end
  61. end