Unified · Split
| @@ -4,7 +4,10 @@ module Docs · 3 unmodified lines | |||
| 4 | def call | 4 | def call |
| 5 | @doc = at_css('.bd-content') | 5 | @doc = at_css('.bd-content') |
| 6 | 6 | ||
| 7 | at_css('h1').content = 'Bootstrap 4' if root_page? | 7 | # 'View on Github' button |
| 8 | css('.btn').remove | ||
| 9 | |||
| 10 | at_css('h1').content = 'Bootstrap' if root_page? | ||
| 8 | 11 | ||
| 9 | css('hr', '.bd-clipboard', '.modal', '.bd-example .bd-example').remove | 12 | css('hr', '.bd-clipboard', '.modal', '.bd-example .bd-example').remove |
| 10 | 13 | ||
| @@ -21,15 +24,6 @@ module Docs · 10 unmodified lines | |||
| 21 | 24 | ||
| 22 | if node.previous_element['class'].try(:include?, 'bd-example') | 25 | if node.previous_element['class'].try(:include?, 'bd-example') |
| 23 | node.remove | 26 | node.remove |
| 24 | else | ||
| 25 | node.content = '' | ||
| 26 | node.name = 'p' | ||
| 27 | node['class'] = 'bd-example' | ||
| 28 | node.remove_attribute('data-example-id') | ||
| 29 | prev = node.previous_element | ||
| 30 | prev = prev.previous_element until !prev || prev['id'] | ||
| 31 | anchor = prev ? %(##{prev['id']}) : '' | ||
| 32 | node.inner_html = %(<a href="#{current_url}#{anchor}">Open example on getbootstrap.com</a>) | ||
| 33 | end | 27 | end |
| 34 | end | 28 | end |
| 35 | 29 | ||
| @@ -0,0 +1,32 @@ | |||
| 1 | module Docs | ||
| 2 | class Bootstrap | ||
| 3 | class CleanHtmlV5Filter < Filter | ||
| 4 | def call | ||
| 5 | |||
| 6 | @doc = at_css('main') | ||
| 7 | |||
| 8 | # Toc | ||
| 9 | css('.bd-toc').remove | ||
| 10 | |||
| 11 | # 'View on Github' button | ||
| 12 | css('.btn').remove | ||
| 13 | |||
| 14 | at_css('h1').content = 'Bootstrap' if root_page? | ||
| 15 | |||
| 16 | css('.highlight').each do |node| | ||
| 17 | code = node.at_css('code') | ||
| 18 | node['data-language'] = code['data-lang'] | ||
| 19 | node.content = code.content | ||
| 20 | node.name = 'pre' | ||
| 21 | end | ||
| 22 | |||
| 23 | css('.bd-example').each do |node| | ||
| 24 | node.remove | ||
| 25 | end | ||
| 26 | |||
| 27 | doc | ||
| 28 | |||
| 29 | end | ||
| 30 | end | ||
| 31 | end | ||
| 32 | end | ||
| @@ -0,0 +1,62 @@ | |||
| 1 | module Docs | ||
| 2 | class Bootstrap | ||
| 3 | class EntriesV5Filter < Docs::EntriesFilter | ||
| 4 | |||
| 5 | def get_name | ||
| 6 | at_css('.bd-title').content.strip | ||
| 7 | end | ||
| 8 | |||
| 9 | def get_type | ||
| 10 | type = subpath.match(/\A.*?\//).to_s[0..-2] | ||
| 11 | type.gsub!('-', ' ') | ||
| 12 | type.capitalize! | ||
| 13 | type << ": #{name}" if type == 'Components' | ||
| 14 | type | ||
| 15 | end | ||
| 16 | |||
| 17 | def additional_entries | ||
| 18 | return [] if root_page? || subpath.start_with?('getting-started') | ||
| 19 | |||
| 20 | entries = [] | ||
| 21 | |||
| 22 | # titles | ||
| 23 | css('h2', 'h3').each do |node| | ||
| 24 | entries << [ name + ': ' + node.content, node['id']] | ||
| 25 | end | ||
| 26 | |||
| 27 | # methods and events | ||
| 28 | # traverse through all '.tables' and search for a 'Method' or 'Event type' in the first <th> | ||
| 29 | css('.table').each do |node| | ||
| 30 | firstTh = node.at_css('th').content | ||
| 31 | |||
| 32 | if firstTh == 'Method' | ||
| 33 | # traverse all <tr> and search only the first <code> of each tr | ||
| 34 | node.css('tr').each do |subnode| | ||
| 35 | if subnode | ||
| 36 | method = subnode.at_css('code') | ||
| 37 | if method | ||
| 38 | method['id'] = method.content | ||
| 39 | entries << [method.content + ' (Method)', method['id']] | ||
| 40 | end | ||
| 41 | end | ||
| 42 | end | ||
| 43 | end | ||
| 44 | |||
| 45 | if firstTh == 'Event type' | ||
| 46 | node.css('tr').each do |subnode| | ||
| 47 | event = subnode.at_css('code') | ||
| 48 | if event | ||
| 49 | event['id'] = event.content | ||
| 50 | entries << [event.content + ' (Event)', event['id']] | ||
| 51 | end | ||
| 52 | end | ||
| 53 | end | ||
| 54 | |||
| 55 | end | ||
| 56 | |||
| 57 | entries | ||
| 58 | end | ||
| 59 | |||
| 60 | end | ||
| 61 | end | ||
| 62 | end | ||
| @@ -16,14 +16,36 @@ module Docs · 15 unmodified lines | |||
| 16 | Documentation licensed under the Creative Commons Attribution License v3.0. | 16 | Documentation licensed under the Creative Commons Attribution License v3.0. |
| 17 | HTML | 17 | HTML |
| 18 | 18 | ||
| 19 | version '5' do | ||
| 20 | self.release = '5.0' | ||
| 21 | self.base_url = "https://getbootstrap.com/docs/#{self.release}/" | ||
| 22 | self.root_path = 'getting-started/introduction/' | ||
| 23 | |||
| 24 | html_filters.push 'bootstrap/entries_v5', 'bootstrap/clean_html_v5' | ||
| 25 | |||
| 26 | options[:only_patterns] = [ | ||
| 27 | /\Agetting-started\//, /\Alayout\//, /\Acontent\//, | ||
| 28 | /\Acomponents\//, /\Autilities\/.+/, /\Ahelpers\// | ||
| 29 | ] | ||
| 30 | |||
| 31 | options[:replace_paths] = { | ||
| 32 | 'components/breadcrumb//' => '/components/breadcrumb/' | ||
| 33 | } | ||
| 34 | |||
| 35 | end | ||
| 36 | |||
| 19 | version '4' do | 37 | version '4' do |
| 20 | self.release = '4.5' | 38 | self.release = '4.5' |
| 21 | self.base_url = 'https://getbootstrap.com/docs/4.5/' | 39 | self.base_url = "https://getbootstrap.com/docs/#{self.release}/" |
| 22 | self.root_path = 'getting-started/introduction/' | 40 | self.root_path = 'getting-started/introduction/' |
| 23 | 41 | ||
| 24 | html_filters.push 'bootstrap/entries_v4', 'bootstrap/clean_html_v4' | 42 | html_filters.push 'bootstrap/entries_v4', 'bootstrap/clean_html_v4' |
| 25 | 43 | ||
| 26 | options[:only_patterns] = [/\Agetting-started\//, /\Alayout\//, /\Acontent\//, /\Acomponents\//, /\Autilities\/.+/, /\Amigration\//] | 44 | options[:only_patterns] = [ |
| 45 | /\Agetting-started\//, /\Alayout\//, /\Acontent\//, | ||
| 46 | /\Acomponents\//, /\Autilities\/.+/, /\Amigration\// | ||
| 47 | ] | ||
| 48 | |||
| 27 | end | 49 | end |
| 28 | 50 | ||
| 29 | version '3' do | 51 | version '3' do |
| @@ -40,5 +62,6 @@ module Docs · 10 unmodified lines | |||
| 40 | doc = fetch_doc('https://getbootstrap.com/docs/versions/', opts) | 62 | doc = fetch_doc('https://getbootstrap.com/docs/versions/', opts) |
| 41 | doc.at_css('span:contains("Latest")').parent.content.split(' ').first | 63 | doc.at_css('span:contains("Latest")').parent.content.split(' ').first |
| 42 | end | 64 | end |
| 65 | |||
| 43 | end | 66 | end |
| 44 | end | 67 | end |