bs5 0.0.4 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -70
  3. data/app/components/bs5/alert_component.html.erb +1 -1
  4. data/app/components/bs5/alert_component.rb +2 -0
  5. data/app/components/bs5/badge_component.rb +2 -0
  6. data/app/components/bs5/breadcrumb_component.html.erb +9 -0
  7. data/app/components/bs5/breadcrumb_component.rb +12 -0
  8. data/app/components/bs5/button_tag_component.rb +121 -0
  9. data/app/components/bs5/close_button_component.html.erb +7 -0
  10. data/app/components/bs5/close_button_component.rb +29 -0
  11. data/app/components/bs5/example_component.html.erb +8 -0
  12. data/app/components/bs5/example_component.rb +44 -0
  13. data/app/controllers/bs5/application_controller.rb +9 -0
  14. data/app/controllers/bs5/examples_controller.rb +9 -0
  15. data/app/helpers/bs5/application_helper.rb +2 -0
  16. data/app/helpers/bs5/components_helper.rb +11 -10
  17. data/app/helpers/bs5/examples_helper.rb +9 -0
  18. data/app/models/bs5/application_record.rb +2 -0
  19. data/app/validators/style_validator.rb +2 -4
  20. data/app/views/bs5/examples/_accordion.html.erb +3 -0
  21. data/app/views/bs5/examples/_alert.html.erb +5 -0
  22. data/app/views/bs5/examples/_badge.html.erb +4 -0
  23. data/app/views/bs5/examples/_breadcrumb.html.erb +2 -0
  24. data/app/views/bs5/examples/_buttons.html.erb +7 -0
  25. data/app/views/bs5/examples/_close_button.html.erb +4 -0
  26. data/app/views/bs5/examples/accordion/default/_example.html.erb +2 -0
  27. data/app/views/bs5/examples/accordion/default/snippet.html.erb +11 -0
  28. data/app/views/bs5/examples/accordion/flush/_example.html.erb +2 -0
  29. data/app/views/bs5/examples/accordion/flush/snippet.html.erb +11 -0
  30. data/app/views/bs5/examples/alert/additional_content/_example.html.erb +2 -0
  31. data/app/views/bs5/examples/alert/additional_content/snippet.html.erb +6 -0
  32. data/app/views/bs5/examples/alert/default/_example.html.erb +2 -0
  33. data/app/views/bs5/examples/alert/default/snippet.html.erb +3 -0
  34. data/app/views/bs5/examples/alert/dismissable/_example.html.erb +2 -0
  35. data/app/views/bs5/examples/alert/dismissable/snippet.html.erb +3 -0
  36. data/app/views/bs5/examples/alert/style/_example.html.erb +2 -0
  37. data/app/views/bs5/examples/alert/style/snippet.html.erb +31 -0
  38. data/app/views/bs5/examples/badge/default/_example.html.erb +2 -0
  39. data/app/views/bs5/examples/badge/default/snippet.html.erb +6 -0
  40. data/app/views/bs5/examples/badge/pill/_example.html.erb +2 -0
  41. data/app/views/bs5/examples/badge/pill/snippet.html.erb +8 -0
  42. data/app/views/bs5/examples/badge/style/_example.html.erb +2 -0
  43. data/app/views/bs5/examples/badge/style/snippet.html.erb +8 -0
  44. data/app/views/bs5/examples/breadcrumb/default/_example.html.erb +2 -0
  45. data/app/views/bs5/examples/breadcrumb/default/snippet.html.erb +14 -0
  46. data/app/views/bs5/examples/buttons/block_buttons/_example.html.erb +5 -0
  47. data/app/views/bs5/examples/buttons/block_buttons/block_buttons.html.erb +4 -0
  48. data/app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_1.html.erb +4 -0
  49. data/app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_2.html.erb +4 -0
  50. data/app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_3.html.erb +4 -0
  51. data/app/views/bs5/examples/buttons/default/_example.html.erb +2 -0
  52. data/app/views/bs5/examples/buttons/default/snippet.html.erb +15 -0
  53. data/app/views/bs5/examples/buttons/outline/_example.html.erb +2 -0
  54. data/app/views/bs5/examples/buttons/outline/snippet.html.erb +19 -0
  55. data/app/views/bs5/examples/buttons/size/_example.html.erb +3 -0
  56. data/app/views/bs5/examples/buttons/size/large.html.erb +3 -0
  57. data/app/views/bs5/examples/buttons/size/small.html.erb +3 -0
  58. data/app/views/bs5/examples/buttons/style/_example.html.erb +2 -0
  59. data/app/views/bs5/examples/buttons/style/snippet.html.erb +19 -0
  60. data/app/views/bs5/examples/buttons/toggle_states/_example.html.erb +2 -0
  61. data/app/views/bs5/examples/buttons/toggle_states/snippet.html.erb +3 -0
  62. data/app/views/bs5/examples/close_button/default/_example.html.erb +2 -0
  63. data/app/views/bs5/examples/close_button/default/snippet.html.erb +1 -0
  64. data/app/views/bs5/examples/close_button/disabled/_example.html.erb +2 -0
  65. data/app/views/bs5/examples/close_button/disabled/snippet.html.erb +1 -0
  66. data/app/views/bs5/examples/close_button/white/_example.html.erb +2 -0
  67. data/app/views/bs5/examples/close_button/white/snippet.html.erb +1 -0
  68. data/app/views/bs5/examples/index.html.erb +23 -0
  69. data/app/views/layouts/bs5/application.html.erb +6 -7
  70. data/config/definitions.rb +31 -0
  71. data/config/locales/en.yml +6 -0
  72. data/config/routes.rb +5 -0
  73. data/lib/bs5.rb +3 -1
  74. data/lib/bs5/version.rb +1 -1
  75. data/lib/generators/bs5/install/install_generator.rb +28 -20
  76. data/lib/tasks/bs5_tasks.rake +1 -0
  77. data/lib/tasks/ci.rake +3 -0
  78. data/lib/tasks/rubocop.rake +5 -0
  79. metadata +102 -15
  80. data/app/jobs/bs5/application_job.rb +0 -4
  81. data/app/mailers/bs5/application_mailer.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d4e64b1fb40e3224c42147923de60bb7233c2c2fbf411674e0bca31c093c837
