Module: ViewComponentContrib::StyleVariants::ClassMethods

Defined in:
lib/view_component_contrib/style_variants.rb

Instance Method Summary collapse

Instance Method Details

#default_style_nameObject

Returns the name of the default style set based on the class name:

MyComponent::Component => my_component
Namespaced::MyComponent => my_component


189
190
191
# File 'lib/view_component_contrib/style_variants.rb', line 189

def default_style_name
  @default_style_name ||= name.demodulize.sub(/(::Component|Component)$/, "").underscore.presence || "component"
end

#style(name = default_style_name, &block) ⇒ Object



193
194
195
# File 'lib/view_component_contrib/style_variants.rb', line 193

def style(name = default_style_name, &block)
  style_config.define(name.to_sym, &block)
end

#style_configObject



197
198
199
200
201
202
203
204
# File 'lib/view_component_contrib/style_variants.rb', line 197

def style_config
  @style_config ||=
    if superclass.respond_to?(:style_config)
      superclass.style_config.dup
    else
      StyleConfig.new
    end
end