spark_components 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spark_components/element.rb +33 -0
- data/lib/spark_components/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: d4b5587ecfcc831c00cce7081d68b2a05fd8d1e40e05fb8e67d42575d50fb59b
|
4
|
+
data.tar.gz: 469503443e27a39caf829f702be3de802bb040826931390c9cb6611fea419115
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cac7acf659a200fcc4d56f01d4d99170d31bd09b94b78fbf26be4a15e1c07c1f1e629c9b835861c9fb6802011fc786757c56aea438e05b497569d8f552bd678
|
7
|
+
data.tar.gz: 1c1c34bf7e139fd8d021cd3516706ee41603b8ba1578e66969824c272274935209694feab07567ad2fea33922147924630d1da48652053df0c26af8694423b80
|
@@ -15,6 +15,10 @@ module SparkComponents
|
|
15
15
|
@attributes ||= {}
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.themes
|
19
|
+
@themes ||= {}
|
20
|
+
end
|
21
|
+
|
18
22
|
def self.elements
|
19
23
|
@elements ||= {}
|
20
24
|
end
|
@@ -49,6 +53,17 @@ module SparkComponents
|
|
49
53
|
tag_attributes[:class].add(*args)
|
50
54
|
end
|
51
55
|
|
56
|
+
def self.add_theme(hash)
|
57
|
+
themes.merge!(hash)
|
58
|
+
return if attributes[:theme]
|
59
|
+
|
60
|
+
if hash.key?(:default)
|
61
|
+
attribute(theme: :default)
|
62
|
+
else
|
63
|
+
attribute(:theme)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
52
67
|
def self.data_attr(*args)
|
53
68
|
set_attr(:data, *args)
|
54
69
|
end
|
@@ -129,6 +144,7 @@ module SparkComponents
|
|
129
144
|
def self.inherited(subclass)
|
130
145
|
attributes.each { |name, options| subclass.set_attribute(name, options.dup) }
|
131
146
|
elements.each { |name, options| subclass.elements[name] = options.dup }
|
147
|
+
subclass.themes.merge!(themes)
|
132
148
|
|
133
149
|
subclass.tag_attributes.merge!(tag_attributes.each_with_object({}) do |(k, v), obj|
|
134
150
|
obj[k] = v.dup
|
@@ -143,6 +159,7 @@ module SparkComponents
|
|
143
159
|
initialize_attributes(attributes)
|
144
160
|
initialize_elements
|
145
161
|
extend_view_methods
|
162
|
+
initialize_themes
|
146
163
|
after_init
|
147
164
|
@yield = block_given? ? @view.capture(self, &block) : nil
|
148
165
|
validate!
|
@@ -238,6 +255,22 @@ module SparkComponents
|
|
238
255
|
end
|
239
256
|
end
|
240
257
|
|
258
|
+
# Add a class based on the chosen theme
|
259
|
+
def initialize_themes
|
260
|
+
themes = self.class.themes.stringify_keys
|
261
|
+
return if themes.empty? || @theme.nil?
|
262
|
+
|
263
|
+
theme = @theme.to_s
|
264
|
+
|
265
|
+
if !themes.key?(theme)
|
266
|
+
theme_list = self.class.themes.keys.map(&:inspect).join(", ")
|
267
|
+
msg = "Unsupported theme: #{@theme.inspect} is not a valid theme. Try: #{theme_list}."
|
268
|
+
return raise(SparkComponents::Error, msg)
|
269
|
+
else
|
270
|
+
add_class themes[theme]
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
241
274
|
def initialize_elements
|
242
275
|
self.class.elements.each do |name, options|
|
243
276
|
if (plural_name = options[:multiple])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spark_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|