bs5 0.0.9 → 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/app/components/bs5/button_tag_component.rb +30 -47
- data/lib/bs5/version.rb +1 -1
- metadata +2 -2
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
|
@@ -3,17 +3,23 @@
|
|
3
3
|
module Bs5
|
4
4
|
class ButtonTagComponent < ViewComponent::Base
|
5
5
|
STYLES = %i[primary secondary success danger warning info light dark link].freeze
|
6
|
-
|
6
|
+
DEFAULT_STYLE = :primary
|
7
|
+
SIZES = { small: :sm, large: :lg }.freeze
|
8
|
+
CLASS_PREFIX = 'btn'
|
7
9
|
|
8
|
-
attr_reader :content_or_options, :
|
10
|
+
attr_reader :content_or_options, :size
|
9
11
|
|
10
12
|
include ActiveModel::Validations
|
11
13
|
validates :style, style: true
|
12
|
-
validates :size, inclusion: { in: SIZES, valid_sizes: SIZES.to_sentence, allow_nil: true }
|
14
|
+
validates :size, inclusion: { in: SIZES.keys, valid_sizes: SIZES.keys.to_sentence, allow_nil: true }
|
13
15
|
|
14
16
|
def initialize(content_or_options = nil, options = nil)
|
15
|
-
|
16
|
-
|
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
|
17
23
|
|
18
24
|
extract_custom_options
|
19
25
|
merge_default_options
|
@@ -33,6 +39,14 @@ module Bs5
|
|
33
39
|
|
34
40
|
private
|
35
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
|
+
|
36
50
|
def extract_custom_options
|
37
51
|
extract_style
|
38
52
|
extract_outline
|
@@ -40,68 +54,43 @@ module Bs5
|
|
40
54
|
end
|
41
55
|
|
42
56
|
def extract_style
|
43
|
-
|
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
|
57
|
+
@style = @options.delete(:style)
|
50
58
|
end
|
51
59
|
|
52
60
|
def extract_outline
|
53
|
-
|
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
|
61
|
+
@outline = @options.delete(:outline)
|
60
62
|
end
|
61
63
|
|
62
64
|
def extract_size
|
63
|
-
|
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
|
65
|
+
@size = @options.delete(:size)
|
70
66
|
end
|
71
67
|
|
72
68
|
def merge_default_options
|
73
|
-
|
74
|
-
|
75
|
-
else
|
76
|
-
@options ||= {}
|
77
|
-
deep_merge_and_join @options, default_options
|
69
|
+
@options.deep_merge!(default_options) do |_key, this_val, other_val|
|
70
|
+
[this_val, other_val].join(' ').strip
|
78
71
|
end
|
79
72
|
end
|
80
73
|
|
81
74
|
def default_options
|
82
|
-
{
|
83
|
-
class: button_class
|
84
|
-
}
|
75
|
+
{ class: button_class }
|
85
76
|
end
|
86
77
|
|
87
78
|
def button_class
|
88
|
-
[
|
79
|
+
[CLASS_PREFIX, contextual_class, size_class].compact.join(' ')
|
89
80
|
end
|
90
81
|
|
91
82
|
def contextual_class
|
92
|
-
[
|
83
|
+
[CLASS_PREFIX, outline? ? 'outline' : nil, style].compact.join('-')
|
93
84
|
end
|
94
85
|
|
95
86
|
def size_class
|
96
87
|
return unless size?
|
97
88
|
|
98
|
-
|
99
|
-
|
100
|
-
"btn-#{x}"
|
89
|
+
[CLASS_PREFIX, SIZES[size]].join('-')
|
101
90
|
end
|
102
91
|
|
103
92
|
def style
|
104
|
-
(@style ||
|
93
|
+
(@style || DEFAULT_STYLE).to_sym
|
105
94
|
end
|
106
95
|
|
107
96
|
def outline?
|
@@ -109,13 +98,7 @@ module Bs5
|
|
109
98
|
end
|
110
99
|
|
111
100
|
def size?
|
112
|
-
|
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
|
101
|
+
!!size
|
119
102
|
end
|
120
103
|
end
|
121
104
|
end
|
data/lib/bs5/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.10
|
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-
|
11
|
+
date: 2020-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|