[devdocsgjs/main: 1436/1867] Add Bootstrap version 5.0




commit 564b02fee447cc4d3ed4cd6ea068848f7a566472
Author: MasterEnoc <brianhernandez222 hotmail com>
Date:   Mon Dec 28 19:48:16 2020 -0600

    Add Bootstrap version 5.0

 lib/docs/filters/bootstrap/clean_html_v4.rb | 14 ++-----
 lib/docs/filters/bootstrap/clean_html_v5.rb | 32 +++++++++++++++
 lib/docs/filters/bootstrap/entries_v5.rb    | 62 +++++++++++++++++++++++++++++
 lib/docs/scrapers/bootstrap.rb              | 27 ++++++++++++-
 4 files changed, 123 insertions(+), 12 deletions(-)
---
diff --git a/lib/docs/filters/bootstrap/clean_html_v4.rb b/lib/docs/filters/bootstrap/clean_html_v4.rb
index 6a94e20e..cc43e565 100644
--- a/lib/docs/filters/bootstrap/clean_html_v4.rb
+++ b/lib/docs/filters/bootstrap/clean_html_v4.rb
@@ -4,7 +4,10 @@ module Docs
       def call
         @doc = at_css('.bd-content')
 
-        at_css('h1').content = 'Bootstrap 4' if root_page?
+        # 'View on Github' button
+        css('.btn').remove
+
+        at_css('h1').content = 'Bootstrap' if root_page?
 
         css('hr', '.bd-clipboard', '.modal', '.bd-example .bd-example').remove
 
@@ -21,15 +24,6 @@ module Docs
 
           if node.previous_element['class'].try(:include?, 'bd-example')
             node.remove
-          else
-            node.content = ''
-            node.name = 'p'
-            node['class'] = 'bd-example'
-            node.remove_attribute('data-example-id')
-            prev = node.previous_element
-            prev = prev.previous_element until !prev || prev['id']
-            anchor = prev ? %(##{prev['id']}) : ''
-            node.inner_html = %(<a href="#{current_url}#{anchor}">Open example on getbootstrap.com</a>)
           end
         end
 
diff --git a/lib/docs/filters/bootstrap/clean_html_v5.rb b/lib/docs/filters/bootstrap/clean_html_v5.rb
new file mode 100644
index 00000000..daf3a81d
--- /dev/null
+++ b/lib/docs/filters/bootstrap/clean_html_v5.rb
@@ -0,0 +1,32 @@
+module Docs
+  class Bootstrap
+    class CleanHtmlV5Filter < Filter
+      def call
+
+        @doc = at_css('main')
+
+        # Toc
+        css('.bd-toc').remove
+
+        # 'View on Github' button
+        css('.btn').remove
+
+        at_css('h1').content = 'Bootstrap' if root_page?
+
+        css('.highlight').each do |node|
+          code = node.at_css('code')
+          node['data-language'] = code['data-lang']
+          node.content = code.content
+          node.name = 'pre'
+        end
+
+        css('.bd-example').each do |node|
+          node.remove
+        end
+
+        doc
+
+      end
+    end
+  end
+end
diff --git a/lib/docs/filters/bootstrap/entries_v5.rb b/lib/docs/filters/bootstrap/entries_v5.rb
new file mode 100644
index 00000000..27ba2f7e
--- /dev/null
+++ b/lib/docs/filters/bootstrap/entries_v5.rb
@@ -0,0 +1,62 @@
+module Docs
+  class Bootstrap
+    class EntriesV5Filter < Docs::EntriesFilter
+
+      def get_name
+        at_css('.bd-title').content.strip
+      end
+
+      def get_type
+        type = subpath.match(/\A.*?\//).to_s[0..-2]
+        type.gsub!('-', ' ')
+        type.capitalize!
+        type << ": #{name}" if type == 'Components'
+        type
+      end
+
+      def additional_entries
+        return [] if root_page? || subpath.start_with?('getting-started')
+
+        entries = []
+
+        # titles
+        css('h2', 'h3').each do |node|
+          entries << [ name + ': ' + node.content, node['id']]
+        end
+
+        # methods and events
+        # traverse through all '.tables' and search for a 'Method' or 'Event type' in the first <th>
+        css('.table').each do |node|
+          firstTh = node.at_css('th').content
+
+          if firstTh == 'Method'
+            # traverse all <tr> and search only the first <code> of each tr
+            node.css('tr').each do |subnode|
+              if subnode
+                method = subnode.at_css('code')
+                if method
+                  method['id'] = method.content
+                  entries << [method.content + ' (Method)', method['id']]
+                end
+              end
+            end
+          end
+
+          if firstTh == 'Event type'
+            node.css('tr').each do |subnode|
+              event = subnode.at_css('code')
+              if event
+                event['id'] = event.content
+                entries << [event.content + ' (Event)', event['id']]
+              end
+            end
+          end
+
+        end
+
+        entries
+      end
+
+    end
+  end
+end
diff --git a/lib/docs/scrapers/bootstrap.rb b/lib/docs/scrapers/bootstrap.rb
index d932db9e..ab91445e 100644
--- a/lib/docs/scrapers/bootstrap.rb
+++ b/lib/docs/scrapers/bootstrap.rb
@@ -16,14 +16,36 @@ module Docs
       Documentation licensed under the Creative Commons Attribution License v3.0.
     HTML
 
+    version '5' do
+      self.release = '5.0'
+      self.base_url = "https://getbootstrap.com/docs/#{self.release}/";
+      self.root_path = 'getting-started/introduction/'
+
+      html_filters.push 'bootstrap/entries_v5', 'bootstrap/clean_html_v5'
+
+      options[:only_patterns] = [
+        /\Agetting-started\//, /\Alayout\//, /\Acontent\//,
+        /\Acomponents\//, /\Autilities\/.+/, /\Ahelpers\//
+      ]
+
+      options[:replace_paths] = {
+        'components/breadcrumb//' => '/components/breadcrumb/'
+      }
+
+    end
+
     version '4' do
       self.release = '4.5'
-      self.base_url = 'https://getbootstrap.com/docs/4.5/'
+      self.base_url = "https://getbootstrap.com/docs/#{self.release}/";
       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\/.+/, /\Amigration\//]
+      options[:only_patterns] = [
+        /\Agetting-started\//, /\Alayout\//, /\Acontent\//,
+        /\Acomponents\//, /\Autilities\/.+/, /\Amigration\//
+      ]
+
     end
 
     version '3' do
@@ -40,5 +62,6 @@ module Docs
       doc = fetch_doc('https://getbootstrap.com/docs/versions/', opts)
       doc.at_css('span:contains("Latest")').parent.content.split(' ').first
     end
+
   end
 end


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]