1
0
Эх сурвалжийг харах

Add D3.js v4 documentation

Thibaut Courouble 9 жил өмнө
parent
commit
dc4ccd9d6c

+ 1 - 1
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -173,7 +173,7 @@ credits = [
     'D3.js',
     '2010-2016 Michael Bostock',
     'BSD',
-    'https://raw.githubusercontent.com/mbostock/d3/master/LICENSE'
+    'https://raw.githubusercontent.com/d3/d3/master/LICENSE'
   ], [
     'Django',
     'Django Software Foundation and individual contributors',

+ 0 - 6
assets/javascripts/views/pages/d3.coffee

@@ -1,6 +0,0 @@
-#= require views/pages/base
-
-class app.views.D3Page extends app.views.BasePage
-  prepare: ->
-    @highlightCode @findAll('.highlight > pre'), 'javascript'
-    return

+ 1 - 0
assets/javascripts/views/pages/simple.coffee

@@ -13,6 +13,7 @@ app.views.CPage =
 app.views.CakephpPage =
 app.views.ChaiPage =
 app.views.CrystalPage =
+app.views.D3Page =
 app.views.DrupalPage =
 app.views.ElixirPage =
 app.views.EmberPage =

+ 9 - 1
assets/stylesheets/pages/_d3.scss

@@ -1,6 +1,14 @@
 ._d3 {
   > h2 { @extend %block-heading; }
-  > h3, > h4 { font-size: 1rem; }
+  > h3 { @extend %block-label; }
+  > h4 { font-size: 1rem; }
   > h6 { @extend %block-label, %label-blue; }
+
+  > h6 > .source {
+    float: right;
+    font-weight: normal;
+  }
+
   code { @extend %label; }
+  blockquote { @extend %note, %note-blue; }
 }

+ 27 - 15
lib/docs/filters/d3/clean_html.rb

@@ -2,35 +2,35 @@ module Docs
   class D3
     class CleanHtmlFilter < Filter
       def call
+        css('p:contains("This page describes the D3 3.x API.")').remove
+
         # Remove links inside <h2> and add "id" attributes
-        css('h2 > a').each do |node|
+        css('a.anchor').each do |node|
           node.parent['id'] = (node['id'] || node['name']).remove('user-content-') if node['id'] || node['name']
           node.before(node.children).remove
         end
 
-        css('.markdown-body > blockquote:first-child', '.anchor').remove
-
-        # Replace .gh-header with <h1>
-        css('.gh-header-title').each do |node|
-          node.parent.parent.before(node).remove
-          node.content = 'D3.js' if root_page?
-        end
-
-        # Move content to the root-level
-        css('#wiki-content').each do |node|
-          node.before(node.at_css('#wiki-body .markdown-body').children).remove
-        end
-
         # Make headings for function definitions and add "id" attributes
         css('p > a:first-child').each do |node|
           next unless node['name'] || node.content == '#'
           parent = node.parent
           parent.name = 'h6'
           parent['id'] = (node['name'] || node['href'].remove(/\A.+#/)).remove('user-content-')
-          parent.css('a[name]').remove
+          parent.css('a[name], a:contains("#")').remove
           node.remove
         end
 
+        css('h4').each { |node| node.name = 'h3' } if root_page?
+
+        css('a > img').each do |node|
+          node.parent.before(node).remove
+        end
+
+        css('h6 a[title="Source"]').each do |node|
+          node.content = 'Source'
+          node['class'] = 'source'
+        end
+
         # Fix internal links
         css('a[href]').each do |node|
           node['href'] = node['href'].sub(/#user\-content\-(\w+?)\z/, '#\1').sub(/#wiki\-(\w+?)\z/, '#\1')
@@ -39,6 +39,18 @@ module Docs
         # Remove code highlighting
         css('.highlight > pre').each do |node|
           node.content = node.content
+          node['data-language'] = if node.parent['class'].include?('html')
+            'markup'
+          elsif node.parent['class'].include?('css')
+            'css'
+          else
+            'javascript'
+          end
+          node.parent.before(node).remove
+        end
+
+        css('pre > code').each do |node|
+          node.before(node.children).remove
         end
 
         doc

+ 5 - 6
lib/docs/filters/d3/entries.rb → lib/docs/filters/d3/entries_v3.rb

@@ -1,21 +1,20 @@
 module Docs
   class D3
-    class EntriesFilter < Docs::EntriesFilter
+    class EntriesV3Filter < Docs::EntriesFilter
       def get_name
-        at_css('h1').content
+        File.basename(slug, '.md').gsub('-', ' ')
       end
 
       def get_type
-        name
+        at_css('h6[id]') ? name : 'D3'
       end
 
       def additional_entries
-        css('h6[id]').inject [] do |entries, node|
+        css('h6[id]').each_with_object [] do |node, entries|
           name = node.content.strip
-          name.remove! %r{\(.*\z}
+          name.sub! %r{\(.*\z}, '()'
           name.sub! %r{\A(svg:\w+)\s+.+}, '\1'
           entries << [name, node['id']] unless name == entries.last.try(:first)
-          entries
         end
       end
     end

+ 33 - 0
lib/docs/filters/d3/entries_v4.rb

@@ -0,0 +1,33 @@
+module Docs
+  class D3
+    class EntriesV4Filter < Docs::EntriesFilter
+      def get_name
+        name = at_css('h1').content
+        name.remove! 'd3-'
+        name
+      end
+
+      def get_type
+        return 'D3' unless at_css('h6[id]')
+        type = name.titleize
+        type.sub! 'Hsv', 'HSV'
+        type.sub! 'Dsv', 'DSV'
+        type
+      end
+
+      def additional_entries
+        css('h6[id]').each_with_object [] do |node, entries|
+          name = node.content.strip
+          name.remove! 'Source'
+          name.remove! '<>'
+          name.gsub! %r{\(.+?\)\)?}, '()'
+          name.sub! %r{\A(svg:\w+)\s+.+}, '\1'
+          name.split(/\s+/).each do |n|
+            next if n.blank?
+            entries << [n, node['id']] unless n == entries.last.try(:first)
+          end
+        end
+      end
+    end
+  end
+end

+ 30 - 32
lib/docs/scrapers/d3.rb

@@ -3,45 +3,43 @@ module Docs
     self.name = 'D3.js'
     self.slug = 'd3'
     self.type = 'd3'
-    self.release = '3.5.16'
-    self.base_url = 'https://github.com/mbostock/d3/wiki/'
-    self.root_path = 'API-Reference'
     self.links = {
-      home: 'http://d3js.org/',
-      code: 'https://github.com/mbostock/d3'
+      home: 'https://d3js.org/',
+      code: 'https://github.com/d3/d3'
     }
 
-    html_filters.push 'd3/clean_html', 'd3/entries'
-
-    options[:container] = '#wiki-wrapper'
-
-    options[:only] = %w(
-      Selections
-      Transitions
-      Arrays
-      Math
-      Requests
-      Formatting
-      CSV
-      Localization
-      Colors
-      Namespaces
-      Internals)
-
-    options[:only_patterns] = [
-      /\-Scales\z/,
-      /\ASVG\-\w/,
-      /\ATime\-/,
-      /\-Layout\z/,
-      /\AGeo\-/,
-      /\-Geom\z/,
-      /\-Behavior\z/]
-
-    options[:skip_patterns] = [/\//]
+    options[:container] = '.markdown-body'
 
     options[:attribution] = <<-HTML
       &copy; 2010&ndash;2016 Michael Bostock<br>
       Licensed under the BSD License.
     HTML
+
+    version '4' do
+      self.release = '4.2.2'
+      self.base_url = 'https://github.com/d3/'
+      self.root_path = 'd3/blob/master/API.md'
+
+      html_filters.push 'd3/clean_html', 'd3/entries_v4'
+
+      options[:only_patterns] = [/\Ad3[\-\w]+\z/, /\Ad3\/blob\/master\/changes\.md\z/i]
+      options[:skip_patterns] = [/3\.x-api-reference/]
+
+      options[:fix_urls] = ->(url) do
+        url.sub! %r{/blob/master/readme.md}i, ''
+        url
+      end
+    end
+
+    version '3' do
+      self.release = '3.5.17'
+      self.base_url = 'https://github.com/d3/d3-3.x-api-reference/blob/master/'
+      self.root_path = 'API-Reference.md'
+
+      html_filters.push 'd3/clean_html', 'd3/entries_v3', 'title'
+
+      options[:root_title] = 'D3.js'
+      options[:only_patterns] = [/\.md\z/]
+    end
   end
 end