diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 5b85e7d6..3552180f 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/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', diff --git a/assets/javascripts/views/pages/d3.coffee b/assets/javascripts/views/pages/d3.coffee deleted file mode 100644 index 2247a6cb..00000000 --- a/assets/javascripts/views/pages/d3.coffee +++ /dev/null @@ -1,6 +0,0 @@ -#= require views/pages/base - -class app.views.D3Page extends app.views.BasePage - prepare: -> - @highlightCode @findAll('.highlight > pre'), 'javascript' - return diff --git a/assets/javascripts/views/pages/simple.coffee b/assets/javascripts/views/pages/simple.coffee index e24bd4a9..b25e30c5 100644 --- a/assets/javascripts/views/pages/simple.coffee +++ b/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 = diff --git a/assets/stylesheets/pages/_d3.scss b/assets/stylesheets/pages/_d3.scss index 0d34d1d9..8357c721 100644 --- a/assets/stylesheets/pages/_d3.scss +++ b/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; } } diff --git a/lib/docs/filters/d3/clean_html.rb b/lib/docs/filters/d3/clean_html.rb index a690bdd5..afba6cb3 100644 --- a/lib/docs/filters/d3/clean_html.rb +++ b/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

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

- 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 diff --git a/lib/docs/filters/d3/entries.rb b/lib/docs/filters/d3/entries_v3.rb similarity index 57% rename from lib/docs/filters/d3/entries.rb rename to lib/docs/filters/d3/entries_v3.rb index 7f19c97d..9afa05ea 100644 --- a/lib/docs/filters/d3/entries.rb +++ b/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 diff --git a/lib/docs/filters/d3/entries_v4.rb b/lib/docs/filters/d3/entries_v4.rb new file mode 100644 index 00000000..93ab739f --- /dev/null +++ b/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 diff --git a/lib/docs/scrapers/d3.rb b/lib/docs/scrapers/d3.rb index dd0031d6..37f229f0 100644 --- a/lib/docs/scrapers/d3.rb +++ b/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 © 2010–2016 Michael Bostock
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