Class: Yattho::ConditionalWrapper
- Defined in:
- app/components/yattho/conditional_wrapper.rb
Overview
Conditionally renders a ‘Yattho::BaseComponent` around the given content. If the given condition is true, a `Yattho::BaseComponent` will render around the content. If the condition is false, only the content is rendered.
Constant Summary
Constants inherited from Component
Yattho::Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(condition:, **base_component_arguments) ⇒ ConditionalWrapper
constructor
A new instance of ConditionalWrapper.
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Constructor Details
#initialize(condition:, **base_component_arguments) ⇒ ConditionalWrapper
Returns a new instance of ConditionalWrapper.
25 26 27 28 |
# File 'app/components/yattho/conditional_wrapper.rb', line 25 def initialize(condition:, **base_component_arguments) @condition = condition @base_component_arguments = base_component_arguments end |
Instance Method Details
#call ⇒ Object
30 31 32 33 34 |
# File 'app/components/yattho/conditional_wrapper.rb', line 30 def call return content unless @condition BaseComponent.new(**@base_component_arguments).render_in(self) { content } end |