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
173 'D3.js',173 'D3.js',
174 '2010-2016 Michael Bostock',174 '2010-2016 Michael Bostock',
175 'BSD',175 'BSD',
176 'https://raw.githubusercontent.com/mbostock/d3/master/LICENSE'176 'https://raw.githubusercontent.com/d3/d3/master/LICENSE'
177 ], [177 ], [
178 'Django',178 'Django',
179 'Django Software Foundation and individual contributors',179 'Django Software Foundation and individual contributors',
assets/javascripts/views/pages/d3.coffee+0−6
@@ -1,6 +0,0 @@
1#= require views/pages/base
2
3class 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
13app.views.CakephpPage =13app.views.CakephpPage =
14app.views.ChaiPage =14app.views.ChaiPage =
15app.views.CrystalPage =15app.views.CrystalPage =
16app.views.D3Page =
16app.views.DrupalPage =17app.views.DrupalPage =
17app.views.ElixirPage =18app.views.ElixirPage =
18app.views.EmberPage =19app.views.EmberPage =
assets/stylesheets/pages/_d3.scss+9−1
@@ -1,6 +1,14 @@
1._d3 {1._d3 {
2 > h2 { @extend %block-heading; }2 > h2 { @extend %block-heading; }
3 > h3, > h4 { font-size: 1rem; }3 > h3 { @extend %block-label; }
4 > h4 { font-size: 1rem; }
4 > h6 { @extend %block-label, %label-blue; }5 > h6 { @extend %block-label, %label-blue; }
6
7 > h6 > .source {
8 float: right;
9 font-weight: normal;
10 }
11
5 code { @extend %label; }12 code { @extend %label; }
13 blockquote { @extend %note, %note-blue; }
6}14}
lib/docs/filters/d3/clean_html.rb+27−15
@@ -2,35 +2,35 @@ module Docs · 1 unmodified line
2 class D32 class D3
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 css('p:contains("This page describes the D3 3.x API.")').remove
6
5 # Remove links inside <h2> and add "id" attributes7 # Remove links inside <h2> and add "id" attributes
6 css('h2 > a').each do |node|8 css('a.anchor').each do |node|
7 node.parent['id'] = (node['id'] || node['name']).remove('user-content-') if node['id'] || node['name']9 node.parent['id'] = (node['id'] || node['name']).remove('user-content-') if node['id'] || node['name']
8 node.before(node.children).remove10 node.before(node.children).remove
9 end11 end
10 12
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
24 # Make headings for function definitions and add "id" attributes13 # Make headings for function definitions and add "id" attributes
25 css('p > a:first-child').each do |node|14 css('p > a:first-child').each do |node|
26 next unless node['name'] || node.content == '#'15 next unless node['name'] || node.content == '#'
27 parent = node.parent16 parent = node.parent
28 parent.name = 'h6'17 parent.name = 'h6'
29 parent['id'] = (node['name'] || node['href'].remove(/\A.+#/)).remove('user-content-')18 parent['id'] = (node['name'] || node['href'].remove(/\A.+#/)).remove('user-content-')
30 parent.css('a[name]').remove19 parent.css('a[name], a:contains("#")').remove
31 node.remove20 node.remove
32 end21 end
33 22
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
34 # Fix internal links34 # Fix internal links
35 css('a[href]').each do |node|35 css('a[href]').each do |node|
36 node['href'] = node['href'].sub(/#user\-content\-(\w+?)\z/, '#\1').sub(/#wiki\-(\w+?)\z/, '#\1')36 node['href'] = node['href'].sub(/#user\-content\-(\w+?)\z/, '#\1').sub(/#wiki\-(\w+?)\z/, '#\1')
@@ -39,6 +39,18 @@ module Docs · 2 unmodified lines
39 # Remove code highlighting39 # Remove code highlighting
40 css('.highlight > pre').each do |node|40 css('.highlight > pre').each do |node|
41 node.content = node.content41 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
42 end54 end
43 55
44 doc56 doc
lib/docs/filters/d3/entries_v3.rbrenamed from lib/docs/filters/d3/entries.rb+5−6
@@ -1,21 +1,20 @@
1module Docs1module Docs
2 class D32 class D3
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesV3Filter < Docs::EntriesFilter
4 def get_name4 def get_name
5 at_css('h1').content5 File.basename(slug, '.md').gsub('-', ' ')
6 end6 end
7 7
8 def get_type8 def get_type
9 name9 at_css('h6[id]') ? name : 'D3'
10 end10 end
11 11
12 def additional_entries12 def additional_entries
13 css('h6[id]').inject [] do |entries, node|13 css('h6[id]').each_with_object [] do |node, entries|
14 name = node.content.strip14 name = node.content.strip
15 name.remove! %r{\(.*\z}15 name.sub! %r{\(.*\z}, '()'
16 name.sub! %r{\A(svg:\w+)\s+.+}, '\1'16 name.sub! %r{\A(svg:\w+)\s+.+}, '\1'
17 entries << [name, node['id']] unless name == entries.last.try(:first)17 entries << [name, node['id']] unless name == entries.last.try(:first)
18 entries
19 end18 end
20 end19 end
21 end20 end
lib/docs/filters/d3/entries_v4.rb+33−0
@@ -0,0 +1,33 @@
1module 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
33end
lib/docs/scrapers/d3.rb+30−32
@@ -3,45 +3,43 @@ module Docs · 2 unmodified lines
3 self.name = 'D3.js'3 self.name = 'D3.js'
4 self.slug = 'd3'4 self.slug = 'd3'
5 self.type = 'd3'5 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'
9 self.links = {6 self.links = {
10 home: 'http://d3js.org/',7 home: 'https://d3js.org/',
11 code: 'https://github.com/mbostock/d3'8 code: 'https://github.com/d3/d3'
12 }9 }
13 10
14 html_filters.push 'd3/clean_html', 'd3/entries'11 options[:container] = '.markdown-body'
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] = [/\//]
41 12
42 options[:attribution] = <<-HTML13 options[:attribution] = <<-HTML
43 &copy; 2010&ndash;2016 Michael Bostock<br>14 &copy; 2010&ndash;2016 Michael Bostock<br>
44 Licensed under the BSD License.15 Licensed under the BSD License.
45 HTML16 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
46 end44 end
47end45end