bs5 0.0.7 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/app/components/bs5/alert_component.rb +2 -0
  3. data/app/components/bs5/badge_component.rb +2 -0
  4. data/app/components/bs5/breadcrumb_component.html.erb +9 -0
  5. data/app/components/bs5/breadcrumb_component.rb +12 -0
  6. data/app/components/bs5/button_tag_component.rb +100 -0
  7. data/app/components/bs5/button_to_component.rb +109 -0
  8. data/app/helpers/bs5/components_helper.rb +18 -12
  9. data/app/validators/style_validator.rb +2 -4
  10. data/app/views/bs5/examples/_alert.html.erb +1 -0
  11. data/app/views/bs5/examples/_breadcrumb.html.erb +2 -0
  12. data/app/views/bs5/examples/_buttons.html.erb +11 -0
  13. data/app/views/bs5/examples/_close_button.html.erb +4 -0
  14. data/app/views/bs5/examples/_tooltips.html.erb +2 -0
  15. data/app/views/bs5/examples/alert/additional_content/_example.html.erb +2 -0
  16. data/app/views/bs5/examples/alert/additional_content/snippet.html.erb +6 -0
  17. data/app/views/bs5/examples/alert/dismissable/_example.html.erb +1 -1
  18. data/app/views/bs5/examples/alert/style/snippet.html.erb +28 -0
  19. data/app/views/bs5/examples/badge/default/_example.html.erb +1 -1
  20. data/app/views/bs5/examples/badge/default/snippet.html.erb +6 -1
  21. data/app/views/bs5/examples/badge/pill/_example.html.erb +1 -1
  22. data/app/views/bs5/examples/badge/pill/snippet.html.erb +8 -1
  23. data/app/views/bs5/examples/badge/style/_example.html.erb +1 -1
  24. data/app/views/bs5/examples/badge/style/snippet.html.erb +8 -1
  25. data/app/views/bs5/examples/breadcrumb/default/_example.html.erb +2 -0
  26. data/app/views/bs5/examples/breadcrumb/default/snippet.html.erb +14 -0
  27. data/app/views/bs5/examples/buttons/button_tag/block_buttons/_example.html.erb +5 -0
  28. data/app/views/bs5/examples/buttons/button_tag/block_buttons/block_buttons.html.erb +4 -0
  29. data/app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_1.html.erb +4 -0
  30. data/app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_2.html.erb +4 -0
  31. data/app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_3.html.erb +4 -0
  32. data/app/views/bs5/examples/buttons/button_tag/default/_example.html.erb +2 -0
  33. data/app/views/bs5/examples/buttons/button_tag/default/snippet.html.erb +15 -0
  34. data/app/views/bs5/examples/buttons/button_tag/outline/_example.html.erb +2 -0
  35. data/app/views/bs5/examples/buttons/button_tag/outline/snippet.html.erb +19 -0
  36. data/app/views/bs5/examples/buttons/button_tag/size/_example.html.erb +3 -0
  37. data/app/views/bs5/examples/buttons/button_tag/size/large.html.erb +3 -0
  38. data/app/views/bs5/examples/buttons/button_tag/size/small.html.erb +3 -0
  39. data/app/views/bs5/examples/buttons/button_tag/style/_example.html.erb +2 -0
  40. data/app/views/bs5/examples/buttons/button_tag/style/snippet.html.erb +19 -0
  41. data/app/views/bs5/examples/buttons/button_tag/toggle_states/_example.html.erb +2 -0
  42. data/app/views/bs5/examples/buttons/button_tag/toggle_states/snippet.html.erb +3 -0
  43. data/app/views/bs5/examples/buttons/button_to/default/_example.html.erb +2 -0
  44. data/app/views/bs5/examples/buttons/button_to/default/snippet.html.erb +11 -0
  45. data/app/views/bs5/examples/close_button/default/_example.html.erb +2 -0
  46. data/app/views/bs5/examples/close_button/default/snippet.html.erb +1 -0
  47. data/app/views/bs5/examples/close_button/disabled/_example.html.erb +2 -0
  48. data/app/views/bs5/examples/close_button/disabled/snippet.html.erb +1 -0
  49. data/app/views/bs5/examples/close_button/white/_example.html.erb +2 -0
  50. data/app/views/bs5/examples/close_button/white/snippet.html.erb +1 -0
  51. data/app/views/bs5/examples/index.html.erb +25 -4
  52. data/app/views/bs5/examples/tooltips/default/_example.html.erb +4 -0
  53. data/app/views/bs5/examples/tooltips/default/buttons.html.erb +9 -0
  54. data/app/views/bs5/examples/tooltips/default/disabled_elements.html.erb +3 -0
  55. data/app/views/bs5/examples/tooltips/default/snippet.html.erb +7 -0
  56. data/config/definitions.rb +31 -0
  57. data/config/locales/en.yml +12 -0
  58. data/lib/bs5/version.rb +1 -1
  59. data/lib/generators/bs5/install/install_generator.rb +12 -4
  60. data/lib/generators/bs5/install/templates/bs5.js +14 -0
  61. metadata +44 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 061a536170d6aa6ef8e76633cb5a88db4832d7a79d8096eba5de62e278bd8775
