Add D3.js v4 documentation

pull/459/merge
Thibaut Courouble 9 years ago
parent 9f642fd0ad
commit dc4ccd9d6c

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

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

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

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

@ -2,35 +2,35 @@ module Docs
class D3 class D3
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
css('p:contains("This page describes the D3 3.x API.")').remove
# Remove links inside <h2> and add "id" attributes # 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.parent['id'] = (node['id'] || node['name']).remove('user-content-') if node['id'] || node['name']
node.before(node.children).remove node.before(node.children).remove
end 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 # Make headings for function definitions and add "id" attributes
css('p > a:first-child').each do |node| css('p > a:first-child').each do |node|
next unless node['name'] || node.content == '#' next unless node['name'] || node.content == '#'
parent = node.parent parent = node.parent
parent.name = 'h6' parent.name = 'h6'
parent['id'] = (node['name'] || node['href'].remove(/\A.+#/)).remove('user-content-') 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 node.remove
end 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 # Fix internal links
css('a[href]').each do |node| css('a[href]').each do |node|
node['href'] = node['href'].sub(/#user\-content\-(\w+?)\z/, '#\1').sub(/#wiki\-(\w+?)\z/, '#\1') node['href'] = node['href'].sub(/#user\-content\-(\w+?)\z/, '#\1').sub(/#wiki\-(\w+?)\z/, '#\1')
@ -39,6 +39,18 @@ module Docs
# Remove code highlighting # Remove code highlighting
css('.highlight > pre').each do |node| css('.highlight > pre').each do |node|
node.content = node.content 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 end
doc doc

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

@ -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

@ -3,45 +3,43 @@ module Docs
self.name = 'D3.js' self.name = 'D3.js'
self.slug = 'd3' self.slug = 'd3'
self.type = '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 = { self.links = {
home: 'http://d3js.org/', home: 'https://d3js.org/',
code: 'https://github.com/mbostock/d3' code: 'https://github.com/d3/d3'
} }
html_filters.push 'd3/clean_html', 'd3/entries' options[:container] = '.markdown-body'
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[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; 2010&ndash;2016 Michael Bostock<br> &copy; 2010&ndash;2016 Michael Bostock<br>
Licensed under the BSD License. Licensed under the BSD License.
HTML 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
end end

Loading…
Cancel
Save