History

Add D3.js v4 documentation

Thibaut Courouble committed 10 years ago

Commit dc4ccd91 parent 9f642fd8 files · +106 −61Browse files

Unified · Split

8 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +1 −1
  2. assets/javascripts/views/pages/d3.coffee +0 −6
  3. assets/javascripts/views/pages/simple.coffee +1 −0
  4. assets/stylesheets/pages/_d3.scss +9 −1
  5. lib/docs/filters/d3/clean_html.rb +27 −15
  6. lib/docs/filters/d3/entries_v3.rb +5 −6
  7. lib/docs/filters/d3/entries_v4.rb +33 −0
  8. lib/docs/scrapers/d3.rb +30 −32
assets/javascripts/templates/pages/about_tmpl.coffee+1−1
@@ -173,7 +173,7 @@ credits = [ · 172 unmodified lines
173173 'D3.js',
174174 '2010-2016 Michael Bostock',
175175 'BSD',
176− 'https://raw.githubusercontent.com/mbostock/d3/master/LICENSE'
176+ 'https://raw.githubusercontent.com/d3/d3/master/LICENSE'
177177 ], [
178178 'Django',
179179 'Django Software Foundation and individual contributors',
assets/javascripts/views/pages/d3.coffee+0−6
@@ -1,6 +0,0 @@
1−#= require views/pages/base
2−
3−class app.views.D3Page extends app.views.BasePage
4− prepare: ->
5− @highlightCode @findAll('.highlight > pre'), 'javascript'
6− return
assets/javascripts/views/pages/simple.coffee+1−0
@@ -13,6 +13,7 @@ app.views.CPage = · 12 unmodified lines
1313 app.views.CakephpPage =
1414 app.views.ChaiPage =
1515 app.views.CrystalPage =
16+app.views.D3Page =
1617 app.views.DrupalPage =
1718 app.views.ElixirPage =
1819 app.views.EmberPage =
assets/stylesheets/pages/_d3.scss+9−1
@@ -1,6 +1,14 @@
11 ._d3 {
22 > h2 { @extend %block-heading; }
3− > h3, > h4 { font-size: 1rem; }
3+ > h3 { @extend %block-label; }
4+ > h4 { font-size: 1rem; }
45 > h6 { @extend %block-label, %label-blue; }
6+
7+ > h6 > .source {
8+ float: right;
9+ font-weight: normal;
10+ }
11+
512 code { @extend %label; }
13+ blockquote { @extend %note, %note-blue; }
614 }
lib/docs/filters/d3/clean_html.rb+27−15
@@ -2,35 +2,35 @@ module Docs · 1 unmodified line
22 class D3
33 class CleanHtmlFilter < Filter
44 def call
5+ css('p:contains("This page describes the D3 3.x API.")').remove
6+
57 # Remove links inside <h2> and add "id" attributes
6− css('h2 > a').each do |node|
8+ css('a.anchor').each do |node|
79 node.parent['id'] = (node['id'] || node['name']).remove('user-content-') if node['id'] || node['name']
810 node.before(node.children).remove
911 end
1012
11− css('.markdown-body > blockquote:first-child', '.anchor').remove
12−
13− # Replace .gh-header with <h1>
14− css('.gh-header-title').each do |node|
15− node.parent.parent.before(node).remove
16− node.content = 'D3.js' if root_page?
17− end
18−
19− # Move content to the root-level
20− css('#wiki-content').each do |node|
21− node.before(node.at_css('#wiki-body .markdown-body').children).remove
22− end
23−
2413 # Make headings for function definitions and add "id" attributes
2514 css('p > a:first-child').each do |node|
2615 next unless node['name'] || node.content == '#'
2716 parent = node.parent
2817 parent.name = 'h6'
2918 parent['id'] = (node['name'] || node['href'].remove(/\A.+#/)).remove('user-content-')
30− parent.css('a[name]').remove
19+ parent.css('a[name], a:contains("#")').remove
3120 node.remove
3221 end
3322
23+ css('h4').each { |node| node.name = 'h3' } if root_page?
24+
25+ css('a > img').each do |node|
26+ node.parent.before(node).remove
27+ end
28+
29+ css('h6 a[title="Source"]').each do |node|
30+ node.content = 'Source'
31+ node['class'] = 'source'
32+ end
33+
3434 # Fix internal links
3535 css('a[href]').each do |node|
3636 node['href'] = node['href'].sub(/#user\-content\-(\w+?)\z/, '#\1').sub(/#wiki\-(\w+?)\z/, '#\1')
@@ -39,6 +39,18 @@ module Docs · 2 unmodified lines
3939 # Remove code highlighting
4040 css('.highlight > pre').each do |node|
4141 node.content = node.content
42+ node['data-language'] = if node.parent['class'].include?('html')
43+ 'markup'
44+ elsif node.parent['class'].include?('css')
45+ 'css'
46+ else
47+ 'javascript'
48+ end
49+ node.parent.before(node).remove
50+ end
51+
52+ css('pre > code').each do |node|
53+ node.before(node.children).remove
4254 end
4355
4456 doc
lib/docs/filters/d3/entries_v3.rbrenamed from lib/docs/filters/d3/entries.rb+5−6
@@ -1,21 +1,20 @@
11 module Docs
22 class D3
3− class EntriesFilter < Docs::EntriesFilter
3+ class EntriesV3Filter < Docs::EntriesFilter
44 def get_name
5− at_css('h1').content
5+ File.basename(slug, '.md').gsub('-', ' ')
66 end
77
88 def get_type
9− name
9+ at_css('h6[id]') ? name : 'D3'
1010 end
1111
1212 def additional_entries
13− css('h6[id]').inject [] do |entries, node|
13+ css('h6[id]').each_with_object [] do |node, entries|
1414 name = node.content.strip
15− name.remove! %r{\(.*\z}
15+ name.sub! %r{\(.*\z}, '()'
1616 name.sub! %r{\A(svg:\w+)\s+.+}, '\1'
1717 entries << [name, node['id']] unless name == entries.last.try(:first)
18− entries
1918 end
2019 end
2120 end
lib/docs/filters/d3/entries_v4.rb+33−0
@@ -0,0 +1,33 @@
1+module Docs
2+ class D3
3+ class EntriesV4Filter < Docs::EntriesFilter
4+ def get_name
5+ name = at_css('h1').content
6+ name.remove! 'd3-'
7+ name
8+ end
9+
10+ def get_type
11+ return 'D3' unless at_css('h6[id]')
12+ type = name.titleize
13+ type.sub! 'Hsv', 'HSV'
14+ type.sub! 'Dsv', 'DSV'
15+ type
16+ end
17+
18+ def additional_entries
19+ css('h6[id]').each_with_object [] do |node, entries|
20+ name = node.content.strip
21+ name.remove! 'Source'
22+ name.remove! '<>'
23+ name.gsub! %r{\(.+?\)\)?}, '()'
24+ name.sub! %r{\A(svg:\w+)\s+.+}, '\1'
25+ name.split(/\s+/).each do |n|
26+ next if n.blank?
27+ entries << [n, node['id']] unless n == entries.last.try(:first)
28+ end
29+ end
30+ end
31+ end
32+ end
33+end
lib/docs/scrapers/d3.rb+30−32
@@ -3,45 +3,43 @@ module Docs · 2 unmodified lines
33 self.name = 'D3.js'
44 self.slug = 'd3'
55 self.type = 'd3'
6− self.release = '3.5.16'
7− self.base_url = 'https://github.com/mbostock/d3/wiki/'
8− self.root_path = 'API-Reference'
96 self.links = {
10− home: 'http://d3js.org/',
11− code: 'https://github.com/mbostock/d3'
7+ home: 'https://d3js.org/',
8+ code: 'https://github.com/d3/d3'
129 }
1310
14− html_filters.push 'd3/clean_html', 'd3/entries'
15−
16− options[:container] = '#wiki-wrapper'
17−
18− options[:only] = %w(
19− Selections
20− Transitions
21− Arrays
22− Math
23− Requests
24− Formatting
25− CSV
26− Localization
27− Colors
28− Namespaces
29− Internals)
30−
31− options[:only_patterns] = [
32− /\-Scales\z/,
33− /\ASVG\-\w/,
34− /\ATime\-/,
35− /\-Layout\z/,
36− /\AGeo\-/,
37− /\-Geom\z/,
38− /\-Behavior\z/]
39−
40− options[:skip_patterns] = [/\//]
11+ options[:container] = '.markdown-body'
4112
4213 options[:attribution] = <<-HTML
4314 &copy; 2010&ndash;2016 Michael Bostock<br>
4415 Licensed under the BSD License.
4516 HTML
17+
18+ version '4' do
19+ self.release = '4.2.2'
20+ self.base_url = 'https://github.com/d3/'
21+ self.root_path = 'd3/blob/master/API.md'
22+
23+ html_filters.push 'd3/clean_html', 'd3/entries_v4'
24+
25+ options[:only_patterns] = [/\Ad3[\-\w]+\z/, /\Ad3\/blob\/master\/changes\.md\z/i]
26+ options[:skip_patterns] = [/3\.x-api-reference/]
27+
28+ options[:fix_urls] = ->(url) do
29+ url.sub! %r{/blob/master/readme.md}i, ''
30+ url
31+ end
32+ end
33+
34+ version '3' do
35+ self.release = '3.5.17'
36+ self.base_url = 'https://github.com/d3/d3-3.x-api-reference/blob/master/'
37+ self.root_path = 'API-Reference.md'
38+
39+ html_filters.push 'd3/clean_html', 'd3/entries_v3', 'title'
40+
41+ options[:root_title] = 'D3.js'
42+ options[:only_patterns] = [/\.md\z/]
43+ end
4644 end
4745 end