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.
146 147 148 149 |
# File 'lib/view_component_contrib/style_variants.rb', line 146 def initialize @styles = {} @postprocessor = DEFAULT_POST_PROCESSOR end |
Instance Attribute Details
#postprocessor ⇒ Object (readonly)
Returns the value of attribute postprocessor.
144 145 146 |
# File 'lib/view_component_contrib/style_variants.rb', line 144 def postprocessor @postprocessor end |
Instance Method Details
#compile(name, **variants) ⇒ Object
155 156 157 158 159 160 161 |
# File 'lib/view_component_contrib/style_variants.rb', line 155 def compile(name, **variants) styles[name]&.compile(**variants).then do |compiled| next unless compiled postprocess(compiled) end end |
#define(name, &block) ⇒ Object
151 152 153 |
# File 'lib/view_component_contrib/style_variants.rb', line 151 def define(name, &block) styles[name] = StyleSet.new(&block) end |
#dup ⇒ Object
168 169 170 171 172 |
# File 'lib/view_component_contrib/style_variants.rb', line 168 def dup copy = super copy.instance_variable_set(:@styles, @styles.dup) copy end |
#postprocess_with(callable = nil, &block) ⇒ Object
Allow defining a custom postprocessor
164 165 166 |
# File 'lib/view_component_contrib/style_variants.rb', line 164 def postprocess_with(callable = nil, &block) @postprocessor = callable || block end |