Sha256: fe984981be3ca1d15d63879714cab53aec3428bc884a503aca9eb029a40d4529

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

module Trestle
  class Form
    module Fields
      class FormControl < Field
        def render
          form_group do
            input_group do
              field
            end
          end
        end

        def input_group
          if @prepend || @append
            content_tag(:div, class: "input-group") do
              concat input_group_addon(@prepend) if @prepend
              concat yield
              concat input_group_addon(@append) if @append
            end
          else
            yield
          end
        end

        def input_group_addon(addon)
          if addon[:wrap]
            content_tag(:span, addon[:content], class: "input-group-text")
          else
            addon[:content]
          end
        end

        def defaults
          super.merge(class: ["form-control"])
        end

        def normalize_options!
          super

          @prepend = { content: options.delete(:prepend),  wrap: true }  if options[:prepend]
          @prepend = { content: options.delete(:prepend!), wrap: false } if options[:prepend!]
          @append  = { content: options.delete(:append),   wrap: true }  if options[:append]
          @append  = { content: options.delete(:append!),  wrap: false } if options[:append!]
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trestle-0.10.0 lib/trestle/form/fields/form_control.rb
trestle-0.10.0.pre2 lib/trestle/form/fields/form_control.rb
trestle-0.10.0.pre lib/trestle/form/fields/form_control.rb