Przeglądaj źródła

Add D3.js documentation

Thibaut 12 lat temu
rodzic
commit
8e469d340e

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -93,6 +93,11 @@ credits = [
     '2005-2013 Mozilla Developer Network and individual contributors',
     'CC BY-SA',
     'http://creativecommons.org/licenses/by-sa/2.5/'
+  ], [
+    'D3.js',
+    '2014 Michael Bostock',
+    'BSD',
+    'https://raw.github.com/mbostock/d3/master/LICENSE'
   ], [
     'Ember.js',
     '2014 Yehuda Katz, Tom Dale and Ember.js contributors',

+ 4 - 1
assets/javascripts/templates/pages/news_tmpl.coffee

@@ -24,7 +24,10 @@ newsItem = (date, news) ->
   result
 
 app.news = [
-  [ 1390003200000, # January 18, 2013
+  [ 1390089600000, # January 19, 2013
+    """ New <a href="/d3/">D3.js</a> documentation """,
+  ], [
+    1390003200000, # January 18, 2013
     """ DevDocs is now available as a <a href="https://marketplace.firefox.com/app/devdocs/">Firefox web app</a> (currently requires Aurora). """,
   ], [
     1389484800000, # January 12, 2013

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

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

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -29,6 +29,7 @@
 
 @import 'pages/angular',
         'pages/coffeescript',
+        'pages/d3',
         'pages/ember',
         'pages/jquery',
         'pages/git',

+ 1 - 0
assets/stylesheets/global/_icons.scss

@@ -45,3 +45,4 @@
 ._icon-git:before           { background-position: -1rem -6rem; }
 ._icon-redis:before         { background-position: -2rem -6rem; }
 ._icon-postgresql:before    { background-position: -3rem -6rem; }
+._icon-d3:before            { background-position: -4rem -6rem; }

+ 6 - 0
assets/stylesheets/pages/_d3.scss

@@ -0,0 +1,6 @@
+._d3 {
+  > h2 { @extend %block-heading; }
+  > h3, > h4 { font-size: 1rem; }
+  > h6 { @extend %block-label, %label-blue; }
+  code { @extend %label; }
+}

+ 42 - 0
lib/docs/filters/d3/clean_html.rb

@@ -0,0 +1,42 @@
+module Docs
+  class D3
+    class CleanHtmlFilter < Filter
+      def call
+        css('#gollum-footer', '.markdown-body > blockquote:first-child', '.anchor').remove
+
+        # Replace #head with <h1>
+        css('#head > h1').each do |node|
+          node.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('.markdown-body').children).remove
+        end
+
+        # Remove links inside <h2>
+        css('h2 > a').each do |node|
+          node.before(node.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'].sub(/\A.+#/, '')).sub('wiki-', '')
+          parent.css('a[name]').remove
+          node.remove
+        end
+
+        # Remove code highlighting
+        css('.highlight > pre').each do |node|
+          node.content = node.content
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 22 - 0
lib/docs/filters/d3/entries.rb

@@ -0,0 +1,22 @@
+module Docs
+  class D3
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        at_css('h1').content
+      end
+
+      def get_type
+        name
+      end
+
+      def additional_entries
+        css('h6[id]').inject [] do |entries, node|
+          name = node.content
+          name.sub! %r{\(.*\z}, ''
+          entries << [name, node['id']] unless name == entries.last.try(:first)
+          entries
+        end
+      end
+    end
+  end
+end

+ 43 - 0
lib/docs/scrapers/d3.rb

@@ -0,0 +1,43 @@
+module Docs
+  class D3 < UrlScraper
+    self.name = 'D3.js'
+    self.slug = 'd3'
+    self.type = 'd3'
+    self.version = '3.4.1'
+    self.base_url = 'https://github.com/mbostock/d3/wiki/'
+    self.root_path = 'API-Reference'
+
+    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\-/,
+      /\ATime\-/,
+      /\-Layout\z/,
+      /\AGeo\-/,
+      /\-Geom\z/,
+      /\-Behavior\z/]
+
+    options[:skip_patterns] = [/\//]
+
+    options[:attribution] = <<-HTML
+      &copy; 2014 Michael Bostock<br>
+      Licensed under the BSD License.
+    HTML
+  end
+end

BIN
public/icons/docs/d3/16.png


BIN
public/icons/docs/d3/16@2x.png


+ 1 - 0
public/icons/docs/d3/SOURCE

@@ -0,0 +1 @@
+http://d3js.org/