bs5 0.0.5 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -112
- data/app/components/bs5/alert_component.rb +2 -0
- data/app/components/bs5/badge_component.rb +2 -0
- data/app/components/bs5/breadcrumb_component.html.erb +9 -0
- data/app/components/bs5/breadcrumb_component.rb +12 -0
- data/app/components/bs5/button_tag_component.rb +104 -0
- data/app/components/bs5/example_component.html.erb +8 -0
- data/app/components/bs5/example_component.rb +44 -0
- data/app/controllers/bs5/application_controller.rb +9 -0
- data/app/controllers/bs5/examples_controller.rb +9 -0
- data/app/helpers/bs5/application_helper.rb +2 -0
- data/app/helpers/bs5/components_helper.rb +10 -13
- data/app/helpers/bs5/examples_helper.rb +9 -0
- data/app/models/bs5/application_record.rb +2 -0
- data/app/validators/style_validator.rb +2 -4
- data/app/views/bs5/examples/_accordion.html.erb +3 -0
- data/app/views/bs5/examples/_alert.html.erb +5 -0
- data/app/views/bs5/examples/_badge.html.erb +4 -0
- data/app/views/bs5/examples/_breadcrumb.html.erb +2 -0
- data/app/views/bs5/examples/_buttons.html.erb +7 -0
- data/app/views/bs5/examples/_close_button.html.erb +4 -0
- data/app/views/bs5/examples/accordion/default/_example.html.erb +2 -0
- data/app/views/bs5/examples/accordion/default/snippet.html.erb +11 -0
- data/app/views/bs5/examples/accordion/flush/_example.html.erb +2 -0
- data/app/views/bs5/examples/accordion/flush/snippet.html.erb +11 -0
- data/app/views/bs5/examples/alert/additional_content/_example.html.erb +2 -0
- data/app/views/bs5/examples/alert/additional_content/snippet.html.erb +6 -0
- data/app/views/bs5/examples/alert/default/_example.html.erb +2 -0
- data/app/views/bs5/examples/alert/default/snippet.html.erb +3 -0
- data/app/views/bs5/examples/alert/dismissable/_example.html.erb +2 -0
- data/app/views/bs5/examples/alert/dismissable/snippet.html.erb +3 -0
- data/app/views/bs5/examples/alert/style/_example.html.erb +2 -0
- data/app/views/bs5/examples/alert/style/snippet.html.erb +31 -0
- data/app/views/bs5/examples/badge/default/_example.html.erb +2 -0
- data/app/views/bs5/examples/badge/default/snippet.html.erb +6 -0
- data/app/views/bs5/examples/badge/pill/_example.html.erb +2 -0
- data/app/views/bs5/examples/badge/pill/snippet.html.erb +8 -0
- data/app/views/bs5/examples/badge/style/_example.html.erb +2 -0
- data/app/views/bs5/examples/badge/style/snippet.html.erb +8 -0
- data/app/views/bs5/examples/breadcrumb/default/_example.html.erb +2 -0
- data/app/views/bs5/examples/breadcrumb/default/snippet.html.erb +14 -0
- data/app/views/bs5/examples/buttons/block_buttons/_example.html.erb +5 -0
- data/app/views/bs5/examples/buttons/block_buttons/block_buttons.html.erb +4 -0
- data/app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_1.html.erb +4 -0
- data/app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_2.html.erb +4 -0
- data/app/views/bs5/examples/buttons/block_buttons/responsive_block_buttons_3.html.erb +4 -0
- data/app/views/bs5/examples/buttons/default/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/default/snippet.html.erb +15 -0
- data/app/views/bs5/examples/buttons/outline/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/outline/snippet.html.erb +19 -0
- data/app/views/bs5/examples/buttons/size/_example.html.erb +3 -0
- data/app/views/bs5/examples/buttons/size/large.html.erb +3 -0
- data/app/views/bs5/examples/buttons/size/small.html.erb +3 -0
- data/app/views/bs5/examples/buttons/style/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/style/snippet.html.erb +19 -0
- data/app/views/bs5/examples/buttons/toggle_states/_example.html.erb +2 -0
- data/app/views/bs5/examples/buttons/toggle_states/snippet.html.erb +3 -0
- data/app/views/bs5/examples/close_button/default/_example.html.erb +2 -0
- data/app/views/bs5/examples/close_button/default/snippet.html.erb +1 -0
- data/app/views/bs5/examples/close_button/disabled/_example.html.erb +2 -0
- data/app/views/bs5/examples/close_button/disabled/snippet.html.erb +1 -0
- data/app/views/bs5/examples/close_button/white/_example.html.erb +2 -0
- data/app/views/bs5/examples/close_button/white/snippet.html.erb +1 -0
- data/app/views/bs5/examples/index.html.erb +23 -0
- data/app/views/layouts/bs5/application.html.erb +6 -7
- data/config/definitions.rb +31 -0
- data/config/locales/en.yml +6 -0
- data/config/routes.rb +5 -0
- data/lib/bs5.rb +3 -1
- data/lib/bs5/version.rb +1 -1
- data/lib/generators/bs5/install/install_generator.rb +28 -20
- data/lib/tasks/bs5_tasks.rake +1 -0
- data/lib/tasks/ci.rake +3 -0
- data/lib/tasks/rubocop.rake +5 -0
- metadata +100 -15
- data/app/jobs/bs5/application_job.rb +0 -4
- data/app/mailers/bs5/application_mailer.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecb9af880ad8e465272d743689c0c470af8c322affb3e77be49bdb360f8b0022
|
4
|
+
data.tar.gz: 3b1517ef64015fa58510b9123cd625735d79e2e7fbbccda4eb161f1f4671e038
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b638dd6760619921caaa399a585a53040501cdb796712c5bf118cc281f5ba65f16637dde70df784adff66839c2b71b91488c64bcd46a0045cc949e82cf8ba995
|
7
|
+
data.tar.gz: f5b36b7a285aad9a6eb2e803d182d5e4126398ae410c9cb2a6dd66674de9474da84ba1db4f6c2202730a6f0b255a3df71762074fb8315c74711f457d3a9331a2
|
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,117 +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](#accordion) ✅
|
40
|
-
- [Alert](#alert) ✅
|
41
|
-
- [Badge](#badge) ✅
|
42
|
-
- Breadcrumb
|
43
|
-
- Buttons
|
44
|
-
- Button group
|
45
|
-
- Card
|
46
|
-
- Carousel
|
47
|
-
- [Close button](#close-button) ✅
|
48
|
-
- Collapse
|
49
|
-
- Dropdowns
|
50
|
-
- List group
|
51
|
-
- Modal
|
52
|
-
- Nav & tabs
|
53
|
-
- Navbar
|
54
|
-
- Pagination
|
55
|
-
- Popovers
|
56
|
-
- Progress
|
57
|
-
- Scrollspy
|
58
|
-
- Spinners
|
59
|
-
- Toasts
|
60
|
-
- Tooltips
|
61
|
-
|
62
|
-
|
63
|
-
### [Accordion](https://v5.getbootstrap.com/docs/5.0/components/accordion/)
|
64
|
-
|
65
|
-
```
|
66
|
-
<%= bs5_accordion do |accordion| %>
|
67
|
-
<% accordion.slot(:item, title: 'Accordion Item #1', collapsed: false) do %>
|
68
|
-
<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.
|
69
|
-
<% end %>
|
70
|
-
<% accordion.slot(:item, title: 'Accordion Item #2') do %>
|
71
|
-
<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.
|
72
|
-
<% end %>
|
73
|
-
<% accordion.slot(:item, title: 'Accordion Item #3') do %>
|
74
|
-
<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.
|
75
|
-
<% end %>
|
76
|
-
<%- end %>
|
77
|
-
```
|
78
|
-
|
79
|
-
```
|
80
|
-
<%= bs5_accordion(flush: true) do |accordion| %>
|
81
|
-
<% accordion.slot(:item, title: 'Accordion Item #1') do %>
|
82
|
-
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.
|
83
|
-
<% end %>
|
84
|
-
<% accordion.slot(:item, title: 'Accordion Item #2') do %>
|
85
|
-
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.
|
86
|
-
<% end %>
|
87
|
-
<% accordion.slot(:item, title: 'Accordion Item #3') do %>
|
88
|
-
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.
|
89
|
-
<% end %>
|
90
|
-
<%- end %>
|
91
|
-
```
|
92
|
-
|
93
|
-
### [Alert](https://v5.getbootstrap.com/docs/5.0/components/alerts/)
|
94
|
-
|
95
|
-
```
|
96
|
-
<%= bs5_alert do %>
|
97
|
-
A simple primary alert—check it out!
|
98
|
-
<%- end %>
|
99
|
-
```
|
100
|
-
|
101
|
-
```
|
102
|
-
<%= bs5_alert(style: :warning, is_dismissable: true) do %>
|
103
|
-
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
|
104
|
-
<%- end %>
|
105
|
-
```
|
106
|
-
|
107
|
-
### [Badge](https://v5.getbootstrap.com/docs/5.0/components/badge/)
|
108
|
-
|
109
|
-
```
|
110
|
-
<%= bs5_badge(text: 'New') %>
|
111
|
-
```
|
112
|
-
|
113
|
-
```
|
114
|
-
<%= bs5_badge(text: 'Warning', style: :warning) %>
|
115
|
-
```
|
116
|
-
|
117
|
-
```
|
118
|
-
<%= bs5_badge(text: 'Danger', style: :danger, pill: true) %>
|
119
|
-
```
|
120
|
-
|
121
|
-
|
122
|
-
### [Breadcrumb](https://v5.getbootstrap.com/docs/5.0/components/breadcrumb/)
|
123
|
-
|
124
|
-
### [Button](https://v5.getbootstrap.com/docs/5.0/components/buttons/)
|
125
|
-
|
126
|
-
### [Close button](https://v5.getbootstrap.com/docs/5.0/components/close-button/)
|
127
|
-
|
128
|
-
```
|
129
|
-
<%= bs5_close_button %>
|
130
|
-
```
|
131
|
-
|
132
|
-
```
|
133
|
-
<%= bs5_close_button(disabled: true) %>
|
134
|
-
```
|
135
|
-
|
136
|
-
```
|
137
|
-
<%= bs5_close_button(white: true) %>
|
138
|
-
```
|
139
|
-
|
140
|
-
```
|
141
|
-
<%= bs5_close_button(data: { controller: 'hello', action: "click->hello#greet }) %>
|
142
|
-
```
|
143
|
-
|
144
|
-
## Previewing components
|
145
|
-
|
146
|
-
- http://localhost:3000/rails/view_components
|
147
|
-
|
148
37
|
## Contributing
|
149
38
|
|
150
39
|
Contribution directions go here.
|
@@ -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,104 @@
|
|
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
|
+
if content
|
34
|
+
button_tag(content_or_options, options) { content }
|
35
|
+
else
|
36
|
+
button_tag(content_or_options, options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def options=(value)
|
43
|
+
@options = Hash(value).symbolize_keys!
|
44
|
+
end
|
45
|
+
|
46
|
+
def options
|
47
|
+
@options.empty? ? nil : @options
|
48
|
+
end
|
49
|
+
|
50
|
+
def extract_custom_options
|
51
|
+
extract_style
|
52
|
+
extract_outline
|
53
|
+
extract_size
|
54
|
+
end
|
55
|
+
|
56
|
+
def extract_style
|
57
|
+
@style = @options.delete(:style)
|
58
|
+
end
|
59
|
+
|
60
|
+
def extract_outline
|
61
|
+
@outline = @options.delete(:outline)
|
62
|
+
end
|
63
|
+
|
64
|
+
def extract_size
|
65
|
+
@size = @options.delete(:size)
|
66
|
+
end
|
67
|
+
|
68
|
+
def merge_default_options
|
69
|
+
@options.deep_merge!(default_options) do |_key, this_val, other_val|
|
70
|
+
[this_val, other_val].join(' ').strip
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def default_options
|
75
|
+
{ class: button_class }
|
76
|
+
end
|
77
|
+
|
78
|
+
def button_class
|
79
|
+
[CLASS_PREFIX, contextual_class, size_class].compact.join(' ')
|
80
|
+
end
|
81
|
+
|
82
|
+
def contextual_class
|
83
|
+
[CLASS_PREFIX, outline? ? 'outline' : nil, style].compact.join('-')
|
84
|
+
end
|
85
|
+
|
86
|
+
def size_class
|
87
|
+
return unless size?
|
88
|
+
|
89
|
+
[CLASS_PREFIX, SIZES[size]].join('-')
|
90
|
+
end
|
91
|
+
|
92
|
+
def style
|
93
|
+
(@style || DEFAULT_STYLE).to_sym
|
94
|
+
end
|
95
|
+
|
96
|
+
def outline?
|
97
|
+
!!@outline
|
98
|
+
end
|
99
|
+
|
100
|
+
def size?
|
101
|
+
!!size
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -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
|
@@ -2,24 +2,21 @@
|
|
2
2
|
|
3
3
|
module Bs5
|
4
4
|
module ComponentsHelper
|
5
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
render BadgeComponent.new(*args)
|
19
|
-
end
|
14
|
+
private
|
20
15
|
|
21
|
-
def
|
22
|
-
render
|
16
|
+
def render_component(component_clazz, *args)
|
17
|
+
render component_clazz.new(*args) do |c|
|
18
|
+
yield c if block_given?
|
19
|
+
end
|
23
20
|
end
|
24
21
|
end
|
25
22
|
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:
|
7
|
+
record.errors.add(attribute, :inclusion, valid_styles: valid_styles.to_sentence)
|
10
8
|
end
|
11
9
|
end
|