Module: ExpressTemplates::Components::Capabilities::Conditionality
- Defined in:
- lib/express_templates/components/capabilities/conditionality.rb
Overview
Adds the capability for a component to only render its markup when a condition to be evaluated in the view is true.
Example:
class PageHeader < ExpressTemplates::Components::Base
include ExpressTemplates::Components::Capabilities::Conditionality
emits {
h1 { content_for(:page_header) }
}
only_if -> { content_for?(:page_header) }
end
end
The condition supplied to only if in the form of a proc is evaluated in the view context.
The component will render an empty string if the proc returns false.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
27 28 29 30 31 |
# File 'lib/express_templates/components/capabilities/conditionality.rb', line 27 def self.included(base) base.class_eval do extend ClassMethods end end |