From f54d2b428cca43b2a061b8f85042f8c44aa98a85 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 25 Jun 2017 10:33:01 -0400 Subject: [PATCH] Update Julia documentation (0.6, 0.5) --- assets/stylesheets/application-dark.css.scss | 1 + assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_julia.scss | 7 ++++ lib/docs/filters/julia/clean_html.rb | 21 +++++++++++- lib/docs/filters/julia/clean_html_sphinx.rb | 11 +++++++ lib/docs/filters/julia/entries.rb | 20 +++++------- lib/docs/filters/julia/entries_sphinx.rb | 34 ++++++++++++++++++++ lib/docs/scrapers/julia.rb | 23 ++++++++++--- 8 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 assets/stylesheets/pages/_julia.scss create mode 100644 lib/docs/filters/julia/clean_html_sphinx.rb create mode 100644 lib/docs/filters/julia/entries_sphinx.rb diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index cc7a44c6..80d4ce75 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -56,6 +56,7 @@ 'pages/go', 'pages/haskell', 'pages/jquery', + 'pages/julia', 'pages/knockout', 'pages/kotlin', 'pages/laravel', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 409a62ba..ea8e5772 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -56,6 +56,7 @@ 'pages/go', 'pages/haskell', 'pages/jquery', + 'pages/julia', 'pages/knockout', 'pages/kotlin', 'pages/laravel', diff --git a/assets/stylesheets/pages/_julia.scss b/assets/stylesheets/pages/_julia.scss new file mode 100644 index 00000000..4887da64 --- /dev/null +++ b/assets/stylesheets/pages/_julia.scss @@ -0,0 +1,7 @@ +._julia { + @extend %simple; + + .footnote { @extend %note; } + .note { @extend %note; } + .docstring-category { float: right; } +} diff --git a/lib/docs/filters/julia/clean_html.rb b/lib/docs/filters/julia/clean_html.rb index 2bf83f36..9c1096dc 100644 --- a/lib/docs/filters/julia/clean_html.rb +++ b/lib/docs/filters/julia/clean_html.rb @@ -2,7 +2,26 @@ module Docs class Julia class CleanHtmlFilter < Filter def call - @doc = at_css('.document .section') + css('> header', '> footer').remove + + css('.docstring', 'div:not([class])').each do |node| + node.before(node.children).remove + end + + css('.docstring-header').each do |node| + node.name = 'h3' + node.children.each { |child| child.remove if child.text? } + node.remove_attribute('class') + end + + css('a.docstring-binding[id]', 'a.nav-anchor').each do |node| + node.parent['id'] = node['id'] + node.before(node.children).remove + end + + css('pre').each do |node| + node.content = node.content + end doc end diff --git a/lib/docs/filters/julia/clean_html_sphinx.rb b/lib/docs/filters/julia/clean_html_sphinx.rb new file mode 100644 index 00000000..e493384f --- /dev/null +++ b/lib/docs/filters/julia/clean_html_sphinx.rb @@ -0,0 +1,11 @@ +module Docs + class Julia + class CleanHtmlSphinxFilter < Filter + def call + @doc = at_css('.document .section') + + doc + end + end + end +end diff --git a/lib/docs/filters/julia/entries.rb b/lib/docs/filters/julia/entries.rb index 2a24e916..46be86c9 100644 --- a/lib/docs/filters/julia/entries.rb +++ b/lib/docs/filters/julia/entries.rb @@ -2,9 +2,7 @@ module Docs class Julia class EntriesFilter < Docs::EntriesFilter def get_name - name = at_css('.document h1').content - name.remove! "\u{00B6}" - name + at_css('h1').content end def get_type @@ -17,17 +15,15 @@ module Docs def additional_entries return [] unless slug.start_with?('stdlib') - entries = [] - css('.function dt[id]').each do |node| - entries << [node['id'].remove('Base.') + '()', node['id']] + css('.docstring-binding[id]').map do |node| + name = node.content + name.gsub! '.:', '.' + name.remove! 'Base.' + category = node.parent.at_css('.docstring-category').content + name << '()' if category == 'Function' || category == 'Method' + [name, node['id']] end - - css('.data dt[id]').each do |node| - entries << [node['id'].remove('Base.'), node['id']] - end - - entries end end end diff --git a/lib/docs/filters/julia/entries_sphinx.rb b/lib/docs/filters/julia/entries_sphinx.rb new file mode 100644 index 00000000..61c652a1 --- /dev/null +++ b/lib/docs/filters/julia/entries_sphinx.rb @@ -0,0 +1,34 @@ +module Docs + class Julia + class EntriesSphinxFilter < Docs::EntriesFilter + def get_name + name = at_css('.document h1').content + name.remove! "\u{00B6}" + name + end + + def get_type + if slug.start_with?('manual') + 'Manual' + else + name + end + end + + def additional_entries + return [] unless slug.start_with?('stdlib') + entries = [] + + css('.function dt[id]').each do |node| + entries << [node['id'].remove('Base.') + '()', node['id']] + end + + css('.data dt[id]').each do |node| + entries << [node['id'].remove('Base.'), node['id']] + end + + entries + end + end + end +end diff --git a/lib/docs/scrapers/julia.rb b/lib/docs/scrapers/julia.rb index f9dc559d..d1c798f8 100644 --- a/lib/docs/scrapers/julia.rb +++ b/lib/docs/scrapers/julia.rb @@ -1,20 +1,33 @@ module Docs class Julia < UrlScraper - self.type = 'sphinx_simple' - self.release = '0.5.2' - self.base_url = 'https://docs.julialang.org/en/stable/' self.links = { home: 'https://julialang.org/', code: 'https://github.com/JuliaLang/julia' } - html_filters.push 'julia/entries', 'julia/clean_html', 'sphinx/clean_html' - options[:only_patterns] = [/\Amanual\//, /\Astdlib\//] options[:attribution] = <<-HTML © 2009–2016 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and other contributors
Licensed under the MIT License. HTML + + version '0.6' do + self.release = '0.6.0' + self.base_url = 'https://docs.julialang.org/en/release-0.6/' + self.type = 'julia' + + html_filters.push 'julia/entries', 'julia/clean_html' + + options[:container] = '#docs' + end + + version '0.5' do + self.release = '0.5.2' + self.base_url = 'https://docs.julialang.org/en/release-0.5/' + self.type = 'sphinx_simple' + + html_filters.push 'julia/entries_sphinx', 'julia/clean_html_sphinx', 'sphinx/clean_html' + end end end