소스 검색

Update Elixir documentation (1.3.3)

Thibaut Courouble 9 년 전
부모
커밋
6fdf81e649
4개의 변경된 파일59개의 추가작업 그리고 16개의 파일을 삭제
  1. 1 1
      lib/docs/core/scrapers/url_scraper.rb
  2. 23 2
      lib/docs/filters/elixir/clean_html.rb
  3. 24 10
      lib/docs/filters/elixir/entries.rb
  4. 11 3
      lib/docs/scrapers/elixir.rb

+ 1 - 1
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

+ 23 - 2
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

+ 24 - 10
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']

+ 11 - 3
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
       &copy; 2012&ndash;2016 Plataformatec<br>
       Licensed under the Apache License, Version 2.0.
     HTML
+
+    def initial_urls
+      super.tap { |urls| urls.last << 'introduction.html' }
+    end
   end
 end