4
- data.tar.gz: 24121455a2fefbc3ebc70a3c70645a33c6a9f46d1303d249adebab639b9648e6
3
+ metadata.gz: 74aab58d89e345e58ed93c1960217477600d6c0bb9c3e9af1dcb3b3542ec55f0
4
+ data.tar.gz: 79c1ddc04689b15bb773de0b99751045f30ffb101acd8ed62e8d816263723f8d
5
5
  SHA512:
6
- metadata.gz: fc2c751f5b54c42761563c5cd08816edfdffa332477eea76290c5f7b344e1e41c5001569785b93311ccb55aa27a1435cbdd5de174594967fcf4b29e1fd77f6f0
7
- data.tar.gz: 0c8a184b0e2ca4cfd24124597f1d16cd4ee8adce371df61f3de58fdad2d4c341f8f906650e0c738a7513364a46c8b99135c3341bc0c39eaeede3b2e9e344bad4
6
+ metadata.gz: 623342435dddb84001b2d70dfd1abc6cf6088b278d2f7c8deb0b11793778fcfcb7e531f5e6c32dcb18865ce918d5bb7a209496577ae486e85304e0d98fc590f3
7
+ data.tar.gz: ba822b14f63cce1ea2be57273aef6014618d1cdab09050a6e842ac8719bf68f7d40b5f04d8a27991f7905700fe35a30b75640d805460599242449b9b7d36cbf6
@@ -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,100 @@
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
+ DEFAULT_STYLE = :primary
7
+ SIZES = { small: :sm, large: :lg }.freeze
8
+ CLASS_PREFIX = 'btn'
9
+
10
+ attr_reader :content_or_options, :size
11
+
12
+ include ActiveModel::Validations
13
+ validates :style, style: true
14
+ validates :size, inclusion: { in: SIZES.keys, valid_sizes: SIZES.keys.to_sentence, allow_nil: true }
15
+
16
+ def initialize(content_or_options = nil, options = nil)
17
+ if content_or_options.is_a? Hash
18
+ self.options = content_or_options
19
+ else
20
+ @content_or_options = content_or_options
21
+ self.options = options
22
+ end
23
+
24
+ extract_custom_options
25
+ merge_default_options
26
+ end
27
+
28
+ def before_render
29
+ raise errors.full_messages.to_sentence if invalid?
30
+ end
31
+
32
+ def call
33
+ button_tag(content || content_or_options, options)
34
+ end
35
+
36
+ private
37
+
38
+ def options=(value)
39
+ @options = Hash(value).symbolize_keys!
40
+ end
41
+
42
+ def options
43
+ @options.empty? ? nil : @options
44
+ end
45
+
46
+ def extract_custom_options
47
+ extract_style
48
+ extract_outline
49
+ extract_size
50
+ end
51
+
52
+ def extract_style
53
+ @style = @options.delete(:style)
54
+ end
55
+
56
+ def extract_outline
57
+ @outline = @options.delete(:outline)
58
+ end
59
+
60
+ def extract_size
61
+ @size = @options.delete(:size)
62
+ end
63
+
64
+ def merge_default_options
65
+ @options.deep_merge!(default_options) do |_key, this_val, other_val|
66
+ [this_val, other_val].join(' ').strip
67
+ end
68
+ end
69
+
70
+ def default_options
71
+ { class: button_class }
72
+ end
73
+
74
+ def button_class
75
+ [CLASS_PREFIX, contextual_class, size_class].compact.join(' ')
76
+ end
77
+
78
+ def contextual_class
79
+ [CLASS_PREFIX, outline? ? 'outline' : nil, style].compact.join('-')
80
+ end
81
+
82
+ def size_class
83
+ return unless size?
84
+
85
+ [CLASS_PREFIX, SIZES[size]].join('-')
86
+ end
87
+
88
+ def style
89
+ (@style || DEFAULT_STYLE).to_sym
90
+ end
91
+
92
+ def outline?
93
+ !!@outline
94
+ end
95
+
96
+ def size?
97
+ !!size
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bs5
4
+ class ButtonToComponent < ViewComponent::Base
5
+ STYLES = %i[primary secondary success danger warning info light dark link].freeze
6
+ DEFAULT_STYLE = :primary
7
+ SIZES = { small: :sm, large: :lg }.freeze
8
+ CLASS_PREFIX = 'btn'
9
+
10
+ attr_reader :size
11
+
12
+ include ActiveModel::Validations
13
+ validates :style, style: true
14
+ validates :size, inclusion: { in: SIZES.keys, valid_sizes: SIZES.keys.to_sentence, allow_nil: true }
15
+
16
+ def initialize(name = nil, options = nil, html_options = nil)
17
+ @name = name
18
+ @options = options
19
+ @html_options = html_options
20
+
21
+ set_button_to_options
22
+ extract_custom_options
23
+ merge_default_options
24
+ end
25
+
26
+ def before_render
27
+ raise errors.full_messages.to_sentence if invalid?
28
+ end
29
+
30
+ def call
31
+ if content
32
+ button_to(@name, @options, @html_options) { content }
33
+ else
34
+ button_to(@name, @options, @html_options)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def set_button_to_options
41
+ if @name.is_a? Hash
42
+ self.button_to_options = @name
43
+ elsif @options.is_a? Hash
44
+ self.button_to_options = @options
45
+ else
46
+ @html_options ||= {}
47
+ self.button_to_options = @html_options
48
+ end
49
+ end
50
+
51
+ def button_to_options=(hash)
52
+ @button_to_options = hash.symbolize_keys!
53
+ end
54
+
55
+ def extract_custom_options
56
+ extract_style
57
+ extract_outline
58
+ extract_size
59
+ end
60
+
61
+ def extract_style
62
+ @style = @button_to_options.delete(:style)
63
+ end
64
+
65
+ def extract_outline
66
+ @outline = @button_to_options.delete(:outline)
67
+ end
68
+
69
+ def extract_size
70
+ @size = @button_to_options.delete(:size)
71
+ end
72
+
73
+ def merge_default_options
74
+ @button_to_options.deep_merge!(default_options) do |_key, this_val, other_val|
75
+ [this_val, other_val].join(' ').strip
76
+ end
77
+ end
78
+
79
+ def default_options
80
+ { class: button_class }
81
+ end
82
+
83
+ def button_class
84
+ [CLASS_PREFIX, contextual_class, size_class].compact.join(' ')
85
+ end
86
+
87
+ def contextual_class
88
+ [CLASS_PREFIX, outline? ? 'outline' : nil, style].compact.join('-')
89
+ end
90
+
91
+ def size_class
92
+ return unless size?
93
+
94
+ [CLASS_PREFIX, SIZES[size]].join('-')
95
+ end
96
+
97
+ def style
98
+ (@style || DEFAULT_STYLE).to_sym
99
+ end
100
+
101
+ def outline?
102
+ !!@outline
103
+ end
104
+
105
+ def size?
106
+ !!size
107
+ end
108
+ end
109
+ end
@@ -2,24 +2,30 @@
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 button_to].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
+ def bs5_tooltip(title, options = nil)
15
+ default_options = { toggle: :tooltip }
16
+ options = Hash(options).symbolize_keys.merge(default_options)
17
+ {
18
+ title: title,
19
+ data: options
20
+ }
19
21
  end
