Update & improve Angular documentation (1.5.3)

Fixes #352.
pull/382/head
Thibaut Courouble 9 years ago
parent f9470dffe9
commit 8d959592b4

@ -278,6 +278,7 @@ class App < Sinatra::Application
get %r{\A/([\w~\.]+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|
return redirect "/#{DOC_REDIRECTS[doc]}#{type}#{rest}" if DOC_REDIRECTS.key?(doc)
return redirect "/angular/api#{rest}", 301 if doc == 'angular' && rest.start_with?('/ng')
return 404 unless @doc = find_doc(doc)
if rest.nil?

@ -36,7 +36,9 @@ module Docs
node.before(node.children).remove
end
at_css('h1').prepend_child(css('.view-source', '.improve-docs'))
if h1 = at_css('h1')
h1.prepend_child(css('.view-source', '.improve-docs'))
end
# Remove root-level <div>
while div = at_css('h1 + div')

@ -2,8 +2,8 @@ module Docs
class Angular
class CleanUrlsFilter < Filter
def call
html.gsub! "angularjs.org/#{Angular.release}/docs/partials/api/", "angularjs.org/#{Angular.release}/docs/api/"
html.gsub! %r{angularjs.org/#{Angular.release}/docs/api/(.+?)\.html}, "angularjs.org/#{Angular.release}/docs/api/\1"
html.gsub! %r{angularjs\.org/([\d\.]+)/docs/partials/(\w+)/}, 'angularjs.org/\1/docs/\2/'
html.gsub! %r{angularjs\.org/([\d\.]+)/docs/(\w+)/(.+?)\.html}, 'angularjs.org/\1/docs/\2/\3'
html
end
end

@ -2,17 +2,27 @@ module Docs
class Angular
class EntriesFilter < Docs::EntriesFilter
def get_name
name = slug.split('/').last
name.remove! %r{\Ang\.}
name << " (#{subtype})" if subtype == 'directive' || subtype == 'filter'
name.prepend("#{type}.") unless type.starts_with?('ng ') || name == type
name
if slug.start_with?('api')
name = URI.unescape(slug).split('/').last
name.remove! %r{\Ang\.}
name << " (#{subtype})" if subtype == 'directive' || subtype == 'filter'
name.prepend("#{type}.") unless type.starts_with?('ng ') || name == type
name
elsif slug.start_with?('guide')
name = URI.decode(at_css('.improve-docs')['href'][/message=docs\(guide%2F(.+?)\)/, 1])
name.prepend 'Guide: '
name
end
end
def get_type
type = slug.split('/').first
type << " #{subtype}s" if type == 'ng' && subtype
type
if slug.start_with?('api')
type = slug.split('/').drop(1).first
type << " #{subtype}s" if type == 'ng' && subtype
type
elsif slug.start_with?('guide')
'Guide'
end
end
def subtype
@ -23,6 +33,7 @@ module Docs
end
def additional_entries
return [] unless slug.start_with?('api')
entries = []
css('ul.defs').each do |list|
@ -37,10 +48,6 @@ module Docs
entries
end
def include_default_entry?
!at_css('h1 + .definition-table:last-child')
end
end
end
end

@ -5,8 +5,10 @@ module Docs
self.name = 'Angular.js'
self.slug = 'angular'
self.type = 'angular'
self.release = '1.5.0'
self.base_url = "https://code.angularjs.org/#{release}/docs/partials/api/"
self.release = '1.5.3'
self.base_url = "https://code.angularjs.org/#{release}/docs/partials/"
self.root_path = 'api.html'
self.initial_paths = %w(guide.html)
html_filters.push 'angular/clean_html', 'angular/entries', 'title'
text_filters.push 'angular/clean_urls'
@ -14,14 +16,25 @@ module Docs
options[:title] = false
options[:root_title] = 'Angular.js'
options[:decode_and_clean_paths] = true
options[:fix_urls_before_parse] = ->(str) do
str.gsub!('[', '%5B')
str.gsub!(']', '%5D')
str
end
options[:fix_urls] = ->(url) do
url.sub! '/partials/api/api/', '/partials/api/'
url.sub! %r{/api/(.+?)/api/}, '/api/'
url.sub! %r{/partials/api/(.+?)(?<!\.html)(?:\z|(#.*))}, '/partials/api/\1.html\2'
%w(api guide).each do |str|
url.sub! "/partials/#{str}/#{str}/", "/partials/#{str}/"
url.sub! %r{/#{str}/img/}, "/img/"
url.sub! %r{/#{str}/(.+?)/#{str}/}, "/#{str}/"
url.sub! %r{/partials/#{str}/(.+?)(?<!\.html)(?:\z|(#.*))}, "/partials/#{str}/\\1.html\\2"
end
url
end
options[:skip] = %w(ng.html)
options[:only_patterns] = [%r{\Aapi/}, %r{\Aguide/}]
options[:skip] = %w(api/ng.html)
options[:attribution] = <<-HTML
&copy; 2010&ndash;2016 Google, Inc.<br>
@ -31,9 +44,11 @@ module Docs
private
def root_page_body
require 'capybara'
require 'capybara/dsl'
Capybara.current_driver = :selenium
Capybara.visit("https://code.angularjs.org/#{self.class.release}/docs/api")
Capybara.run_server = false
Capybara.app_host = 'https://code.angularjs.org'
Capybara.visit("/#{self.class.release}/docs/api")
Capybara.find('.side-navigation')['innerHTML']
end
end

Loading…
Cancel
Save