فهرست منبع

Add Angular 2 Dart documentation

Thibaut Courouble 9 سال پیش
والد
کامیت
a05ed038d4

+ 6 - 5
assets/stylesheets/pages/_angular.scss

@@ -1,24 +1,25 @@
 ._angular {
   padding-left: 1rem;
 
-  h1, h2, > h3, .banner, .badges { margin-left: -1rem; }
+  h1, h2, > h3, .banner, .badges, .breadcrumbs { margin-left: -1rem; }
 
   ._mobile & {
     padding-left: 0;
 
-    h1, h2, > h3, .banner, .badges { margin-left: 0; }
+    h1, h2, > h3, .banner, .badges, .breadcrumbs { margin-left: 0; }
   }
 
   h2 { @extend %block-heading; }
   > h3 { @extend %block-label, %label-blue; }
   .code-example > h4, .pre-title { @extend %pre-heading; }
 
-  p > code, .status-badge { @extend %label; }
+  p > code, dd > code, .status-badge { @extend %label; }
 
-  .l-sub-section, .alert, .banner { @extend %note; }
+  .l-sub-section, .alert, .banner, .breadcrumbs { @extend %note; }
   .banner { @extend %note-green; }
   .alert.is-important { @extend %note-red; }
-  .alert.is-helpful { @extend %note-blue; }
+  .alert.is-helpful, .breadcrumbs { @extend %note-blue; }
+  .breadcrumbs { padding-left: 2em; }
 
   td > h3, .l-sub-section > h3, .l-sub-section > h4, .alert > h3, .alert > h4, .row-margin > h3 {
     margin-top: .25rem;

+ 11 - 3
lib/docs/filters/angular/clean_html.rb

@@ -9,7 +9,7 @@ module Docs
           node.to_html
         end.join(' ')
         badges = %(<div class="badges">#{badges}</div>)
-        container.child.before(at_css('header.hero h1')).before(badges).before(css('header.hero + .banner'))
+        container.child.before(at_css('header.hero h1')).before(badges).before(css('header.hero + .banner, header.hero .breadcrumbs'))
         @doc = container
 
         title = at_css('h1').content.strip
@@ -17,6 +17,8 @@ module Docs
           at_css('h1').content = result[:entries].first.name
         elsif title == 'Angular'
           at_css('h1').content = slug.split('/').last.gsub('-', ' ')
+        elsif at_css('.breadcrumbs') && title != result[:entries].first.name
+          at_css('h1').content = result[:entries].first.name
         end
 
         css('pre.no-bg-with-indent').each do |node|
@@ -28,9 +30,9 @@ module Docs
           node.parent.content = node.parent.css('code, pre').map(&:content).join("\n")
         end
 
-        css('button.verbose', 'button.verbose + .l-verbose-section', 'a[id=top]', 'a[href="#top"]').remove
+        css('button.verbose', 'button.verbose + .l-verbose-section', 'a[id=top]', 'a[href="#top"]', '.sidebar').remove
 
-        css('.c10', '.showcase', '.showcase-content', '.l-main-section', 'div.div', 'div[flex]', 'code-tabs', 'md-card', 'md-card-content', 'div:not([class])', 'footer', '.card-row', '.card-row-container', 'figure', 'blockquote', 'exported', 'defined', 'div.ng-scope', '.code-example header').each do |node|
+        css('.c10', '.showcase', '.showcase-content', '.l-main-section', 'div.div', 'div[flex]', 'code-tabs', 'md-card', 'md-card-content', 'div:not([class])', 'footer', '.card-row', '.card-row-container', 'figure', 'blockquote', 'exported', 'defined', 'div.ng-scope', '.code-example header', 'section.desc', '.row', '.dart-api-entry-main', '.main-content', 'section.summary', 'span.signature').each do |node|
           node.before(node.children).remove
         end
 
@@ -44,6 +46,12 @@ module Docs
 
         css('pre.prettyprint').each do |node|
           node.content = node.content.strip
+          node['data-language'] = 'dart' if node['class'].include?('dart')
+        end
+
+        css('.multi-line-signature').each do |node|
+          node.name = 'pre'
+          node.content = node.content.strip
         end
 
         css('a[id]:empty').each do |node|

+ 10 - 3
lib/docs/filters/angular/entries.rb

@@ -3,7 +3,7 @@ module Docs
     class EntriesFilter < Docs::EntriesFilter
       def get_name
         if slug.start_with?('tutorial') || slug.start_with?('guide')
-          name = at_css('.nav-list-item.is-selected').content.strip
+          name = at_css('.nav-list-item.is-selected, header.hero h1').content.strip
         else
           name = at_css('header.hero h1').content.strip
         end
@@ -18,7 +18,11 @@ module Docs
           end
         end
 
-        name << '()' if at_css('.hero-subtitle').try(:content) == 'Function'
+        subtitle = at_css('.hero-subtitle').try(:content)
+        breadcrumbs = css('.breadcrumbs li').map(&:content)[2..-2]
+
+        name.prepend "#{breadcrumbs.join('.')}#" if breadcrumbs.present? && breadcrumbs[0] != name
+        name << '()' if %w(Function Method Constructor).include?(subtitle)
         name
       end
 
@@ -46,7 +50,10 @@ module Docs
       private
 
       def mod
-        @mod ||= slug[/api\/([\w\-]+)\//, 1]
+        return @mod if defined?(@mod)
+        @mod = slug[/api\/([\w\-\.]+)\//, 1]
+        @mod.remove! 'angular2.' if @mod
+        @mod
       end
     end
   end

+ 11 - 1
lib/docs/scrapers/angular.rb

@@ -36,7 +36,7 @@ module Docs
     stub 'api/' do
       capybara = load_capybara_selenium
       capybara.app_host = 'https://angular.io'
-      capybara.visit('/docs/ts/latest/api/')
+      capybara.visit(URL.parse(self.base_url).path + 'api/')
       capybara.execute_script('return document.body.innerHTML')
     end
 
@@ -45,6 +45,16 @@ module Docs
       self.base_url = 'https://angular.io/docs/ts/latest/'
     end
 
+    version '2 Dart' do
+      self.release = '2.1.2'
+      self.base_url = 'https://angular.io/docs/dart/latest/'
+
+      options[:skip_patterns] += [/angular2\.compiler/]
+      options[:skip_link] = ->(link) do
+        link.parent['class'].try(:include?, 'inherited') || link.parent.parent['class'].try(:include?, 'inherited')
+      end
+    end
+
     private
 
     def parse(string)