Sha256: bb9b87a6ca188915ecfc08c219b741cdfd2887aca0f313230a84b0408e1aa196

Contents?: true

Size: 787 Bytes

Versions: 8

Compression:

Stored size: 787 Bytes

Contents

module Trestle
  class Form
    module Fields
      class StaticField < Field
        attr_reader :value

        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

        def field
          if block
            template.capture(&block)
          else
            content_tag(:p, value || default_value, class: "form-control-static")
          end
        end

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

Trestle::Form::Builder.register(:static_field, Trestle::Form::Fields::StaticField)

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
trestle-0.10.0 lib/trestle/form/fields/static_field.rb
trestle-0.10.0.pre2 lib/trestle/form/fields/static_field.rb
trestle-0.10.0.pre lib/trestle/form/fields/static_field.rb
trestle-0.9.8 lib/trestle/form/fields/static_field.rb
trestle-0.9.7 lib/trestle/form/fields/static_field.rb
trestle-0.9.6 lib/trestle/form/fields/static_field.rb
trestle-0.9.5 lib/trestle/form/fields/static_field.rb
trestle-0.9.4 lib/trestle/form/fields/static_field.rb