History

Add Bootstrap version 5.0

MasterEnoc committed 5 years ago

Commit 564b02f1 parent e832d3b4 files · +123 −12Browse files

Unified · Split

4 files
  1. lib/docs/filters/bootstrap/clean_html_v4.rb +4 −10
  2. lib/docs/filters/bootstrap/clean_html_v5.rb +32 −0
  3. lib/docs/filters/bootstrap/entries_v5.rb +62 −0
  4. lib/docs/scrapers/bootstrap.rb +25 −2
lib/docs/filters/bootstrap/clean_html_v4.rb+4−10
@@ -4,7 +4,10 @@ module Docs · 3 unmodified lines
44 def call
55 @doc = at_css('.bd-content')
66
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?
811
912 css('hr', '.bd-clipboard', '.modal', '.bd-example .bd-example').remove
1013
@@ -21,15 +24,6 @@ module Docs · 10 unmodified lines
2124
2225 if node.previous_element['class'].try(:include?, 'bd-example')
2326 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>)
3327 end
3428 end
3529
lib/docs/filters/bootstrap/clean_html_v5.rb+32−0
@@ -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
lib/docs/filters/bootstrap/entries_v5.rb+62−0
@@ -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
lib/docs/scrapers/bootstrap.rb+25−2
@@ -16,14 +16,36 @@ module Docs · 15 unmodified lines
1616 Documentation licensed under the Creative Commons Attribution License v3.0.
1717 HTML
1818
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+
1937 version '4' do
2038 self.release = '4.5'
21− self.base_url = 'https://getbootstrap.com/docs/4.5/'
39+ self.base_url = "https://getbootstrap.com/docs/#{self.release}/"
2240 self.root_path = 'getting-started/introduction/'
2341
2442 html_filters.push 'bootstrap/entries_v4', 'bootstrap/clean_html_v4'
2543
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+
2749 end
2850
2951 version '3' do
@@ -40,5 +62,6 @@ module Docs · 10 unmodified lines
4062 doc = fetch_doc('https://getbootstrap.com/docs/versions/', opts)
4163 doc.at_css('span:contains("Latest")').parent.content.split(' ').first
4264 end
65+
4366 end
4467 end