From e97b8d463d04002d7adfa3a935582884dfe96334 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sun, 8 Feb 2015 13:58:02 -0500 Subject: [PATCH] Update Laravel documentation (5.0.0) --- lib/docs/filters/laravel/clean_html.rb | 20 +++++++++++--- lib/docs/filters/laravel/entries.rb | 27 +++++++++++++------ lib/docs/scrapers/laravel.rb | 36 +++++++++++++------------- 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/lib/docs/filters/laravel/clean_html.rb b/lib/docs/filters/laravel/clean_html.rb index fca4d644..4ed481e1 100644 --- a/lib/docs/filters/laravel/clean_html.rb +++ b/lib/docs/filters/laravel/clean_html.rb @@ -12,12 +12,24 @@ module Docs end def api - css('#footer', '.location').remove + @doc = doc.at_css('#page-content') + + css('.location').remove # Replace .header with

- css('.header > h1').each do |node| - node.parent.before(node).remove + css('.page-header > h1').each do |node| node.content = 'Laravel' if root_page? + node.parent.before(node).remove + end + + css('.container-fluid').each do |node| + node.name = 'table' + node.css('.row').each { |n| n.name = 'tr' } + node.css('div[class^="col"]').each { |n| n.name = 'td' } + end + + css('> div').each do |node| + node.before(node.children).remove end # Remove @@ -38,7 +50,7 @@ module Docs end def other - @doc = at_css('#docs-content') + @doc = at_css('article') # Clean up headings css('h2 > a').each do |node| diff --git a/lib/docs/filters/laravel/entries.rb b/lib/docs/filters/laravel/entries.rb index 3a0da2c9..75d33db9 100644 --- a/lib/docs/filters/laravel/entries.rb +++ b/lib/docs/filters/laravel/entries.rb @@ -3,29 +3,36 @@ module Docs class EntriesFilter < Docs::EntriesFilter def get_name if api_page? - at_css('h1').content.strip.split('\\').last + name = at_css('h1').content.strip.remove('Illuminate\\') + name << " (#{type})" unless name.start_with?(self.type) + name else - at_css('h1').content.strip + at_css('h1').content end end def get_type - if api_page? - type = at_css('h1').content.strip.remove('Illuminate\\').remove(/\\\w+?\z/) - type.end_with?('Console') ? type.split('\\').first : type + return 'Guides' unless api_page? + type = slug.remove('api/5.0/').remove('Illuminate/').remove(/\/\w+?\z/).gsub('/', '\\') + + if type.end_with?('Console') + type.split('\\').first + elsif type.start_with?('Contracts') + 'Contracts' else - 'Guides' + type end end def additional_entries - return [] unless api_page? + return [] if root_page? || !api_page? + base_name = self.name.remove(/\(.+\)/).strip css('h3[id^="method_"]').each_with_object [] do |node, entries| next if node.at_css('.location').content.start_with?('in') name = node['id'].remove('method_') - name.prepend "#{self.name}::" + name.prepend "#{base_name}::" name << '()' entries << [name, node['id']] @@ -35,6 +42,10 @@ module Docs def api_page? subpath.start_with?('/api') end + + def include_default_entry? + subpath != '/api/5.0/classes.html' + end end end end diff --git a/lib/docs/scrapers/laravel.rb b/lib/docs/scrapers/laravel.rb index c5a317a5..36f7b936 100644 --- a/lib/docs/scrapers/laravel.rb +++ b/lib/docs/scrapers/laravel.rb @@ -3,36 +3,36 @@ module Docs self.name = 'Laravel' self.slug = 'laravel' self.type = 'laravel' - self.version = '4.2.11' + self.version = '5.0.0' self.base_url = 'http://laravel.com' - self.root_path = '/docs/4.2/introduction' - self.initial_paths = %w(/api/4.2/classes.html) + self.root_path = '/api/5.0/index.html' + self.initial_paths = %w(/docs/5.0/installation /api/5.0/classes.html) html_filters.push 'laravel/entries', 'laravel/clean_html' options[:container] = ->(filter) { - filter.subpath.start_with?('/api') ? nil : '#documentation > article' + filter.subpath.start_with?('/api') ? '#content' : '.docs-wrapper' } options[:only_patterns] = [ - /\A\/api\/4\.2\//, - /\A\/docs\/4\.2\//] + /\A\/api\/5\.0\//, + /\A\/docs\/5\.0\//] options[:skip] = %w( - /docs/4.2/quick - /docs/4.2/releases - /docs/4.2/upgrade - /docs/4.2/artisan - /docs/4.2/commands - /api/4.2/panel.html - /api/4.2/namespaces.html - /api/4.2/interfaces.html - /api/4.2/traits.html - /api/4.2/doc-index.html - /api/4.2/Illuminate.html) + /docs/5.0/quick + /docs/5.0/releases + /docs/5.0/artisan + /docs/5.0/commands + /api/5.0/panel.html + /api/5.0/namespaces.html + /api/5.0/interfaces.html + /api/5.0/traits.html + /api/5.0/doc-index.html + /api/5.0/Illuminate.html + /api/5.0/search.html) options[:fix_urls] = ->(url) do - url.sub! %r{#{Regexp.escape(Laravel.base_url)}/docs\/(?!\d)}, "#{Laravel.base_url}/docs/4.2/" + url.sub! %r{#{Regexp.escape(Laravel.base_url)}/docs\/(?!\d)}, "#{Laravel.base_url}/docs/5.0/" url end