From e22cbb47e91d06b9984aaeddb7e1a14f67eff734 Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 17 Sep 2017 13:42:43 -0400 Subject: [PATCH] Update Bootstrap documentation (4.0.0-beta) --- lib/docs/filters/bootstrap/clean_html_v4.rb | 4 ++++ lib/docs/filters/bootstrap/entries_v4.rb | 23 +++++++++++++------- lib/docs/scrapers/bootstrap.rb | 24 +++++++-------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/docs/filters/bootstrap/clean_html_v4.rb b/lib/docs/filters/bootstrap/clean_html_v4.rb index 12db365b..b841410a 100644 --- a/lib/docs/filters/bootstrap/clean_html_v4.rb +++ b/lib/docs/filters/bootstrap/clean_html_v4.rb @@ -53,6 +53,10 @@ module Docs node.name = 'h4' end + css('thead td').each do |node| + node.name = 'th' + end + css('table, tr, td, th, pre, code').each do |node| node.remove_attribute('class') node.remove_attribute('style') diff --git a/lib/docs/filters/bootstrap/entries_v4.rb b/lib/docs/filters/bootstrap/entries_v4.rb index e84b2371..1d362d9f 100644 --- a/lib/docs/filters/bootstrap/entries_v4.rb +++ b/lib/docs/filters/bootstrap/entries_v4.rb @@ -4,24 +4,22 @@ module Docs def get_name name = at_css('.bd-content h1').content.strip name.remove! ' system' - return type if name == 'Overview' - name.prepend 'Utilities: ' if subpath.start_with?('utilities') - name + name == 'Overview' ? type : name end def get_type if subpath.start_with?('components') at_css('.bd-content h1').content.strip.prepend 'Components: ' else - at_css('.bd-pageheader h1').content + at_css('.bd-toc-item.active > .bd-toc-link').content end end def additional_entries - return [] if root_page? || subpath.start_with?('getting-started') + return [] if root_page? || subpath.start_with?('getting-started') || subpath.start_with?('migration') entries = [] - css('#markdown-toc > li > a', '#markdown-toc > li li #markdown-toc-events').each do |node| + css('.bd-toc > ul > li > a', '.bd-toc a[href="#events"]', '.bd-toc a[href="#methods"]', '.bd-toc a[href="#triggers"]').each do |node| name = node.content next if name =~ /example/i || IGNORE_ENTRIES.include?(name) name.downcase! @@ -48,17 +46,26 @@ module Docs entries << [name, id] end + css("#events ~ table tbody td:first-child").each do |node| + name = node.content.strip + unless id = node.parent['id'] + id = node.parent['id'] = "#{name.parameterize}-event" + end + name.prepend "#{self.name}: " + name << ' (event)' + entries << [name, id] + end + entries end IGNORE_ENTRIES = %w( - Contents How\ it\ works Approach JavaScript\ behavior Usage - Basics Overview + About ) end end diff --git a/lib/docs/scrapers/bootstrap.rb b/lib/docs/scrapers/bootstrap.rb index f9b31070..f462e220 100644 --- a/lib/docs/scrapers/bootstrap.rb +++ b/lib/docs/scrapers/bootstrap.rb @@ -6,7 +6,7 @@ module Docs code: 'https://github.com/twbs/bootstrap' } - options[:trailing_slash] = false + options[:trailing_slash] = true options[:attribution] = <<-HTML © 2011–2017 Twitter, Inc.
@@ -16,31 +16,23 @@ module Docs HTML version '4' do - self.release = 'alpha.6' - self.base_url = 'https://v4-alpha.getbootstrap.com/' - self.root_path = 'getting-started/introduction' + self.release = '4.0.0-beta' + self.base_url = 'https://getbootstrap.com/docs/4.0/' + self.root_path = 'getting-started/introduction/' html_filters.push 'bootstrap/entries_v4', 'bootstrap/clean_html_v4' - options[:only_patterns] = [/\Agetting-started\//, /\Alayout\//, /\Acontent\//, /\Acomponents\//, /\Autilities\//] + options[:only_patterns] = [/\Agetting-started\//, /\Alayout\//, /\Acontent\//, /\Acomponents\//, /\Autilities\//, /\Amigration\//] end version '3' do self.release = '3.3.7' - self.base_url = 'https://getbootstrap.com/' - self.root_path = 'getting-started' + self.base_url = 'https://getbootstrap.com/docs/3.3/' + self.root_path = 'getting-started/' html_filters.push 'bootstrap/entries_v3', 'bootstrap/clean_html_v3' - options[:only] = %w(getting-started css components javascript) - end - - private - - def handle_response(response) - response.effective_url.scheme = 'https' - response.effective_url.path = response.effective_url.path.remove(/\/\z/) - super + options[:only] = %w(getting-started/ css/ components/ javascript/) end end end