Module: StyleCapsule::ComponentStylesSupport
- Defined in:
- lib/style_capsule/component_styles_support.rb
Overview
Shared module for component styles support (used by both Component and ViewComponent)
Provides unified support for both instance and class method component_styles:
- Instance method:
def component_styles- dynamic rendering, supports all cache strategies except :file - Class method:
def self.component_styles- static rendering, supports all cache strategies including :file
Instance Method Summary collapse
-
#class_styles_only? ⇒ Boolean
Check if component uses class method styles exclusively (required for file caching).
-
#component_styles? ⇒ Boolean
Check if component defines styles (instance or class method).
-
#component_styles_content ⇒ String?
Resolve component styles (from instance or class method).
-
#file_caching_allowed? ⇒ Boolean
Check if file caching is allowed for this component.
Instance Method Details
#class_styles_only? ⇒ Boolean
Check if component uses class method styles exclusively (required for file caching)
Returns true only if class styles are defined and instance styles are not.
34 35 36 |
# File 'lib/style_capsule/component_styles_support.rb', line 34 def class_styles_only? class_styles? && !instance_styles? end |
#component_styles? ⇒ Boolean
Check if component defines styles (instance or class method)
13 14 15 |
# File 'lib/style_capsule/component_styles_support.rb', line 13 def component_styles? instance_styles? || class_styles? end |
#component_styles_content ⇒ String?
Resolve component styles (from instance or class method)
20 21 22 23 24 25 26 27 |
# File 'lib/style_capsule/component_styles_support.rb', line 20 def component_styles_content # Prefer instance method for dynamic rendering if instance_styles? component_styles elsif class_styles? self.class.component_styles end end |
#file_caching_allowed? ⇒ Boolean
Check if file caching is allowed for this component
File caching is only allowed for class method component_styles
43 44 45 46 47 |
# File 'lib/style_capsule/component_styles_support.rb', line 43 def file_caching_allowed? cache_strategy = self.class.inline_cache_strategy return false unless cache_strategy == :file class_styles_only? end |