bsvc 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +59 -3
- data/app/components/accordion/accordion_component.html.erb +9 -0
- data/app/components/accordion/accordion_component.rb +38 -0
- data/app/components/accordion/accordion_item_component.htm.erb +24 -0
- data/app/components/accordion/accordion_item_component.rb +25 -0
- data/app/components/alert/alert_component.html.erb +14 -0
- data/app/components/alert/alert_component.rb +38 -0
- data/app/components/alpha/forms/form/form.rb +12 -0
- data/app/components/alpha/forms/input/input_component.html.erb +10 -0
- data/app/components/alpha/forms/input/input_component.rb +48 -0
- data/app/components/card/card_component.rb +2 -4
- data/app/components/grid/columns/columns_component.rb +8 -6
- data/app/helpers/accordion/accordion_helper.rb +17 -0
- data/app/helpers/alert/alert_helper.rb +15 -0
- data/app/helpers/alpha/forms/input_helper.rb +9 -0
- data/app/helpers/card/card_helper.rb +12 -0
- data/app/helpers/grid/row_helper.rb +6 -0
- data/bsvc.gemspec +0 -2
- data/lib/bsvc/version.rb +1 -1
- data/lib/generators/bsvc/component_generator.rb +15 -1
- metadata +18 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a73813d0faff1ece3a11dbb99ab92fc0ae1b6a21b569f4e7b8098360414bd23f
|
4
|
+
data.tar.gz: aed5a21edf2dea1a80191fd25d091be82125bc2180f800ec87d0e513ae4c2ee0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a169f4e0a2632317c578e39374375dd39572d0d7c8764d51d55b81851cd2bbdb8916ee2013e28b9ba5fb7455403a14a2c623fdcbb95807d18920704fe5df5b80
|
7
|
+
data.tar.gz: c9b5faa907d9ee920a650e04de3cc22e3e8c560ece596a4b9b67dd9f07711bf33b5d95c5b60f3eed0dfa287bc33f300785c050d82c6629d3c435c370649b2b27
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -20,9 +20,53 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install bsvc
|
22
22
|
|
23
|
+
|
24
|
+
**NOTE:** BSVC does _not_ include Bootstrap for you, this is by design. BSVC will work however you include Bootstrap in your application, whether through sprockets, esbuild, import map or any other way.
|
25
|
+
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
Basic four column grid that shrinks to two, double stacked columns at the 768px (md) breakpont. Each column contains a heading component.
|
29
|
+
|
30
|
+
**NOTE:** The last column shows a heading component (`h`) passing content in through a block rather than the `text:` option.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
<%= container do %>
|
34
|
+
<%= row do |c| %>
|
35
|
+
<%= column(c, col: { md: 6, lg: 3 }) do %>
|
36
|
+
<%= h(tag: 'h2', text: 'Column 1') %>
|
37
|
+
<% end %>
|
38
|
+
<%= column(c, col: { md: 6, lg: 3 }) do %>
|
39
|
+
<%= h(tag: 'h2', text: 'Column 2') %>
|
40
|
+
<% end %>
|
41
|
+
<%= column(c, col: { md: 6, lg: 3 }) do %>
|
42
|
+
<%= h(tag: 'h2', text: 'Column 3') %>
|
43
|
+
<% end %>
|
44
|
+
<%= column(c, col: { md: 6, lg: 3 }) do %>
|
45
|
+
<%= h(tag: 'h2') do %>
|
46
|
+
<i class="bi bi-4-circle-fill"></i> Column 4
|
47
|
+
<% end %>
|
48
|
+
<% end %>
|
49
|
+
<% end %>
|
50
|
+
<% end %>
|
51
|
+
```
|
52
|
+
|
53
|
+
### Compoments used:
|
54
|
+
- Container
|
55
|
+
- Accepts two options, type of container (`sm, md, lg...fluid`) and any additional classes
|
56
|
+
- Row
|
57
|
+
- Accepts additional classes (`row` is default) and styles.
|
58
|
+
- Column
|
59
|
+
- Accepts:
|
60
|
+
- col (`md: 6`)
|
61
|
+
- offset (`md: 6`)
|
62
|
+
- classes
|
63
|
+
- styles
|
64
|
+
- Heading (h)
|
65
|
+
- Accepts:
|
66
|
+
- text (only if no block is provided)
|
67
|
+
- tag (h1, h2, h3 etc)
|
68
|
+
- classes
|
69
|
+
- styles
|
26
70
|
|
27
71
|
## Customizing Components
|
28
72
|
|
@@ -36,14 +80,26 @@ To copy all compoents into your app run:
|
|
36
80
|
rails g bsvc:components
|
37
81
|
```
|
38
82
|
|
39
|
-
This will copy over all of BSVC components and helpers. It will create
|
83
|
+
This will copy over all of BSVC components and helpers. It will create an `app/components/` directory in the root of app. All helpers will be placed inside `app/helpers/`.
|
40
84
|
|
41
85
|
### A Single Component
|
42
86
|
|
43
87
|
```ruby
|
44
88
|
rails g bsvc:component --name COMPONENT_NAME
|
45
89
|
```
|
46
|
-
|
90
|
+
`COMPONENT_NAME` should be the top level directory of the coponent you want in `app/components/`
|
91
|
+
|
92
|
+
**NOTE:** Running the `component` command on a parent component with nested child components will copy over all child components in the top level directory.
|
93
|
+
|
94
|
+
### A Single Nested Child Component
|
95
|
+
For nested child components, pass the path of the component starting with the top level directory.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
rails g bsvc:component --name grid/container
|
99
|
+
```
|
100
|
+
|
101
|
+
This will grab only the container component and helper and place them in `app/components/grid` and `app/helpers/grid`.
|
102
|
+
|
47
103
|
|
48
104
|
## Roadmap
|
49
105
|
- Continue building out components
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Accordion
|
4
|
+
def default_plus_passed_classes(defaults, classes)
|
5
|
+
"#{defaults} #{classes}".strip
|
6
|
+
end
|
7
|
+
|
8
|
+
module_function :default_plus_passed_classes
|
9
|
+
|
10
|
+
class AccordionComponent < ViewComponent::Base
|
11
|
+
renders_many :items, AccordionItemComponent
|
12
|
+
|
13
|
+
def initialize(**options)
|
14
|
+
@id = options[:id]
|
15
|
+
@classses = options[:classses]
|
16
|
+
@styles = options[:styles]
|
17
|
+
|
18
|
+
@default_classses = 'accordion'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def styles
|
24
|
+
@styles if @styles.present?
|
25
|
+
end
|
26
|
+
|
27
|
+
def id
|
28
|
+
"id=#{@id}" if @id
|
29
|
+
end
|
30
|
+
|
31
|
+
def classes
|
32
|
+
"class=#{Accordion.default_plus_passed_classes(
|
33
|
+
@default_classses,
|
34
|
+
@classes
|
35
|
+
)}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<div class="accordion-item">
|
2
|
+
<h2 class="accordion-header" <%= id %>>
|
3
|
+
<button
|
4
|
+
class="<%= "accordion-button #{active_item? ? nil : 'collapsed'}".strip %>"
|
5
|
+
type="button"
|
6
|
+
data-bs-toggle="collapse"
|
7
|
+
data-bs-target="#<%= @target %>"
|
8
|
+
aria-expanded="<%= active_item? ? 'true' : 'false' %>"
|
9
|
+
aria-controls="<%= @target %>"
|
10
|
+
>
|
11
|
+
<%= @title %>
|
12
|
+
</button>
|
13
|
+
</h2>
|
14
|
+
<div
|
15
|
+
id="<%= @target %>"
|
16
|
+
class="<%= "accordion-collapse collapse #{active_item? ? 'show' : nil}".strip %>"
|
17
|
+
aria-labelledby="<%= @id %>"
|
18
|
+
data-bs-parent="<%= "##{@parent}" %>"
|
19
|
+
>
|
20
|
+
<div class="accordion-body">
|
21
|
+
<%= content %>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</div>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_strin_literal: true
|
2
|
+
|
3
|
+
module Accordion
|
4
|
+
class AccordionItemComponent < ViewComponent::Base
|
5
|
+
|
6
|
+
def initialize(**options)
|
7
|
+
@id = options[:id]
|
8
|
+
@title = options[:title]
|
9
|
+
@index = options[:index]
|
10
|
+
@target = options[:target]
|
11
|
+
@active = options[:active]
|
12
|
+
@parent = options[:parent]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def active_item?
|
18
|
+
@active
|
19
|
+
end
|
20
|
+
|
21
|
+
def id
|
22
|
+
"id=#{@id}" if @id
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<div
|
2
|
+
class="alert alert-<%= variant %> <%= dismissible_classes %> <%= icon_classes %>"
|
3
|
+
role="alert"
|
4
|
+
>
|
5
|
+
<%= message %>
|
6
|
+
<% if dismissible? %>
|
7
|
+
<button
|
8
|
+
type="button"
|
9
|
+
class="btn-close"
|
10
|
+
data-bs-dismiss="alert"
|
11
|
+
aria-label="Close">
|
12
|
+
</button>
|
13
|
+
<% end %>
|
14
|
+
</div>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alert
|
4
|
+
class AlertComponent < ViewComponent::Base
|
5
|
+
def initialize(**options)
|
6
|
+
@variant = options[:variant]
|
7
|
+
@dismiss = options[:dismiss]
|
8
|
+
@message = options[:message]
|
9
|
+
@icon = options[:icon]
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def dismissible?
|
15
|
+
true unless @dismiss == false
|
16
|
+
end
|
17
|
+
|
18
|
+
def dismissible_classes
|
19
|
+
'alert-dismissible fade show' if dismissible?
|
20
|
+
end
|
21
|
+
|
22
|
+
def icon?
|
23
|
+
@icon
|
24
|
+
end
|
25
|
+
|
26
|
+
def icon_classes
|
27
|
+
'd-flex align-items-center' if icon?
|
28
|
+
end
|
29
|
+
|
30
|
+
def variant
|
31
|
+
@variant || 'primary'
|
32
|
+
end
|
33
|
+
|
34
|
+
def message
|
35
|
+
@message || content
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Forms
|
4
|
+
module Input
|
5
|
+
class InputComponent < ViewComponent::Base
|
6
|
+
def initialize(**options)
|
7
|
+
@method = options[:method]
|
8
|
+
@object = options[:object]
|
9
|
+
@scope = options[:scope]
|
10
|
+
@type = options.dig(:html, :type)
|
11
|
+
@classes = options.dig(:html, :class)
|
12
|
+
@floating = options.dig(:html, :floating)
|
13
|
+
@placeholder = options.dig(:html, :placeholder)
|
14
|
+
@onchange = options.dig(:html, :onchange)
|
15
|
+
@html = options[:html]
|
16
|
+
classes_builder
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def text_input
|
22
|
+
if scoped?
|
23
|
+
@scope.text_field(@method, @html)
|
24
|
+
else
|
25
|
+
text_field(@object, @method, @html)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def scoped?
|
30
|
+
@scope.present?
|
31
|
+
end
|
32
|
+
|
33
|
+
def floating_label_id
|
34
|
+
if scoped?
|
35
|
+
@scope.options[:html][:id]
|
36
|
+
else
|
37
|
+
"#{@object}_#{@method}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def classes_builder
|
42
|
+
if @html[:class]
|
43
|
+
@html[:class] = "form-control #{@classes}".strip
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -19,7 +19,6 @@ module Card
|
|
19
19
|
class HeaderComponent < ViewComponent::Base
|
20
20
|
|
21
21
|
def initialize(**options)
|
22
|
-
@tag = options[:tag] || :h2
|
23
22
|
@classes = options[:classes]
|
24
23
|
@styles = options[:styles]
|
25
24
|
|
@@ -27,7 +26,7 @@ module Card
|
|
27
26
|
end
|
28
27
|
|
29
28
|
def call
|
30
|
-
content_tag(
|
29
|
+
content_tag(:div,
|
31
30
|
content,
|
32
31
|
class: Card.default_plus_passed_classes(
|
33
32
|
@default_classses,
|
@@ -41,7 +40,6 @@ module Card
|
|
41
40
|
class FooterComponent < ViewComponent::Base
|
42
41
|
|
43
42
|
def initialize(**options)
|
44
|
-
@tag = options[:tag] || :div
|
45
43
|
@classes = options[:classes]
|
46
44
|
@styles = options[:styles]
|
47
45
|
|
@@ -49,7 +47,7 @@ module Card
|
|
49
47
|
end
|
50
48
|
|
51
49
|
def call
|
52
|
-
content_tag(
|
50
|
+
content_tag(:div,
|
53
51
|
content,
|
54
52
|
class: Card.default_plus_passed_classes(
|
55
53
|
@default_classses,
|
@@ -23,15 +23,17 @@ module Grid
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def column_class_builder
|
26
|
-
"#{column_breakpoint} #{column_offset} #{@classes}"
|
26
|
+
"#{column_breakpoint} #{column_offset} #{@classes}".strip
|
27
27
|
end
|
28
28
|
|
29
29
|
def class_parser(option, klass)
|
30
|
-
option.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
unless option.nil?
|
31
|
+
option.map do |key, value|
|
32
|
+
if BREAK_POINTS.include?(key)
|
33
|
+
"#{klass}-#{key}-#{value} "
|
34
|
+
end
|
35
|
+
end.join('').strip
|
36
|
+
end
|
35
37
|
end
|
36
38
|
|
37
39
|
def column_breakpoint
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_strin_literal: true
|
2
|
+
|
3
|
+
module Accordion
|
4
|
+
module AccordionHelper
|
5
|
+
def accordion(**options)
|
6
|
+
render(Accordion::AccordionComponent.new(**options)) do |c|
|
7
|
+
yield(c)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def item(c, **options)
|
12
|
+
c.with_item(**options) do
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alert
|
4
|
+
module AlertHelper
|
5
|
+
def alert(**options)
|
6
|
+
if block_given?
|
7
|
+
render(Alert::AlertComponent.new(**options)) do
|
8
|
+
yield
|
9
|
+
end
|
10
|
+
else
|
11
|
+
render(Alert::AlertComponent.new(**options))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/bsvc.gemspec
CHANGED
@@ -19,8 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.metadata["source_code_uri"] = spec.homepage
|
20
20
|
spec.metadata["changelog_uri"] = spec.homepage
|
21
21
|
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
22
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
23
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
24
|
end
|
data/lib/bsvc/version.rb
CHANGED
@@ -8,8 +8,22 @@ module Bsvc
|
|
8
8
|
class_option :name, type: :string, default: ''
|
9
9
|
|
10
10
|
def copy_single_component
|
11
|
+
copy_component_to_app
|
12
|
+
copy_helper_to_app
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def copy_component_to_app
|
11
18
|
directory("app/components/#{@options[:name]}", "app/components/#{@options[:name]}")
|
12
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_helper_to_app
|
22
|
+
if @options[:name].include?('/')
|
23
|
+
copy_file("app/helpers/#{@options[:name]}_helper.rb", "app/helpers/#{@options[:name]}_helper.rb")
|
24
|
+
else
|
25
|
+
directory("app/helpers/#{@options[:name]}", "app/helpers/#{@options[:name]}")
|
26
|
+
end
|
13
27
|
end
|
14
28
|
end
|
15
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bsvc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick McNeany
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,15 @@ files:
|
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
|
+
- app/components/accordion/accordion_component.html.erb
|
84
|
+
- app/components/accordion/accordion_component.rb
|
85
|
+
- app/components/accordion/accordion_item_component.htm.erb
|
86
|
+
- app/components/accordion/accordion_item_component.rb
|
87
|
+
- app/components/alert/alert_component.html.erb
|
88
|
+
- app/components/alert/alert_component.rb
|
89
|
+
- app/components/alpha/forms/form/form.rb
|
90
|
+
- app/components/alpha/forms/input/input_component.html.erb
|
91
|
+
- app/components/alpha/forms/input/input_component.rb
|
83
92
|
- app/components/card/card_component.html.erb
|
84
93
|
- app/components/card/card_component.rb
|
85
94
|
- app/components/grid/columns/columns_component.rb
|
@@ -87,6 +96,9 @@ files:
|
|
87
96
|
- app/components/grid/container/container_component.rb
|
88
97
|
- app/components/grid/row/row_component.rb
|
89
98
|
- app/components/heading/h_component.rb
|
99
|
+
- app/helpers/accordion/accordion_helper.rb
|
100
|
+
- app/helpers/alert/alert_helper.rb
|
101
|
+
- app/helpers/alpha/forms/input_helper.rb
|
90
102
|
- app/helpers/card/card_helper.rb
|
91
103
|
- app/helpers/grid/container_helper.rb
|
92
104
|
- app/helpers/grid/row_helper.rb
|
@@ -106,7 +118,7 @@ metadata:
|
|
106
118
|
homepage_uri: https://github.com/Nickiam7/bsvc
|
107
119
|
source_code_uri: https://github.com/Nickiam7/bsvc
|
108
120
|
changelog_uri: https://github.com/Nickiam7/bsvc
|
109
|
-
post_install_message:
|
121
|
+
post_install_message:
|
110
122
|
rdoc_options: []
|
111
123
|
require_paths:
|
112
124
|
- lib
|
@@ -121,8 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
133
|
- !ruby/object:Gem::Version
|
122
134
|
version: '0'
|
123
135
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
125
|
-
signing_key:
|
136
|
+
rubygems_version: 3.3.25
|
137
|
+
signing_key:
|
126
138
|
specification_version: 4
|
127
139
|
summary: A Bootstrap and ViewComponent library for Rails views.
|
128
140
|
test_files: []
|