浏览代码

Finish Elixir scraper

Thibaut 10 年之前
父节点
当前提交
4ce964c134

二进制
assets/images/icons.png


二进制
assets/images/icons@2x.png


+ 3 - 0
assets/javascripts/news.json

@@ -1,5 +1,8 @@
 [
   [
+    "2015-11-08",
+    "New documentation: <a href=\"/elixir/\">Elixir</a>"
+  ], [
     "2015-10-18",
     "Added a \"Copy to clipboard\" button inside each code block."
   ], [

+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -144,6 +144,11 @@ credits = [
     '2015 Yehuda Katz, Tom Dale and Ember.js contributors',
     'MIT',
     'https://raw.github.com/emberjs/ember.js/master/LICENSE'
+  ], [
+    'Elixir',
+    '2012 Plataformatec',
+    'Apache',
+    'https://raw.githubusercontent.com/elixir-lang/elixir/master/LICENSE'
   ], [
     'Express',
     '2009-2015 TJ Holowaychuk',

+ 1 - 1
assets/javascripts/views/pages/elixir.coffee

@@ -2,5 +2,5 @@
 
 class app.views.ElixirPage extends app.views.BasePage
   prepare: ->
-    @highlightCode @findAll('pre.elixir'), 'elixir'
+    @highlightCode @findAllByTag('pre'), 'elixir'
     return

+ 1 - 0
assets/stylesheets/global/_icons.scss

@@ -116,3 +116,4 @@
 ._icon-phalcon:before       { background-position: -1rem -9rem; }
 %icon-clipboard             { background-position: -2rem -9rem; }
 %icon-clipboard-white       { background-position: -3rem -9rem; }
+._icon-elixir:before        { background-position: -4rem -9rem; @extend %darkIconFix !optional; }

+ 4 - 1
assets/stylesheets/pages/_elixir.scss

@@ -1,4 +1,7 @@
 ._elixir {
   @extend %simple;
-  h3 { @extend %block-label; }
+
+  .type-detail { margin-bottom: 2em; }
+  .type-detail pre { margin-left: -1rem; }
+  ._mobile & .type-detail pre { margin-left: 0; }
 }

+ 17 - 30
lib/docs/filters/elixir/clean_html.rb

@@ -2,45 +2,32 @@ module Docs
   class Elixir
     class CleanHtmlFilter < Filter
       def call
+        at_css('footer', '.view-source').remove
 
-        # Strip h1 content
-        css('h1').each do |node|
-          node.content = node.content.strip
-        end
-
-        # Make subtitles smaller
-        css('h2').each do |node|
+        css('section section.docstring h2').each do |node|
           node.name = 'h4'
         end
 
-        # Remove footer
-        at_css('footer').remove
-
-        # Remove behaviour after module name
-        css('h1').each do |node|
-          if !(node.has_attribute?('id'))
-            node.content = node.content.split(" ")[0]
-          end
-        end
-
-        # Remove links from summary headings
-        css('.summary > h4 > a').each do |node|
-          node.delete('href')
+        css('h1 .hover-link', '.detail-link').each do |node|
+          node.parent['id'] = node['href'].remove('#')
+          node.remove
         end
 
-        # Add elixir class to each pre for syntax highlighting
-        css('pre').each do |node|
-          node['class'] = "elixir"
+        css('.details-list').each do |list|
+          type = list['id'].remove(/s\z/)
+          list.css('.detail-header').each do |node|
+            node.name = 'h3'
+            node['class'] += " #{type}"
+          end
         end
 
-        # Rewrite .detail -> .method-detail
-        css('.detail').each do |node|
-          node['class'] = "method-detail"
-        end
+        css('.summary h2').each { |node| node.parent.before(node) }
+        css('.summary').each { |node| node.name = 'dl' }
+        css('.summary-signature').each { |node| node.name = 'dt' }
+        css('.summary-synopsis').each { |node| node.name = 'dd' }
 
-        # Change .detail-header to h3
-        css('.detail-header .signature').each do |node|
-          node.name = 'h3'
+        css('section', 'div:not(.type-detail)', 'h2 a').each do |node|
+          node.before(node.children).remove
         end
 
         doc

+ 23 - 18
lib/docs/filters/elixir/entries.rb

@@ -2,33 +2,38 @@ module Docs
   class Elixir
     class EntriesFilter < Docs::EntriesFilter
       def get_name
-        at_css('h1').content.gsub('behaviour', ' ').strip
+        at_css('h1').content.split(' ').first.strip
       end
 
       def get_type
-        return nil if (slug.split("#")[1] == "functions")
-        slug.split("#")[1]
+        case at_css('h1 small').try(:content)
+        when 'exception'
+          'Exceptions'
+        when 'protocol'
+          'Protocols'
+        else
+          name.split('.').first
+        end
       end
 
       def additional_entries
-        return [] if root_page?
-       
-        entries = [] 
+        return [] if type == 'Exceptions'
 
-        # Add itself (moduledoc) to entries
-        klass = at_css('h1').content.strip.split(" ")[0]
-        entries << [klass, klass, name]
+        css('.detail-header .signature').map do |node|
+          id = node.parent['id']
+          name = node.content.strip
+          name.remove! %r{\(.*\)}
+          name.remove! 'left '
+          name.remove! ' right'
+          name.sub! 'sigil_', '~'
 
-        # Add functions
-        css('.summary-functions .summary-signature a').each do |node|
-          entries << [(name + node['href']), node['href'][1..-1], name]
-        end
+          unless node.parent['class'].end_with?('macro') || self.name.start_with?('Kernel')
+            name.prepend "#{self.name}."
+            name << " (#{id.split('/').last})"
+          end
 
-        return entries
-      end
-
-      def include_default_entry?
-        !initial_page?
+          [name, id]
+        end
       end
     end
   end

+ 11 - 16
lib/docs/scrapers/elixir.rb

@@ -3,34 +3,29 @@ module Docs
     self.name = 'Elixir'
     self.type = 'elixir'
     self.version = '1.1.1'
-    self.base_url = 'http://elixir-lang.org/docs/stable/elixir/'
-    self.root_path = 'extra-api-reference.html'
+    self.base_url = 'http://elixir-lang.org/docs/stable/'
+    self.root_path = 'elixir/extra-api-reference.html'
+    self.initial_paths = %w(
+      eex/EEx.html
+      ex_unit/ExUnit.html
+      iex/IEx.html
+      logger/Logger.html
+      mix/Mix.html
+    )
     self.links = {
-      home: 'https://elixir-lang.org/',
+      home: 'http://elixir-lang.org/',
       code: 'https://github.com/elixir-lang/elixir'
     }
 
     html_filters.push 'elixir/clean_html', 'elixir/entries', 'title'
 
-    # Skip exceptions
-    options[:skip_patterns] = [/Error/]
-    # Skip protocols
-    options[:skip] = %w(
-      Collectable.html
-      Enumerable.html
-      Inspect.html
-      List.Chars.html
-      String.Chars.html
-    )
-
-    options[:follow_links] = ->(filter) { filter.root_page? }
     options[:container] = "#content"
     options[:title] = false
     options[:root_title] = 'Elixir'
 
     options[:attribution] = <<-HTML
       &copy; 2012 Plataformatec<br>
-      Licensed under the Apache License, Version 2.0
+      Licensed under the Apache License, Version 2.0.
     HTML
   end
 end

二进制
public/icons/docs/elixir/16.png


二进制
public/icons/docs/elixir/16@2x.png