20
22
 
21
- def bs5_close_button(*args)
22
- render CloseButtonComponent.new(*args)
23
+ private
24
+
25
+ def render_component(component_clazz, *args)
26
+ render component_clazz.new(*args) do |c|
27
+ yield c if block_given?
28
+ end
23
29
  end
24
30
  end
25
31
  end
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class StyleValidator < ActiveModel::EachValidator
4
- STYLES = %i[primary secondary success danger warning info light dark].freeze
5
-
6
4
  def validate_each(record, attribute, value)
7
- return if value.in?(STYLES)
5
+ return if value.in?(valid_styles = record.class::STYLES)
8
6
 
9
- record.errors.add(attribute, :inclusion, valid_styles: STYLES.to_sentence)
7
+ record.errors.add(attribute, :inclusion, valid_styles: valid_styles.to_sentence)
10
8
  end
11
9
  end
@@ -1,4 +1,5 @@
1
1
  <h2>Alert</h2>
2
2
  <%= render 'bs5/examples/alert/default/example' %>
3
3
  <%= render 'bs5/examples/alert/style/example' %>
4
+ <%= render 'bs5/examples/alert/additional_content/example' %>
4
5
  <%= render 'bs5/examples/alert/dismissable/example' %>
@@ -0,0 +1,2 @@
1
+ <h2>Breadcrumb</h2>
2
+ <%= render 'bs5/examples/breadcrumb/default/example' %>
@@ -0,0 +1,11 @@
1
+ <h2>Buttons</h2>
2
+ <h3>Decorating Rails' <code>button_tag</code></h3>
3
+ <%= render 'bs5/examples/buttons/button_tag/default/example' %>
4
+ <%= render 'bs5/examples/buttons/button_tag/style/example' %>
5
+ <%= render 'bs5/examples/buttons/button_tag/outline/example' %>
6
+ <%= render 'bs5/examples/buttons/button_tag/size/example' %>
7
+ <%= render 'bs5/examples/buttons/button_tag/block_buttons/example' %>
8
+ <%= render 'bs5/examples/buttons/button_tag/toggle_states/example' %>
9
+
10
+ <h3>Decorating Rails' <code>button_to</code></h3>
11
+ <%= render 'bs5/examples/buttons/button_to/default/example' %>
@@ -0,0 +1,4 @@
1
+ <h2>Close button</h2>
2
+ <%= render 'bs5/examples/close_button/default/example' %>
3
+ <%= render 'bs5/examples/close_button/disabled/example' %>
4
+ <%= render 'bs5/examples/close_button/white/example' %>
@@ -0,0 +1,2 @@
1
+ <h2>Tooltips</h2>
2
+ <%= render 'bs5/examples/tooltips/default/example' %>
@@ -0,0 +1,2 @@
1
+ <h3>Additional content</h3>
2
+ <%= bs5_example(snippet: 'alert/additional_content/snippet') %>
@@ -0,0 +1,6 @@
1
+ <%= bs5_alert(style: :success) do %>
2
+ <h4 class="alert-heading">Well done!</h4>
3
+ <p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
4
+ <hr>
5
+ <p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
6
+ <%- end %>
@@ -1,2 +1,2 @@
1
- <h3>Dismissable</h3>
1
+ <h3>Dismissing</h3>
2
2
  <%= bs5_example(snippet: 'alert/dismissable/snippet') %>
