Class: ViewComponentContrib::StyleVariants::StyleConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/view_component_contrib/style_variants.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_POST_PROCESSOR =
->(compiled) { compiled.join(" ") }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStyleConfig

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

#postprocessorObject (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

#dupObject



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