Class: ExpressTemplates::Components::Configurable
- Defined in:
- lib/express_templates/components/configurable.rb
Overview
Configurable components support configuration options supplied to the builder method. Supported options must be declared. All other options are passed along and converted to html attributes.
Example:
“‘ruby
class Pane < ExpressTemplates::Components::Configurable
has_option :title, "Displayed in the title area", required: true
has_option :status, "Displayed in the status area"
end
# Usage:
pane(title: “People”, status: “#peoplepeople.count people”)
“‘ruby
Options specified as required must be supplied.
Default values may be supplied for options with a default: keyword.
Options may be passed as html attributes with attribute: true
Direct Known Subclasses
Class Method Summary collapse
- .emits(*args, &block) ⇒ Object
- .has_argument(name, description, as: nil, type: :string, default: nil, optional: false) ⇒ Object
- .has_option(name, description, type: :string, required: nil, default: nil, attribute: nil, values: nil) ⇒ Object
Instance Method Summary collapse
Methods inherited from Base
before_build, builder_method_and_class, builder_method_name, #builder_method_name, contains, descendants, has_attributes, inherited, #initialize, #resource, tag
Constructor Details
This class inherits a constructor from ExpressTemplates::Components::Base
Class Method Details
.emits(*args, &block) ⇒ Object
36 37 38 39 |
# File 'lib/express_templates/components/configurable.rb', line 36 def self.emits(*args, &block) warn ".emits is deprecrated" self.contains(*args, &block) end |
.has_argument(name, description, as: nil, type: :string, default: nil, optional: false) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/express_templates/components/configurable.rb', line 62 def self.has_argument(name, description, as: nil, type: :string, default: nil, optional: false) raise "name must be a symbol" unless name.kind_of?(Symbol) argument_definition = {description: description, as: as, type: type, default: default, optional: optional} self.supported_arguments = self.supported_arguments.merge(name => argument_definition) end |
.has_option(name, description, type: :string, required: nil, default: nil, attribute: nil, values: nil) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/express_templates/components/configurable.rb', line 50 def self.has_option(name, description, type: :string, required: nil, default: nil, attribute: nil, values: nil) raise "name must be a symbol" unless name.kind_of?(Symbol) option_definition = {description: description} option_definition.merge!(type: type, required: required, default: default, attribute: attribute, values: values) self. = self..merge(name => option_definition) end |
Instance Method Details
#build(*args, &block) ⇒ Object
41 42 43 44 |
# File 'lib/express_templates/components/configurable.rb', line 41 def build(*args, &block) _process_builder_args!(args) super(*args, &block) end |
#config ⇒ Object
46 47 48 |
# File 'lib/express_templates/components/configurable.rb', line 46 def config @config ||= {} end |
#required_options ⇒ Object
58 59 60 |
# File 'lib/express_templates/components/configurable.rb', line 58 def .select {|k,v| v[:required] unless v[:default] } end |