@@ -1,3 +1,31 @@
1
+ <%= bs5_alert(style: :primary) do %>
2
+ A simple primary alert—check it out!
3
+ <%- end %>
4
+
5
+ <%= bs5_alert(style: :secondary) do %>
6
+ A simple secondary alert—check it out!
7
+ <%- end %>
8
+
9
+ <%= bs5_alert(style: :success) do %>
10
+ A simple success alert—check it out!
11
+ <%- end %>
12
+
1
13
  <%= bs5_alert(style: :danger) do %>
2
14
  A simple danger alert—check it out!
15
+ <%- end %>
16
+
17
+ <%= bs5_alert(style: :warning) do %>
18
+ A simple warning alert—check it out!
19
+ <%- end %>
20
+
21
+ <%= bs5_alert(style: :info) do %>
22
+ A simple info alert—check it out!
23
+ <%- end %>
24
+
25
+ <%= bs5_alert(style: :light) do %>
26
+ A simple light alert—check it out!
27
+ <%- end %>
28
+
29
+ <%= bs5_alert(style: :dark) do %>
30
+ A simple dark alert—check it out!
3
31
  <%- end %>
@@ -1,2 +1,2 @@
1
- <h3>Default</h3>
1
+ <h3>Example</h3>
2
2
  <%= bs5_example(snippet: 'badge/default/snippet') %>
@@ -1 +1,6 @@
1
- <%= bs5_badge(text: 'New') %>
1
+ <h1>Example heading <%= bs5_badge(text: 'New') %></h1>
2
+ <h2>Example heading <%= bs5_badge(text: 'New') %></h2>
3
+ <h3>Example heading <%= bs5_badge(text: 'New') %></h3>
4
+ <h4>Example heading <%= bs5_badge(text: 'New') %></h4>
5
+ <h5>Example heading <%= bs5_badge(text: 'New') %></h5>
6
+ <h6>Example heading <%= bs5_badge(text: 'New') %></h6>
@@ -1,2 +1,2 @@
1
- <h3>Pill</h3>
1
+ <h3>Pill badges</h3>
2
2
  <%= bs5_example(snippet: 'badge/pill/snippet') %>
@@ -1 +1,8 @@
1
- <%= bs5_badge(text: 'Danger', style: :danger, pill: true) %>
1
+ <%= bs5_badge(text: 'Primary', style: :primary, pill: true) %>
2
+ <%= bs5_badge(text: 'Secondary', style: :secondary, pill: true) %>
3
+ <%= bs5_badge(text: 'Sucess', style: :success, pill: true) %>
4
+ <%= bs5_badge(text: 'Danger', style: :danger, pill: true) %>
5
+ <%= bs5_badge(text: 'Warning', style: :warning, pill: true) %>
6
+ <%= bs5_badge(text: 'Info', style: :info, pill: true) %>
7
+ <%= bs5_badge(text: 'Light', style: :light, pill: true) %>
8
+ <%= bs5_badge(text: 'Dark', style: :dark, pill: true) %>
@@ -1,2 +1,2 @@
1
- <h3>Style</h3>
1
+ <h3>Background colors</h3>
2
2
  <%= bs5_example(snippet: 'badge/style/snippet') %>
