Module: ViewComponent::ScopedStyles
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/view_component/scoped_styles.rb,
lib/view_component/scoped_styles/concern.rb,
lib/view_component/scoped_styles/railtie.rb,
lib/view_component/scoped_styles/stylist.rb,
lib/view_component/scoped_styles/version.rb,
lib/view_component/scoped_styles/configuration.rb,
lib/view_component/scoped_styles/stylist/writer.rb,
lib/view_component/scoped_styles/css_class_prefix.rb,
lib/generators/view_component/scoped_styles/install_generator.rb
Defined Under Namespace
Modules: Generators Classes: Configuration, CssClassPrefix, Railtie, Stylist
Constant Summary collapse
- CACHED_VARIABLES =
%i[@component_styles @component_id @component_class_map].freeze
- CLASS_SELECTOR_PATTERN =
/\.([a-zA-Z_][\w-]*)\b/- COMPONENT_REFERENCE_PATTERN =
/ :component\( \s* (?<component_name>[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*) \s* (?:,\s*(?<css_class>[a-zA-Z_][\w-]*)\s*)? \) /x- COMPONENT_RESOLUTION_STACK_KEY =
:view_component_scoped_styles_component_resolution_stack- COMPONENT_CSS_CLASS =
Default root class for
component_classwhen it matches a selector in the CSS. "component".freeze
- IGNORED_CSS_CLASSES =
[].freeze
- VERSION =
"0.6.0"
Class Method Summary collapse
-
.configuration ⇒ Configuration
Returns the global configuration object, creating it on first access.
-
.configure {|config| ... } ⇒ void
Yields the global configuration for block-style setup.
Instance Method Summary collapse
-
#component_class(name = nil, from: self.class) ⇒ Object
Scoped CSS class for a selector (e.g. “c-99d08d5a”).
Class Method Details
.configuration ⇒ Configuration
Returns the global configuration object, creating it on first access.
68 69 70 |
# File 'lib/view_component/scoped_styles/configuration.rb', line 68 def configuration @configuration ||= Configuration.new end |
.configure {|config| ... } ⇒ void
This method returns an undefined value.
Yields the global configuration for block-style setup.
76 |
# File 'lib/view_component/scoped_styles/configuration.rb', line 76 def configure = yield(configuration) |
Instance Method Details
#component_class(name = nil, from: self.class) ⇒ Object
Scoped CSS class for a selector (e.g. “c-99d08d5a”).
With no argument, returns the scoped root class (COMPONENT_CSS_CLASS when it appears in the CSS, otherwise the first class in the stylesheet).
282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/view_component/scoped_styles/concern.rb', line 282 def component_class(name = nil, from: self.class) return nil unless from.respond_to?(:component_styles) return nil unless component_has_styles?(from) || component_has_stylesheet?(from) from.component_styles if name class_map = from.instance_variable_get(:@component_class_map) class_map[name.to_s.delete_prefix(".")] else from.instance_variable_get(:@component_id) end end |