1
0

angular.rb 2.0 KB

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