Class: ViewComponentContrib::StyleVariants::StyleConfig
- Inherits:
-
Object
- Object
- ViewComponentContrib::StyleVariants::StyleConfig
- Defined in:
- lib/view_component_contrib/style_variants.rb
Overview
:nodoc:
Constant Summary collapse
- DEFAULT_POST_PROCESSOR =
->(compiled) { compiled.join(" ") }
Instance Attribute Summary collapse
-
#postprocessor ⇒ Object
readonly
Returns the value of attribute postprocessor.
Instance Method Summary collapse
- #compile(name, **variants) ⇒ Object
- #define(name, &block) ⇒ Object
- #dup ⇒ Object
-
#initialize ⇒ StyleConfig
constructor
A new instance of StyleConfig.
-
#postprocess_with(callable = nil, &block) ⇒ Object
Allow defining a custom postprocessor.
Constructor Details
#initialize ⇒ StyleConfig
Returns a new instance of StyleConfig.
177 178 179 180 |
# File 'lib/view_component_contrib/style_variants.rb', line 177 def initialize @styles = {} @postprocessor = DEFAULT_POST_PROCESSOR end |
Instance Attribute Details
#postprocessor ⇒ Object (readonly)
Returns the value of attribute postprocessor.
175 176 177 |
# File 'lib/view_component_contrib/style_variants.rb', line 175 def postprocessor @postprocessor end |
Instance Method Details
#compile(name, **variants) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/view_component_contrib/style_variants.rb', line 186 def compile(name, **variants) styles[name]&.compile(**variants).then do |compiled| next unless compiled postprocess(compiled) end end |
#define(name, &block) ⇒ Object
182 183 184 |
# File 'lib/view_component_contrib/style_variants.rb', line 182 def define(name, &block) styles[name] = StyleSet.new(&block) end |
#dup ⇒ Object
199 200 201 202 203 |
# File 'lib/view_component_contrib/style_variants.rb', line 199 def dup copy = super copy.instance_variable_set(:@styles, @styles.dup) copy end |
#postprocess_with(callable = nil, &block) ⇒ Object
Allow defining a custom postprocessor
195 196 197 |
# File 'lib/view_component_contrib/style_variants.rb', line 195 def postprocess_with(callable = nil, &block) @postprocessor = callable || block end |