@@ -1 +1,8 @@
1
- <%= bs5_badge(text: 'Warning', style: :warning) %>
1
+ <%= bs5_badge(text: 'Primary', style: :primary) %>
2
+ <%= bs5_badge(text: 'Secondary', style: :secondary) %>
3
+ <%= bs5_badge(text: 'Success', style: :success) %>
4
+ <%= bs5_badge(text: 'Danger', style: :danger) %>
5
+ <%= bs5_badge(text: 'Warning', style: :warning) %>
6
+ <%= bs5_badge(text: 'Info', style: :info) %>
7
+ <%= bs5_badge(text: 'Light', style: :light) %>
8
+ <%= bs5_badge(text: 'Dark', style: :dark) %>
@@ -0,0 +1,2 @@
1
+ <h3>Example</h3>
2
+ <%= bs5_example(snippet: 'breadcrumb/default/snippet') %>
@@ -0,0 +1,14 @@
1
+ <%= bs5_breadcrumb do |breadcrumb| %>
2
+ <% breadcrumb.slot(:item) do %>Home<% end %>
3
+ <%- end %>
4
+
5
+ <%= bs5_breadcrumb do |breadcrumb| %>
6
+ <% breadcrumb.slot(:item) do %><a href="#">Home</a><% end %>
7
+ <% breadcrumb.slot(:item) do %>Library<% end %>
8
+ <%- end %>
9
+
10
+ <%= bs5_breadcrumb do |breadcrumb| %>
11
+ <% breadcrumb.slot(:item) do %><a href="#">Home</a><% end %>
12
+ <% breadcrumb.slot(:item) do %><a href="#">Library</a><% end %>
13
+ <% breadcrumb.slot(:item) do %>Data<% end %>
14
+ <%- end %>
@@ -0,0 +1,5 @@
1
+ <h3>Block buttons</h3>
2
+ <%= bs5_example(snippet: 'buttons/button_tag/block_buttons/block_buttons') %>
3
+ <%= bs5_example(snippet: 'buttons/button_tag/block_buttons/responsive_block_buttons_1') %>
4
+ <%= bs5_example(snippet: 'buttons/button_tag/block_buttons/responsive_block_buttons_2') %>
5
+ <%= bs5_example(snippet: 'buttons/button_tag/block_buttons/responsive_block_buttons_3') %>
@@ -0,0 +1,4 @@
1
+ <div class="d-grid gap-2">
2
+ <%= bs5_button_tag %>
3
+ <%= bs5_button_tag %>
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div class="d-grid gap-2 d-md-block">
2
+ <%= bs5_button_tag %>
3
+ <%= bs5_button_tag %>
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div class="d-grid gap-2 col-6 mx-auto">
2
+ <%= bs5_button_tag %>
3
+ <%= bs5_button_tag %>
4
+ </div>
@@ -0,0 +1,4 @@
1
+ <div class="d-grid gap-2 d-md-flex justify-content-md-end">
2
+ <%= bs5_button_tag('Button', class: 'mr-md-2') %>
3
+ <%= bs5_button_tag %>
4
+ </div>
@@ -0,0 +1,2 @@
1
+ <h3>Example</h3>
2
+ <%= bs5_example(snippet: 'buttons/button_tag/default/snippet') %>
@@ -0,0 +1,15 @@
1
+ <%= bs5_button_tag %>
2
+
3
+ <%= bs5_button_tag 'Reset', type: 'reset' %>
4
+
5
+ <%= bs5_button_tag 'Button', type: 'button' %>
6
+
7
+ <%= bs5_button_tag 'Reset', type: 'reset', disabled: true %>
8
+
9
+ <%= bs5_button_tag(type: 'button') do %>
10
+ <%= content_tag(:strong, 'Ask me!') %>
11
+ <% end %>
12
+
13
+ <%= bs5_button_tag 'Save', data: { confirm: 'Are you sure?' } %>
14
+
15
+ <%= bs5_button_tag 'Checkout', data: { disable_with: 'Please wait...' } %>
@@ -0,0 +1,2 @@
1
+ <h3>Outline</h3>
2
+ <%= bs5_example(snippet: 'buttons/button_tag/outline/snippet') %>
@@ -0,0 +1,19 @@
1
+ <%= bs5_button_tag 'Primary', style: :primary, outline: true %>
2
+
3
+ <%= bs5_button_tag 'Secondary', style: :secondary, outline: true %>
4
+
5
+ <%= bs5_button_tag 'Success', style: :success, outline: true %>
6
+
7
+ <%= bs5_button_tag 'Danger', style: :danger, outline: true %>
8
+
9
+ <%= bs5_button_tag(style: :warning, outline: true, type: 'button') do %>
10
+ <%= content_tag(:strong, 'Warning') %>
11
+ <% end %>
12
+
13
+ <%= bs5_button_tag 'Info', style: :info, outline: true %>
14
+
15
+ <%= bs5_button_tag 'Light', style: :light, outline: true %>
16
+
17
+ <%= bs5_button_tag 'Dark', style: :dark, outline: true %>
18
+
19
+ <%= bs5_button_tag 'Link', style: :link, outline: true %>
@@ -0,0 +1,3 @@
1
+ <h3>Sizes</h3>
2
+ <%= bs5_example(snippet: 'buttons/button_tag/size/large') %>
3
+ <%= bs5_example(snippet: 'buttons/button_tag/size/small') %>
@@ -0,0 +1,3 @@
1
+ <%= bs5_button_tag 'Large button', style: :primary, size: :large %>
2
+
3
+ <%= bs5_button_tag 'Large button', style: :secondary, size: :large %>
@@ -0,0 +1,3 @@
1
+ <%= bs5_button_tag 'Small button', style: :primary, size: :small %>
2
+
3
+ <%= bs5_button_tag 'Small button', style: :secondary, size: :small %>
@@ -0,0 +1,2 @@
1
+ <h3>Style</h3>
2
+ <%= bs5_example(snippet: 'buttons/button_tag/style/snippet') %>
@@ -0,0 +1,19 @@
1
+ <%= bs5_button_tag 'Primary', style: :primary %>
2
+
3
+ <%= bs5_button_tag 'Secondary', style: :secondary %>
4
+
5
+ <%= bs5_button_tag 'Success', style: :success %>
6
+
7
+ <%= bs5_button_tag 'Danger', style: :danger %>
8
+
9
+ <%= bs5_button_tag(style: :warning, type: 'button') do %>
10
+ <%= content_tag(:strong, 'Warning') %>
11
+ <% end %>
12
+
13
+ <%= bs5_button_tag 'Info', style: :info %>
14
+
15
+ <%= bs5_button_tag 'Light', style: :light %>
16
+
17
+ <%= bs5_button_tag 'Dark', style: :dark %>
18
+
19
+ <%= bs5_button_tag 'Link', style: :link %>
@@ -0,0 +1,2 @@
1
+ <h3>Toggle states</h3>
2
+ <%= bs5_example(snippet: 'buttons/button_tag/toggle_states/snippet') %>
@@ -0,0 +1,3 @@
1
+ <%= bs5_button_tag('Toggle button', data: { toggle: 'button' }, autocomplete: 'off') %>
2
+ <%= bs5_button_tag('Active toggle button', class: 'active', data: { toggle: 'button' }, autocomplete: 'off', aria: { pressed: true }) %>
3
+ <%= bs5_button_tag('Disabled toggle button', data: { toggle: 'button' }, autocomplete: 'off', disabled: true) %>
@@ -0,0 +1,2 @@
1
+ <h3>Example</h3>
2
+ <%= bs5_example(snippet: 'buttons/button_to/default/snippet') %>
@@ -0,0 +1,11 @@
1
+ <div class="d-grid gap-2 d-md-flex">
2
+ <%= bs5_button_to('New', 'http://www.example.com') %>
3
+
4
+ <%= bs5_button_to('http://www.example.com', style: :success) do %>
5
+ Make happy <strong>John Doe</strong>
6
+ <%- end %>
7
+
8
+ <%= bs5_button_to('New', 'http://www.example.com', style: :dark, outline: true, size: :large, form_class: 'new-thing') %>
9
+
10
+ <%= bs5_button_to('Destroy', 'http://www.example.com', style: :danger, method: "delete", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %>
11
+ </div>
@@ -0,0 +1,2 @@
1
+ <h3>Default</h3>
2
+ <%= bs5_example(snippet: 'close_button/default/snippet') %>
@@ -0,0 +1 @@
1
+ <%= bs5_close_button %>
@@ -0,0 +1,2 @@
1
+ <h3>Disabled</h3>
2
+ <%= bs5_example(snippet: 'close_button/disabled/snippet') %>
@@ -0,0 +1 @@
1
+ <%= bs5_close_button(disabled: true) %>
@@ -0,0 +1,2 @@
1
+ <h3>White</h3>
2
+ <%= bs5_example(snippet: 'close_button/white/snippet') %>
@@ -0,0 +1 @@
1
+ <%= bs5_close_button(white: true) %>
@@ -1,4 +1,25 @@
1
- <h1>Bootstrap Examples</h1>
2
- <%= render 'accordion' %>
3
- <%= render 'alert' %>
4
- <%= render 'badge' %>
1
+ <div class="row">
2
+ <div class="col">
3
+ <div class="sticky-top">
4
+ <ul class="nav flex-column">
5
+ <li>Accordion</li>
6
+ <li>Alert</li>
7
+ <li>Badge</li>
8
+ <li>Close button</li>
9
+ <li>Breadcrumb</li>
10
+ <li>Buttons</li>
11
+ <li>Tooltips</li>
12
+ </ul>
13
+ </div>
14
+ </div>
15
+ <div class="col-10">
16
+ <h1>Bootstrap Examples</h1>
17
+ <%= render 'accordion' %>
18
+ <%= render 'alert' %>
19
+ <%= render 'badge' %>
20
+ <%= render 'close_button' %>
21
+ <%= render 'breadcrumb' %>
22
+ <%= render 'buttons' %>
23
+ <%= render 'tooltips' %>
24
+ </div>
25
+ </div>
@@ -0,0 +1,4 @@
1
+ <h3>Default</h3>
2
+ <%= bs5_example(snippet: 'tooltips/default/snippet') %>
3
+ <%= bs5_example(snippet: 'tooltips/default/buttons') %>
4
+ <%= bs5_example(snippet: 'tooltips/default/disabled_elements') %>
@@ -0,0 +1,9 @@
1
+ <%= bs5_button_tag('Tooltip on top', bs5_tooltip('Tooltip on top', placement: :top).merge(style: :secondary)) %>
2
+
3
+ <%= bs5_button_tag('Tooltip on right', bs5_tooltip('Tooltip on right', placement: :right).merge(style: :secondary)) %>
4
+
5
+ <%= bs5_button_tag('Tooltip on bottom', bs5_tooltip('Tooltip on bottom', placement: :bottom).merge(style: :secondary)) %>
6
+
7
+ <%= bs5_button_tag('Tooltip on left', bs5_tooltip('Tooltip on left', placement: :left).merge(style: :secondary)) %>
8
+
9
+ <%= bs5_button_tag('Tooltip with HTML', bs5_tooltip('<em>Tooltip</em> <u>with</u> <b>HTML</b>', html: :true).merge(style: :secondary)) %>
@@ -0,0 +1,3 @@
1
+ <%= tag.span(bs5_tooltip('Disabled tooltip').merge(class: 'd-inline-block', tabindex: 0)) do %>
2
+ <%= bs5_button_tag('Disabled button', disabled: true) %>
3
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <p class="muted">
2
+ Tight pants next level keffiyeh <%= link_to('you probably', '#', bs5_tooltip('Default tooltip')) %> haven't heard of them.
3
+ Photo booth beard raw denim letterpress vegan messenger bag stumptown.
4
+ Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel <%= link_to('have a', '#', bs5_tooltip('Another tooltip')) %> terry richardson vinyl chambray.
5
+ Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray.
6
+ A really ironic artisan <%= link_to('whatever keytar', '#', bs5_tooltip('Another one here too')) %>, scenester farm-to-table banksy Austin <%= link_to('twitter handle', '#', bs5_tooltip('The last tip!')) %> freegan cred raw denim single-origin coffee viral.
7
+ </p>
@@ -0,0 +1,31 @@
1
+ # The following comments fill some of the gaps in Solargraph's understanding of
2
+ # Rails apps. Since they're all in YARD, they get mapped in Solargraph but
3
+ # ignored at runtime.
4
+ #
5
+ # You can put this file anywhere in the project, as long as it gets included in
6
+ # the workspace maps. It's recommended that you keep it in a standalone file
7
+ # instead of pasting it into an existing one.
8
+ #
9
+ # @!parse
10
+ # class ActionController::Base
11
+ # include ActionController::MimeResponds
12
+ # extend ActiveSupport::Callbacks::ClassMethods
13
+ # extend AbstractController::Callbacks::ClassMethods
14
+ # end
15
+ # class ActiveRecord::Base
16
+ # extend ActiveRecord::QueryMethods
17
+ # extend ActiveRecord::FinderMethods
18
+ # extend ActiveRecord::Associations::ClassMethods
19
+ # extend ActiveRecord::Inheritance::ClassMethods
20
+ # include ActiveRecord::Persistence
21
+ # end
22
+ # @!override ActiveRecord::FinderMethods#find
23
+ # @overload find(id)
24
+ # @param id [Integer]
25
+ # @return [self]
26
+ # @overload find(list)
27
+ # @param list [Array]
28
+ # @return [Array<self>]
29
+ # @overload find(*args)
30
+ # @return [Array<self>]
31
+ # @return [self, Array<self>]
@@ -6,3 +6,15 @@ en:
6
6
  attributes:
7
7
  style:
8
8
  inclusion: "is not included in the list: %{valid_styles}."
9
+ bs5/button_tag_component:
10
+ attributes:
11
+ style:
12
+ inclusion: "is not included in the list: %{valid_styles}."
13
+ size:
14
+ inclusion: "is not included in the list: %{valid_sizes}."
15
+ bs5/button_to_component:
16
+ attributes:
17
+ style:
18
+ inclusion: "is not included in the list: %{valid_styles}."
19
+ size:
20
+ inclusion: "is not included in the list: %{valid_sizes}."
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bs5
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.12'
5
5
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Bs5
4
4
  class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('templates', __dir__)
6
+
5
7
  def add_bootstrap # rubocop:disable Metrics/MethodLength
6
8
  run 'yarn add bootstrap@next popper.js'
7
9
 
@@ -9,6 +11,16 @@ module Bs5
9
11
  @import "~bootstrap/scss/bootstrap";
10
12
  HEREDOC
11
13
 
14
+ copy_file 'bs5.js', 'app/javascript/bs5.js'
15
+
16
+ append_file 'app/javascript/packs/application.js', <<~HEREDOC
17
+ import * as bs5 from "bs5";
18
+
19
+ document.addEventListener("turbolinks:load", function () {
20
+ bs5.start();
21
+ });
22
+ HEREDOC
23
+
12
24
  inject_into_file 'app/views/layouts/application.html.erb', before: '</head>' do
13
25
  <<~HEREDOC
14
26
  <%= stylesheet_pack_tag 'styles', media: 'all', 'data-turbolinks-track': 'reload' %>
@@ -27,10 +39,6 @@ module Bs5
27
39
  HEREDOC
28
40
  end
29
41
 
30
- append_file 'app/javascript/packs/application.js', <<~HEREDOC
31
- import "bootstrap";
32
- HEREDOC
33
-
34
42
  gsub_file 'config/webpacker.yml', 'extract_css: false', 'extract_css: true'
35
43
  end
36
44
  end
@@ -0,0 +1,14 @@
1
+ import * as bootstrap from "bootstrap";
2
+
3
+ function tooltipify() {
4
+ const tooltipTriggerList = [].slice.call(
5
+ document.querySelectorAll('[data-toggle="tooltip"]')
6
+ );
7
+ tooltipTriggerList.map(function (tooltipTriggerEl) {
8
+ return new bootstrap.Tooltip(tooltipTriggerEl);
9
+ });
10
+ }
11
+
12
+ export function start() {
13
+ tooltipify();
14
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bs5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Baselier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-21 00:00:00.000000000 Z
11
+ date: 2020-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -132,6 +132,10 @@ files:
132
132
  - app/components/bs5/alert_component.rb
133
133
  - app/components/bs5/badge_component.html.erb
134
134
  - app/components/bs5/badge_component.rb
135
+ - app/components/bs5/breadcrumb_component.html.erb
136
+ - app/components/bs5/breadcrumb_component.rb
137
+ - app/components/bs5/button_tag_component.rb
138
+ - app/components/bs5/button_to_component.rb
135
139
  - app/components/bs5/close_button_component.html.erb
136
140
  - app/components/bs5/close_button_component.rb
137
141
  - app/components/bs5/example_component.html.erb
@@ -146,10 +150,16 @@ files:
146
150
  - app/views/bs5/examples/_accordion.html.erb
147
151
  - app/views/bs5/examples/_alert.html.erb
148
152
  - app/views/bs5/examples/_badge.html.erb
153
+ - app/views/bs5/examples/_breadcrumb.html.erb
154
+ - app/views/bs5/examples/_buttons.html.erb
155
+ - app/views/bs5/examples/_close_button.html.erb
156
+ - app/views/bs5/examples/_tooltips.html.erb
149
157
  - app/views/bs5/examples/accordion/default/_example.html.erb
150
158
  - app/views/bs5/examples/accordion/default/snippet.html.erb
151
159
  - app/views/bs5/examples/accordion/flush/_example.html.erb
152
160
  - app/views/bs5/examples/accordion/flush/snippet.html.erb
161
+ - app/views/bs5/examples/alert/additional_content/_example.html.erb
162
+ - app/views/bs5/examples/alert/additional_content/snippet.html.erb
153
163
  - app/views/bs5/examples/alert/default/_example.html.erb
154
164
  - app/views/bs5/examples/alert/default/snippet.html.erb
155
165
  - app/views/bs5/examples/alert/dismissable/_example.html.erb
@@ -162,8 +172,39 @@ files:
162
172
  - app/views/bs5/examples/badge/pill/snippet.html.erb
163
173
  - app/views/bs5/examples/badge/style/_example.html.erb
164
174
  - app/views/bs5/examples/badge/style/snippet.html.erb
175
+ - app/views/bs5/examples/breadcrumb/default/_example.html.erb
176
+ - app/views/bs5/examples/breadcrumb/default/snippet.html.erb
177
+ - app/views/bs5/examples/buttons/button_tag/block_buttons/_example.html.erb
178
+ - app/views/bs5/examples/buttons/button_tag/block_buttons/block_buttons.html.erb
179
+ - app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_1.html.erb
180
+ - app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_2.html.erb
181
+ - app/views/bs5/examples/buttons/button_tag/block_buttons/responsive_block_buttons_3.html.erb
182
+ - app/views/bs5/examples/buttons/button_tag/default/_example.html.erb
183
+ - app/views/bs5/examples/buttons/button_tag/default/snippet.html.erb
184
+ - app/views/bs5/examples/buttons/button_tag/outline/_example.html.erb
185
+ - app/views/bs5/examples/buttons/button_tag/outline/snippet.html.erb
186
+ - app/views/bs5/examples/buttons/button_tag/size/_example.html.erb
187
+ - app/views/bs5/examples/buttons/button_tag/size/large.html.erb
188
+ - app/views/bs5/examples/buttons/button_tag/size/small.html.erb
189
+ - app/views/bs5/examples/buttons/button_tag/style/_example.html.erb
190
+ - app/views/bs5/examples/buttons/button_tag/style/snippet.html.erb
191
+ - app/views/bs5/examples/buttons/button_tag/toggle_states/_example.html.erb
192
+ - app/views/bs5/examples/buttons/button_tag/toggle_states/snippet.html.erb
193
+ - app/views/bs5/examples/buttons/button_to/default/_example.html.erb
194
+ - app/views/bs5/examples/buttons/button_to/default/snippet.html.erb
195
+ - app/views/bs5/examples/close_button/default/_example.html.erb
196
+ - app/views/bs5/examples/close_button/default/snippet.html.erb
197
+ - app/views/bs5/examples/close_button/disabled/_example.html.erb
198
+ - app/views/bs5/examples/close_button/disabled/snippet.html.erb
199
+ - app/views/bs5/examples/close_button/white/_example.html.erb
200
+ - app/views/bs5/examples/close_button/white/snippet.html.erb
165
201
  - app/views/bs5/examples/index.html.erb
202
+ - app/views/bs5/examples/tooltips/default/_example.html.erb
203
+ - app/views/bs5/examples/tooltips/default/buttons.html.erb
204
+ - app/views/bs5/examples/tooltips/default/disabled_elements.html.erb
205
+ - app/views/bs5/examples/tooltips/default/snippet.html.erb
166
206
  - app/views/layouts/bs5/application.html.erb
207
+ - config/definitions.rb
167
208
  - config/locales/en.yml
168
209
  - config/routes.rb
169
210
  - lib/bs5.rb
@@ -171,6 +212,7 @@ files:
171
212
  - lib/bs5/version.rb
172
213
  - lib/generators/bs5/install/USAGE
173
214
  - lib/generators/bs5/install/install_generator.rb
215
+ - lib/generators/bs5/install/templates/bs5.js
174
216
  - lib/tasks/bs5_tasks.rake
175
217
  - lib/tasks/ci.rake
176
218
  - lib/tasks/rubocop.rake