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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f46f7deb1b2f66de32843565d17a4e3021901e0cb0fdf3b231ccf148e053151
4
- data.tar.gz: 1d7b1189052c480e87018deae07426a170ab97e51607089fc81d495dd21e12d9
3
+ metadata.gz: d4b5587ecfcc831c00cce7081d68b2a05fd8d1e40e05fb8e67d42575d50fb59b
4
+ data.tar.gz: 469503443e27a39caf829f702be3de802bb040826931390c9cb6611fea419115
5
5
  SHA512:
6
- metadata.gz: e5c363ac58ca543540c673618e334159b0b5a2d8f8e062145802e74ad453b0a3c784e95285ebdd17e19be12c6e49446ad933f1def829a1655a92925e56d0d316
7
- data.tar.gz: 4fc740749a6367df09d0efb8a9137a27095dab9471758206a99a0fffcdff6bff319c3e070eb62b01b75330e965b79df36275d5dc8108936581c684854b0b73ac
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])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SparkComponents
4
- VERSION = "1.1.1"
4
+ VERSION = "1.2.0"
5
5
  end
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.1.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-05-23 00:00:00.000000000 Z
11
+ date: 2019-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails