Class: Trestle::Form::Fields::StaticField
- Inherits:
-
Trestle::Form::Field
- Object
- Trestle::Form::Field
- Trestle::Form::Fields::StaticField
- Defined in:
- lib/trestle/form/fields/static_field.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Trestle::Form::Field
#block, #builder, #name, #options, #template
Instance Method Summary collapse
- #default_value ⇒ Object
- #field ⇒ Object
-
#initialize(builder, template, name, value = nil, options = {}, &block) ⇒ StaticField
constructor
A new instance of StaticField.
Methods inherited from Trestle::Form::Field
#defaults, #errors, #form_group, #normalize_options!, #readonly?, #render
Constructor Details
#initialize(builder, template, name, value = nil, options = {}, &block) ⇒ StaticField
Returns a new instance of StaticField.
7 8 9 10 11 12 13 14 15 |
# File 'lib/trestle/form/fields/static_field.rb', line 7 def initialize(builder, template, name, value=nil, ={}, &block) if block_given? && value.is_a?(Hash) = value else @value = value end super(builder, template, name, , &block) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/trestle/form/fields/static_field.rb', line 5 def value @value end |
Instance Method Details
#default_value ⇒ Object
25 26 27 |
# File 'lib/trestle/form/fields/static_field.rb', line 25 def default_value builder.object.send(name) if builder.object end |
#field ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/trestle/form/fields/static_field.rb', line 17 def field if block template.capture(&block) else content_tag(:p, value || default_value, class: "form-control-static") end end |