Class: Caisson::Helpers::Form::Builder::FieldBuilder::Base
- Inherits:
-
Object
- Object
- Caisson::Helpers::Form::Builder::FieldBuilder::Base
- Defined in:
- lib/caisson/helpers/form/builder/field_builder/base.rb
Instance Attribute Summary collapse
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#nature ⇒ Object
readonly
Returns the value of attribute nature.
Instance Method Summary collapse
-
#build ⇒ Object
************************************************************************************* PUBLIC INSTANCE METHODS *************************************************************************************.
- #checkbox? ⇒ Boolean
- #errors ⇒ Object
- #errors? ⇒ Boolean
- #hidden? ⇒ Boolean
- #hint? ⇒ Boolean
-
#initialize(core, name, options = {}) ⇒ Base
constructor
************************************************************************************* CONSTRUCTOR *************************************************************************************.
- #label ⇒ Object
- #wrap_field(field_tags) ⇒ Object
- #wrapper_errors ⇒ Object
- #wrapper_hint ⇒ Object
Constructor Details
#initialize(core, name, options = {}) ⇒ Base
************************************************************************************* CONSTRUCTOR *************************************************************************************
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 15 def initialize(core, name, ={}) .reverse_merge!(nature: nil, hint: true) @core = core @name = name = .dup @record = core.record @show_hint = [:hint] @nature = Caisson::Helpers::Form::Builder::FieldBuilder::Nature.new(@record, name).get(force: [:nature]) end |
Instance Attribute Details
#core ⇒ Object (readonly)
Returns the value of attribute core.
7 8 9 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 7 def core @core end |
#nature ⇒ Object (readonly)
Returns the value of attribute nature.
6 7 8 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 6 def nature @nature end |
Instance Method Details
#build ⇒ Object
************************************************************************************* PUBLIC INSTANCE METHODS *************************************************************************************
30 31 32 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 30 def build "Caisson::Helpers::Form::Builder::Field::#{@nature.camelize}".constantize.new(@core, @record, @name, ).build end |
#checkbox? ⇒ Boolean
34 35 36 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 34 def checkbox? nature == 'checkbox' end |
#errors ⇒ Object
42 43 44 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 42 def errors interpreti.field_errors(@name) end |
#errors? ⇒ Boolean
38 39 40 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 38 def errors? not errors.empty? end |
#hidden? ⇒ Boolean
46 47 48 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 46 def hidden? @nature == 'hidden' end |
#hint? ⇒ Boolean
50 51 52 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 50 def hint? not interpreti.field_hint(@name).blank? and @show_hint end |
#label ⇒ Object
54 55 56 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 54 def label interpreti.field_label(@name) end |
#wrap_field(field_tags) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 58 def wrap_field() css_class = ['field'] css_class << 'errors' if errors? content_tag(:div, + wrapper_hint + wrapper_errors, class: css_class.join(' ')) end |
#wrapper_errors ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 65 def wrapper_errors if errors? content_tag(:div, errors.map{|e| content_tag(:span, e)}.join.html_safe, class: 'error-messages') else '' end end |
#wrapper_hint ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/caisson/helpers/form/builder/field_builder/base.rb', line 73 def wrapper_hint if hint? content_tag(:div, interpreti.field_hint(@name).html_safe, class: 'hint') else '' end end |