4
- data.tar.gz: 80ef0fe973d5cab69eb75e4834dbaed31c1886d13c4f6586aeed655d0a69ba2a
3
+ metadata.gz: 54b572156c8e8680ba3937031736fe9cdb6e2aeaf2ea88cb49b6e26c18e02c35
4
+ data.tar.gz: 4a4650ceee8e21d32f6a905f00c398e072bb407a4f118cd95488454f9ef61121
5
5
  SHA512:
6
- metadata.gz: a4b8e31ace3f99001251e99f0e8c7d2ad8e2320008223c7b346eeca08fcd9e39d2b59c208e181720a2c6e611550a6913e11cc941b0c92a89dffd73b4bf9d615d
7
- data.tar.gz: 10bcf562669a15ea680eea134048ab9ee32986e905e28173184ddf044842ac6dafdb507817a3154487e2fa5e567aaa2209313e25752b77e7699df18720adc630
6
+ metadata.gz: c3be0fb1a7839cafbd9673ee974879fd2e95c13e25c5a0f73a27c278c0f2abb1d4305d7eaf965999e5c5fcd390079d116c9aea297e63c1ce5530fdc3e455deb8
7
+ data.tar.gz: 73f164bfd36774c565a358e23e294d49b8f386db1450e92a9e73cefd81fa2951b7560705c6e098607a5005e50bf071c094a23d1eacfadf304be61c07995771df
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This is a Ruby on Rails engine to include [Bootstrap 5](https://v5.getbootstrap.com/).
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/bs5.svg)](https://badge.fury.io/rb/bs5)
5
+ [![Gem Version](https://badge.fury.io/rb/bs5.svg)](https://badge.fury.io/rb/bs5) [![Build Status](https://travis-ci.org/bazzel/bs5.svg?branch=main)](https://travis-ci.org/bazzel/bs5) [![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
6
6
 
7
7
  ## Usage
8
8
 
@@ -34,75 +34,6 @@ Run the following command to setup your project to use Bootstrap 5.
34
34
 
35
35
  $ rails generate bs5:install
36
36
 
37
- ## Components
38
-
39
- ### [Accordion](https://v5.getbootstrap.com/docs/5.0/components/accordion/) ✅
40
-
41
- ```
42
- <%= bs5_accordion do |accordion| %>
43
- <% accordion.slot(:item, title: 'Accordion Item #1', collapsed: false) do %>
44
- <strong>This is the first item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
45
- <% end %>
46
- <% accordion.slot(:item, title: 'Accordion Item #2') do %>
47
- <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
48
- <% end %>
49
- <% accordion.slot(:item, title: 'Accordion Item #3') do %>
50
- <strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
51
- <% end %>
52
- <%- end %>
53
- ```
54
-
55
- ```
56
- <%= bs5_accordion(flush: true) do |accordion| %>
57
- <% accordion.slot(:item, title: 'Accordion Item #1') do %>
58
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
59
- <% end %>
60
- <% accordion.slot(:item, title: 'Accordion Item #2') do %>
61
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
62
- <% end %>
63
- <% accordion.slot(:item, title: 'Accordion Item #3') do %>
64
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
65
- <% end %>
66
- <%- end %>
67
- ```
68
-
69
- ### [Alert](https://v5.getbootstrap.com/docs/5.0/components/alerts/) ✅
70
-
71
- ```
72
- <%= bs5_alert do %>
73
- A simple primary alert—check it out!
74
- <%- end %>
75
- ```
76
-
77
- ```
78
- <%= bs5_alert(style: :warning, is_dismissable: true) do %>
79
- <strong>Holy guacamole!</strong> You should check in on some of those fields below.
80
- <%- end %>
81
- ```
82
-
83
- ### [Badge](https://v5.getbootstrap.com/docs/5.0/components/badge/) ✅
84
-
85
- ```
86
- <%= bs5_badge(text: 'New') %>
87
- ```
88
-
89
- ```
90
- <%= bs5_badge(text: 'Warning', style: :warning) %>
91
- ```
92
-
93
- ```
94
- <%= bs5_badge(text: 'Danger', style: :danger, pill: true) %>
95
- ```
96
-
97
-
98
- ### [Breadcrumb](https://v5.getbootstrap.com/docs/5.0/components/breadcrumb/)
99
-
100
- ### [Button](https://v5.getbootstrap.com/docs/5.0/components/buttons/)
101
-
102
- ## Previewing components
103
-
104
- - http://localhost:3000/rails/view_components
105
-
106
37
  ## Contributing
107
38
 
108
39
  Contribution directions go here.
@@ -1,6 +1,6 @@
1
1
  <div class="<%= component_class %>" role="alert">
2
2
  <%= content %>
3
3
  <%- if is_dismissable %>
4
- <button type="button" class="btn-close" data-dismiss="alert" aria-label="Close"></button>
4
+ <%= render Bs5::CloseButtonComponent.new(data: { dismiss: :alert }) %>
5
5
  <%- end %>
6
6
  </div>
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Bs5
4
4
  class AlertComponent < ViewComponent::Base
5
+ STYLES = %i[primary secondary success danger warning info light dark].freeze
6
+
5
7
  attr_reader :style, :is_dismissable
6
8
 
7
9
  include ActiveModel::Validations
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Bs5
4
4
  class BadgeComponent < ViewComponent::Base
5
+ STYLES = %i[primary secondary success danger warning info light dark].freeze
6
+
5
7
  attr_reader :text, :style
6
8
 
7
9
  include ActiveModel::Validations
@@ -0,0 +1,9 @@
1
+ <% if items.any? %>
2
+ <nav aria-label="breadcrumb">
3
+ <ol class="breadcrumb">
4
+ <% items.each do |item| %>
5
+ <li class="breadcrumb-item <%= item == items.last ? 'active' : '' %>" <%= item == items.last ? 'aria-current=page' : '' %>><%= item.content %></li>
6
+ <% end %>
7
+ </ol>
8
+ </nav>
9
+ <% end %>
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ class BreadcrumbComponent < ViewComponent::Base
5
+ include ViewComponent::Slotable
6
+
7
+ with_slot :item, collection: true, class_name: 'Item'
8
+
9
+ class Item < ViewComponent::Slot
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ class ButtonTagComponent < ViewComponent::Base
5
+ STYLES = %i[primary secondary success danger warning info light dark link].freeze
6
+ SIZES = %i[small large].freeze
7
+
8
+ attr_reader :content_or_options, :options, :size
9
+
10
+ include ActiveModel::Validations
11
+ validates :style, style: true
12
+ validates :size, inclusion: { in: SIZES, valid_sizes: SIZES.to_sentence, allow_nil: true }
13
+
14
+ def initialize(content_or_options = nil, options = nil)
15
+ @content_or_options = content_or_options.dup
16
+ @options = options.dup
17
+
18
+ extract_custom_options
19
+ merge_default_options
20
+ end
21
+
22
+ def before_render
23
+ raise errors.full_messages.to_sentence if invalid?
24
+ end
25
+
26
+ def call
27
+ if content
28
+ button_tag(content_or_options, options) { content }
29
+ else
30
+ button_tag(content_or_options, options)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def extract_custom_options
37
+ extract_style
38
+ extract_outline
39
+ extract_size
40
+ end
41
+
42
+ def extract_style
43
+ if @content_or_options.is_a? Hash
44
+ @style = @content_or_options.delete(:style)
45
+ @content_or_options = nil if @content_or_options.empty?
46
+ elsif @options.is_a? Hash
47
+ @style = @options.delete(:style)
48
+ @options = nil if @options.empty?
49
+ end
50
+ end
51
+
52
+ def extract_outline
53
+ if @content_or_options.is_a? Hash
54
+ @outline = @content_or_options.delete(:outline)
55
+ @content_or_options = nil if @content_or_options.empty?
56
+ elsif @options.is_a? Hash
57
+ @outline = @options.delete(:outline)
58
+ @options = nil if @options.empty?
59
+ end
60
+ end
61
+
62
+ def extract_size
63
+ if @content_or_options.is_a? Hash
64
+ @size = @content_or_options.delete(:size)
65
+ @content_or_options = nil if @content_or_options.empty?
66
+ elsif @options.is_a? Hash
67
+ @size = @options.delete(:size)
68
+ @options = nil if @options.empty?
69
+ end
70
+ end
71
+
72
+ def merge_default_options
73
+ if @content_or_options.is_a? Hash
74
+ deep_merge_and_join @content_or_options, default_options
75
+ else
76
+ @options ||= {}
77
+ deep_merge_and_join @options, default_options
78
+ end
79
+ end
80
+
81
+ def default_options
82
+ {
83
+ class: button_class
84
+ }
85
+ end
86
+
87
+ def button_class
88
+ ['btn', contextual_class, size_class].compact.join(' ')
89
+ end
90
+
91
+ def contextual_class
92
+ ['btn', outline? ? 'outline' : nil, style].compact.join('-')
93
+ end
94
+
95
+ def size_class
96
+ return unless size?
97
+
98
+ x = { large: 'lg', small: 'sm' }[@size]
99
+
100
+ "btn-#{x}"
101
+ end
102
+
103
+ def style
104
+ (@style || 'primary').to_sym
105
+ end
106
+
107
+ def outline?
108
+ !!@outline
109
+ end
110
+
111
+ def size?
112
+ !!@size
113
+ end
114
+
115
+ def deep_merge_and_join(h1, h2)
116
+ h1.deep_merge!(h2) do |key, this_val, other_val|
117
+ [this_val, other_val].join(' ').strip
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,7 @@
1
+ <%= button_tag '',
2
+ type: 'button',
3
+ class: component_class,
4
+ disabled: disabled?,
5
+ aria: { label: 'Close'},
6
+ data: data
7
+ %>
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ class CloseButtonComponent < ViewComponent::Base
5
+ attr_reader :data
6
+
7
+ def initialize(disabled: false, white: false, data: nil)
8
+ @disabled = disabled
9
+ @white = white
10
+ @data = data
11
+ end
12
+
13
+ private
14
+
15
+ def white?
16
+ @white
17
+ end
18
+
19
+ def disabled?
20
+ @disabled
21
+ end
22
+
23
+ def component_class
24
+ class_names = ['btn-close']
25
+ class_names << %w[btn-close-white] if white?
26
+ class_names.join(' ')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ <div class="mt-4 mb-3">
2
+ <div class="border rounded-2 p-4">
3
+ <%= render template: snippet %>
4
+ </div>
5
+ <div class="highlight p-4">
6
+ <pre class='mb-0'><code><%= highlight %></code></pre>
7
+ </div>
8
+ </div>
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rouge'
4
+
5
+ module Bs5
6
+ class ExampleComponent < ViewComponent::Base
7
+ include ComponentsHelper
8
+
9
+ attr_reader :snippet
10
+
11
+ def initialize(snippet:)
12
+ @snippet = snippet
13
+ @path = snippet.split('/')
14
+ @basename = @path.pop
15
+ end
16
+
17
+ def highlight
18
+ formatter = Rouge::Formatters::HTML.new
19
+ lexer = Rouge::Lexer.find(language)
20
+ formatter.format(lexer.lex(file_content)).html_safe # rubocop:disable Rails/OutputSafety
21
+ end
22
+
23
+ private
24
+
25
+ def file_content
26
+ @file_content ||= file.read
27
+ end
28
+
29
+ def file
30
+ @file ||= examples_path
31
+ .join(*@path)
32
+ .children
33
+ .find { |ch| ch.basename.to_s.start_with?(@basename) }
34
+ end
35
+
36
+ def examples_path
37
+ Engine.root.join('app', 'views', 'bs5', 'examples')
38
+ end
39
+
40
+ def language
41
+ file.extname.delete('.')
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bs5
2
4
  class ApplicationController < ActionController::Base
3
5
  protect_from_forgery with: :exception
6
+ before_action :set_views_path
7
+
8
+ private
9
+
10
+ def set_views_path
11
+ append_view_path Engine.root.join('app', 'views', 'bs5', 'examples')
12
+ end
4
13
  end
5
14
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency 'bs5/application_controller'
4
+
5
+ module Bs5
6
+ class ExamplesController < ApplicationController
7
+ def index; end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bs5
2
4
  module ApplicationHelper
3
5
  end
@@ -2,20 +2,21 @@
2
2
 
3
3
  module Bs5
4
4
  module ComponentsHelper
5
- def bs5_accordion(*args)
6
- render AccordionComponent.new(*args) do |accordion|
7
- yield accordion if block_given?
8
- end
9
- end
5
+ COMPONENTS = %w[accordion alert badge close_button breadcrumb button_tag].freeze
10
6
 
11
- def bs5_alert(*args)
12
- render AlertComponent.new(*args) do
13
- yield if block_given?
7
+ COMPONENTS.each do |name|
8
+ define_method("bs5_#{name}") do |*args, &block|
9
+ clazz = "Bs5::#{name.classify}Component".constantize
10
+ render_component(clazz, *args, &block)
14
11
  end
15
12
  end
16
13
 
17
- def bs5_badge(*args)
18
- render BadgeComponent.new(*args)
14
+ private
15
+
16
+ def render_component(component_clazz, *args)
17
+ render component_clazz.new(*args) do |c|
18
+ yield c if block_given?
19
+ end
19
20
  end
20
21
  end
21
22
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ module ExamplesHelper
5
+ def bs5_example(*args)
6
+ render ExampleComponent.new(*args)
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bs5
2
4
  class ApplicationRecord < ActiveRecord::Base
3
5
  self.abstract_class = true