From 6fdf81e649323b4b6ad6b9ad08fbb1cf824c438b Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sat, 1 Oct 2016 09:47:30 -0400 Subject: [PATCH] Update Elixir documentation (1.3.3) --- lib/docs/core/scrapers/url_scraper.rb | 2 +- lib/docs/filters/elixir/clean_html.rb | 25 ++++++++++++++++++-- lib/docs/filters/elixir/entries.rb | 34 +++++++++++++++++++-------- lib/docs/scrapers/elixir.rb | 14 ++++++++--- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/lib/docs/core/scrapers/url_scraper.rb b/lib/docs/core/scrapers/url_scraper.rb index d5082478..3887cc14 100644 --- a/lib/docs/core/scrapers/url_scraper.rb +++ b/lib/docs/core/scrapers/url_scraper.rb @@ -65,7 +65,7 @@ module Docs end def initial_urls - super + self.class.base_urls[1..-1] + super + self.class.base_urls[1..-1].deep_dup end def base_urls diff --git a/lib/docs/filters/elixir/clean_html.rb b/lib/docs/filters/elixir/clean_html.rb index 04055a67..25ba719e 100644 --- a/lib/docs/filters/elixir/clean_html.rb +++ b/lib/docs/filters/elixir/clean_html.rb @@ -2,6 +2,29 @@ module Docs class Elixir class CleanHtmlFilter < Filter def call + if current_url.path.start_with?('/getting-started') + guide + else + api + end + doc + end + + def guide + @doc = at_css('#content article') + + css('pre > code').each do |node| + node.parent.content = node.content + end + + css('div > pre.highlight').each do |node| + node.content = node.content + node['data-language'] = node.parent['class'][/language-(\w+)/, 1] + node.parent.before(node).remove + end + end + + def api css('footer', '.view-source', 'h1 .visible-xs').remove css('section section.docstring h2').each do |node| @@ -33,8 +56,6 @@ module Docs css('pre').each do |node| node['data-language'] = 'elixir' end - - doc end end end diff --git a/lib/docs/filters/elixir/entries.rb b/lib/docs/filters/elixir/entries.rb index f64f387f..babf2a99 100644 --- a/lib/docs/filters/elixir/entries.rb +++ b/lib/docs/filters/elixir/entries.rb @@ -2,26 +2,40 @@ module Docs class Elixir class EntriesFilter < Docs::EntriesFilter def get_name - at_css('h1').content.split(' ').first.strip + if current_url.path.start_with?('/getting-started') + at_css('h1').content.strip.remove(/\.\z/) + else + at_css('h1').content.split(' ').first.strip + end end def get_type - case at_css('h1 small').try(:content) - when 'exception' - 'Exceptions' - when 'protocol' - 'Protocols' + if current_url.path.start_with?('/getting-started') + if subpath.start_with?('mix-otp') + 'Guide: Mix & OTP' + elsif subpath.start_with?('meta') + 'Guide: Metaprogramming' + else + 'Guide' + end else - if name.start_with?('Phoenix') - name.split('.')[0..2].join('.') + case at_css('h1 small').try(:content) + when 'exception' + 'Exceptions' + when 'protocol' + 'Protocols' else - name.split('.').first + if name.start_with?('Phoenix') + name.split('.')[0..2].join('.') + else + name.split('.').first + end end end end def additional_entries - return [] if type == 'Exceptions' + return [] if type == 'Exceptions' || type == 'Guide' css('.detail-header .signature').map do |node| id = node.parent['id'] diff --git a/lib/docs/scrapers/elixir.rb b/lib/docs/scrapers/elixir.rb index 0d24d02e..8c25954a 100644 --- a/lib/docs/scrapers/elixir.rb +++ b/lib/docs/scrapers/elixir.rb @@ -1,9 +1,11 @@ module Docs class Elixir < UrlScraper + include MultipleBaseUrls + self.name = 'Elixir' self.type = 'elixir' - self.release = '1.3.2' - self.base_url = 'http://elixir-lang.org/docs/stable/' + self.release = '1.3.3' + self.base_urls = ['http://elixir-lang.org/docs/stable/', 'http://elixir-lang.org/getting-started/'] self.root_path = 'elixir/api-reference.html' self.initial_paths = %w( eex/EEx.html @@ -19,7 +21,9 @@ module Docs html_filters.push 'elixir/clean_html', 'elixir/entries', 'title' - options[:container] = "#content" + options[:container] = ->(filter) { + filter.current_url.path.start_with?('/getting-started') ? '#main' : '#content' + } options[:title] = false options[:root_title] = 'Elixir' @@ -27,5 +31,9 @@ module Docs © 2012–2016 Plataformatec
Licensed under the Apache License, Version 2.0. HTML + + def initial_urls + super.tap { |urls| urls.last << 'introduction.html' } + end end end