Class: Trestle::Form::Fields::StaticField

Inherits:
Trestle::Form::Field show all
Defined in:
lib/trestle/form/fields/static_field.rb

Instance Attribute Summary collapse

Attributes inherited from Trestle::Form::Field

#block, #builder, #name, #options, #template

Instance Method Summary collapse

Methods inherited from Trestle::Form::Field

#defaults, #disabled?, #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, options={}, &block)
  if value.is_a?(Hash)
    @value, options = nil, value
  else
    @value = value
  end

  super(builder, template, name, options, &block)
end

Instance Attribute Details

#valueObject (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_valueObject



25
26
27
# File 'lib/trestle/form/fields/static_field.rb', line 25

def default_value
  builder.object.send(name) if builder.object
end

#fieldObject



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
    (:p, value || default_value, class: "form-control-static")
  end
end