Update Angular.js documentation (1.3.0)

pull/129/head
Thibaut 10 years ago
parent 945eae8a88
commit c93adea843

@ -3,5 +3,12 @@
class app.views.AngularPage extends app.views.BasePage
afterRender: ->
for el in @findAllByTag('pre')
@highlightCode el, if el.textContent[0] is '<' then 'markup' else 'javascript'
lang = if el.classList.contains('lang-html') or el.textContent[0] is '<'
'markup'
else if el.classList.contains('lang-css')
'css'
else
'javascript'
el.setAttribute('class', '')
@highlightCode el, lang
return

@ -5,7 +5,7 @@
// Index
//
.nav-header.section {
.nav-index-section {
margin: 1.5em 0 1em -2em;
list-style: none;
font-weight: bold;

@ -2,44 +2,38 @@ module Docs
class Angular
class CleanHtmlFilter < Filter
def call
# Fix internal links (remove colons)
css('a[href]').each do |node|
node['href'] = node['href'].gsub %r{(directive|filter):}, '\1-'
root_page? ? root : other
# Remove ng-* attributes
css('*').each do |node|
node.attributes.each_key do |attribute|
node.remove_attribute(attribute) if attribute.start_with? 'ng-'
end
end
root_page? ? root : other
doc
end
def root
css('.pull-right', '.ng-hide').remove
# Turn "module [...]" <li> into <h2>
css('.nav-header.module').each do |node|
node.name = 'h2'
node.parent.before(node)
css('.nav-index-group').each do |node|
if heading = node.at_css('.nav-index-group-heading')
heading.name = 'h2'
end
node.parent.before(node.children)
end
# Remove links to "Directive", "Filter", etc.
css('a.guide').each do |node|
node.replace(node.content)
css('.nav-index-section').each do |node|
node.content = node.content
end
css('.toc-close', '.naked-list').remove
end
def other
css('#example', '.example', '#description_source', '#description_demo', '[id$="example"]').remove
css('#example', '.example', '#description_source', '#description_demo', '[id$="example"]', 'hr').remove
if at_css('h1').content.strip.empty?
# Ensure proper <h1> (e.g. ngResource, AUTO, etc.)
at_css('h2').tap do |node|
at_css('h1').content = node.try(:content) || slug
node.try(:remove)
end
else
# Clean up .hint in <h1>
css('h1 > div > .hint').each do |node|
node.parent.before("<small>(#{node.content.strip})</small>").remove
end
css('header').each do |node|
node.before(node.children).remove
end
at_css('h1').add_child(css('.view-source', '.improve-docs'))
@ -50,34 +44,41 @@ module Docs
div.remove
end
css('.api-profile-header-structure > li').each do |node|
node.inner_html = node.inner_html.remove('- ')
end
css('h1').each_with_index do |node, i|
next if i == 0
node.name = 'h2'
end
# Remove examples
css('.runnable-example').each do |node|
node.parent.remove
end
# Remove dead links (e.g. ngRepeat)
css('a.type-hint').each do |node|
node.name = 'code'
node.remove_attribute 'href'
end
# Remove some <code> elements
css('h1 > code', 'pre > code', 'h6 > code').each do |node|
node.before(node.content).remove
end
# Fix code indentation
css('code', 'pre').each do |node|
node.inner_html = node.inner_html.strip_heredoc.strip
css('pre > code').each do |node|
node.parent['class'] = node['class']
node.before(node.children).remove
end
# Make <pre> elements
css('.in-javascript', '.in-html-template-binding').each do |node|
node.name = 'pre'
node.content = node.content
# Remove some <code> elements
css('h1 > code', 'h2 > code', 'h3 > code', 'h4 > code', 'h6 > code').each do |node|
node.before(node.content).remove
end
css('ul.methods', 'ul.properties', 'ul.events').add_class('defs')
# Remove ng-* attributes
css('*').each do |node|
node.attributes.each_key do |attribute|
node.remove_attribute(attribute) if attribute.start_with? 'ng-'
css('ul.methods', 'ul.properties', 'ul.events').add_class('defs').each do |node|
node.css('> li > h3').each do |h3|
next if h3.content.present?
h3.content = h3.next_element.content
h3.next_element.remove
end
end
end

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

@ -2,22 +2,23 @@ module Docs
class Angular
class EntriesFilter < Docs::EntriesFilter
def get_name
name = slug.split(':').last
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
end
def get_type
type = slug.split('.').first
type = slug.split('/').first
type << " #{subtype}s" if type == 'ng' && subtype
type
end
def subtype
return @subtype if defined? @subtype
node = at_css 'h1'
data = node.content.match %r{\((.+) in module} if node
node = at_css '.api-profile-header-structure'
data = node.content.match %r{(\w+?) in module} if node
@subtype = data && data[1]
end
@ -25,9 +26,10 @@ module Docs
entries = []
css('ul.defs').each do |list|
list.css('> li > h3:first-child').each do |node|
name = node.content.strip
name.sub! %r{\(.+\)}, '()'
list.css('> li[id]').each do |node|
next unless heading = node.at_css('h3')
name = heading.content.strip
name.sub! %r{\(.*\);}, '()'
name.prepend "#{self.name.split.first}."
entries << [name, node['id']]
end

@ -3,11 +3,10 @@ module Docs
self.name = 'Angular.js'
self.slug = 'angular'
self.type = 'angular'
self.version = '1.2.12'
self.base_url = 'http://docs.angularjs.org/partials/api/'
self.version = '1.3.0'
self.base_url = 'https://code.angularjs.org/1.3.0/docs/partials/api/'
html_filters.insert_before 'normalize_paths', 'angular/clean_html'
html_filters.push 'angular/entries', 'title'
html_filters.push 'angular/clean_html', 'angular/entries', 'title'
text_filters.push 'angular/clean_urls'
options[:title] = false
@ -15,13 +14,13 @@ module Docs
options[:fix_urls] = ->(url) do
url.sub! '/partials/api/api/', '/partials/api/'
url.sub! '/partials/api/guide/', '/guide/'
url.sub! %r{/api/(.+?)/api/}, '/api/'
url.sub! %r{/partials/api/(.+?)(?<!\.html)(?:\z|(#.*))}, '/partials/api/\1.html\2'
url.gsub! '/partials/api/(.+?)\:', '/partials/api/\1%3A'
url
end
options[:skip] = %w(ng.html)
options[:skip_patterns] = [/\/(function|directive|object|type|provider|service|filter)\.html\z/]
options[:attribution] = <<-HTML
&copy; 2010&ndash;2014 Google, Inc.<br>
@ -53,7 +52,7 @@ module Docs
def get_root_page_body
require 'capybara'
Capybara.current_driver = :selenium
Capybara.visit('http://docs.angularjs.org/api/')
Capybara.visit('https://code.angularjs.org/1.3.0/docs/api')
Capybara.find('.side-navigation')['innerHTML']
end
end

Loading…
Cancel
Save