Browse Source

Finish Vagrant scraper

Thibaut 10 years ago
parent
commit
de1c879730

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 1 - 1
assets/javascripts/news.json

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

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

@@ -379,6 +379,11 @@ credits = [
     '2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors',
     'MIT',
     'https://raw.github.com/jashkenas/underscore/master/LICENSE'
+  ], [
+    'Vagrant',
+    '2010-2015 Mitchell Hashimoto',
+    'MIT',
+    'https://raw.githubusercontent.com/mitchellh/vagrant/master/LICENSE'
   ], [
     'Vue.js',
     '2013-2015 Evan You, Vue.js contributors',

+ 5 - 0
assets/javascripts/views/pages/vagrant.coffee

@@ -0,0 +1,5 @@
+#= require views/pages/base
+
+class app.views.VagrantPage extends app.views.BasePage
+  prepare: ->
+    @highlightCode @findAll('pre.ruby'), 'ruby'

+ 1 - 0
assets/stylesheets/application-dark.css.scss

@@ -72,6 +72,7 @@
         'pages/socketio',
         'pages/sphinx',
         'pages/underscore',
+        'pages/vagrant',
         'pages/vue',
         'pages/yard',
         'pages/yii';

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -72,6 +72,7 @@
         'pages/socketio',
         'pages/sphinx',
         'pages/underscore',
+        'pages/vagrant',
         'pages/vue',
         'pages/yard',
         'pages/yii';

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

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

+ 9 - 0
assets/stylesheets/pages/_vagrant.scss

@@ -0,0 +1,9 @@
+._vagrant {
+  @extend %simple;
+
+  .alert { @extend %note; }
+  .prev-button { float: left; }
+  .prev-button:before { content: '\2190  '; }
+  .next-button { float: right; }
+  .next-button:after { content: ' \2192'; }
+}

+ 4 - 6
lib/docs/filters/vagrant/clean_html.rb

@@ -2,14 +2,12 @@ module Docs
   class Vagrant
     class CleanHtmlFilter < Filter
       def call
-        if root_page?
-          doc.children = css('h1, .category')
-          return doc
-        end
+        @doc = at_css('.page-contents .span8')
 
-        css('nav', '.sidebar', 'footer').remove
+        css('hr').remove
 
-        css('.wrapper', '.page', '.container', '.row', '.page-contents', '.span8').each do |node|
+        css('pre > code').each do |node|
+          node.parent['class'] = node['class']
           node.before(node.children).remove
         end
 

+ 21 - 48
lib/docs/filters/vagrant/entries.rb

@@ -3,59 +3,32 @@ module Docs
     class EntriesFilter < Docs::EntriesFilter
       def get_name
         if slug.start_with?('push/')
-          if at_css('h2')
-            name = at_css('h2').content.strip
-          else
-            name = at_css('h1').content.strip
-          end
-          name
-        else
-          name = at_css('h1').content.strip
-          name
+          name = at_css('h2').try(:content)
+        elsif slug.start_with?('cli/')
+          name = at_css('h1 + p > strong > code').try(:content).try(:[], /\s*vagrant\s+[\w\-]+/)
         end
+
+        name || at_css('h1').content
       end
 
       def get_type
-        if slug.start_with?('why-vagrant')
-          'Why Vagrant?'
-        elsif slug.start_with?('installation')
-          'Installation'
-        elsif slug.start_with?('getting-started')
-          'Getting Started'
-        elsif slug.start_with?('cli')
-          'Command-Line Interface'
-        elsif slug.start_with?('share')
-          'Vagrant Share'
-        elsif slug.start_with?('vagrantfile')
-          'Vagrantfile'
-        elsif slug.start_with?('boxes')
-          'Boxes'
-        elsif slug.start_with?('provisioning')
-          'Provisioning'
-        elsif slug.start_with?('networking')
-          'Networking'
-        elsif slug.start_with?('synced-folders')
-          'Synced Folders'
-        elsif slug.start_with?('multi-machine')
-          'Multi-Machine'
-        elsif slug.start_with?('providers')
-          'Providers'
-        elsif slug.start_with?('plugins')
-          'Plugins'
-        elsif slug.start_with?('push')
-          'Push'
-        elsif slug.start_with?('other')
-          'Other'
-        elsif slug.start_with?('vmware')
-          'VMware'
-        elsif slug.start_with?('docker')
-          'Docker'
-        elsif slug.start_with?('virtualbox')
-          'VirtualBox'
-        elsif slug.start_with?('hyperv')
-          'Hyper-V'
+        at_css('.sidebar-nav li.current').content
+      end
+
+      def additional_entries
+        case at_css('h1 + p > strong > code').try(:content)
+        when /config\./
+          h2 = nil
+          css('.page-contents .span8 > *').each_with_object [] do |node, entries|
+            if node.name == 'h2'
+              h2 = node.content
+            elsif h2 == 'Available Settings' && (code = node.at_css('code')) && (name = code.content) && name.start_with?('config.')
+              id = code.parent['id'] = name.parameterize
+              entries << [name, id, 'Config']
+            end
+          end
         else
-          'Overview'
+          []
         end
       end
     end

+ 4 - 4
lib/docs/scrapers/vagrant.rb

@@ -1,15 +1,15 @@
 module Docs
   class Vagrant < UrlScraper
     self.name = 'Vagrant'
-    self.slug = 'vagrant'
     self.type = 'vagrant'
     self.version = '1.7.4'
-    self.base_url = 'http://docs.vagrantup.com/v2/'
+    self.base_url = 'https://docs.vagrantup.com/v2/'
     self.links = {
-      home: 'http://www.vagrantup.com/'
+      home: 'https://www.vagrantup.com/',
+      code: 'https://github.com/mitchellh/vagrant'
     }
 
-    html_filters.push 'vagrant/clean_html', 'vagrant/entries'
+    html_filters.push 'vagrant/entries', 'vagrant/clean_html'
 
     options[:attribution] = <<-HTML
       &copy; 2010&ndash;2015 Mitchell Hashimoto<br>

BIN
public/icons/docs/vagrant/16.png


BIN
public/icons/docs/vagrant/16@2x.png