Class: HungryForm::Elements::Base::Element
- Inherits:
-
Object
- Object
- HungryForm::Elements::Base::Element
- Includes:
- Hashable
- Defined in:
- lib/hungryform/elements/base/element.rb
Overview
The Element class is used in every form element. It contains the attrs and methods used by all form elements, such as name, visible, dependency etc
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#dependency ⇒ Object
Returns the value of attribute dependency.
-
#label ⇒ Object
Returns the value of attribute label.
-
#name ⇒ Object
Returns the value of attribute name.
-
#placeholders ⇒ Object
Returns the value of attribute placeholders.
-
#resolver ⇒ Object
Returns the value of attribute resolver.
-
#visible ⇒ Object
(also: #visible?)
Returns the value of attribute visible.
Instance Method Summary collapse
-
#configuration ⇒ Object
Configuration params specific to the element.
- #dependency_json ⇒ Object
-
#initialize(name, parent, resolver, attributes = {}) ⇒ Element
constructor
A new instance of Element.
Methods included from Hashable
Constructor Details
#initialize(name, parent, resolver, attributes = {}) ⇒ Element
Returns a new instance of Element.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hungryform/elements/base/element.rb', line 13 def initialize(name, parent, resolver, attributes = {}) @attributes = configuration.dup @attributes.merge!(attributes) @placeholders ||= {} @resolver = resolver self.dependency ||= @attributes.delete(:dependency) # The element is visible if no visible parameter passed or # visible param equals true and the dependency is resolved positively self.visible = @attributes.key?(:visible) ? @attributes.delete(:visible) : true if dependency self.visible &&= resolver.resolve_dependency(dependency) end # An element's name is prefixed with all parents names up to the page self.name = resolver.get_value(name, self) self.name = "#{parent.name}_#{name}" unless parent.nil? # Label can be created from name if there is no label given if @attributes[:label] self.label = resolver.get_value(@attributes.delete(:label), self) else self.label = resolver.get_value(name, self).humanize end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/hungryform/elements/base/element.rb', line 8 def attributes @attributes end |
#dependency ⇒ Object
Returns the value of attribute dependency.
8 9 10 |
# File 'lib/hungryform/elements/base/element.rb', line 8 def dependency @dependency end |
#label ⇒ Object
Returns the value of attribute label.
8 9 10 |
# File 'lib/hungryform/elements/base/element.rb', line 8 def label @label end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/hungryform/elements/base/element.rb', line 8 def name @name end |
#placeholders ⇒ Object
Returns the value of attribute placeholders.
8 9 10 |
# File 'lib/hungryform/elements/base/element.rb', line 8 def placeholders @placeholders end |
#resolver ⇒ Object
Returns the value of attribute resolver.
8 9 10 |
# File 'lib/hungryform/elements/base/element.rb', line 8 def resolver @resolver end |
#visible ⇒ Object Also known as: visible?
Returns the value of attribute visible.
8 9 10 |
# File 'lib/hungryform/elements/base/element.rb', line 8 def visible @visible end |
Instance Method Details
#configuration ⇒ Object
Configuration params specific to the element
47 48 49 |
# File 'lib/hungryform/elements/base/element.rb', line 47 def configuration HungryForm.configuration.send(self.class.name.demodulize.underscore) end |
#dependency_json ⇒ Object
42 43 44 |
# File 'lib/hungryform/elements/base/element.rb', line 42 def dependency_json JSON.generate(dependency) if dependency end |