Sha256: 938fff050641ea11b85da1f19646cdae2b8165b84a74dbf556a9fa7d2fe8e133

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module ExtForm
  module Wrappers
    module Mixin
      extend ActiveSupport::Concern

      def wrap_style_options(input, type, namespace)
        l = input.l
        options = input.options

        if l.instance_of?(ExtForm::Layouts::DefaultLayout)
          default_style_options(l, type, namespace, options)
          input.input_html_classes.unshift('input-with-layout') if type == 'input'
        else
          bootstrap_style_options(l, type, namespace, options)
          input.input_html_classes.unshift(options[:"#{namespace}_html"][:class]) if type == 'input'
        end
      end

      private
      def default_style_options(l, type, namespace, options={})
        html_option = options.delete(:"#{namespace}_html") || {}

        style = []
        style << html_option.delete(:style)
        style << "width: #{l.send("#{type}_width", options[:input_seq]%l.layout.size)}#{l.layout_config[:measure]}; " \
                 "float: left;"

        html_option[:style] = style.compact.join(';')

        options[:"#{namespace}_html"] = html_option
        options
      end

      def bootstrap_style_options(l, type, namespace, options={})
        html_option = options.delete(:"#{namespace}_html") || {}

        clazz = []
        clazz << html_option.delete(:class)
        clazz << "span#{l.send("#{type}_width", options[:input_seq]%l.layout.size)}"

        html_option[:class] = clazz.compact.join(' ')

        options[:"#{namespace}_html"] = html_option
        options
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ext_form-0.1.5 lib/ext_form/wrappers/mixin.rb
ext_form-0.1.4 lib/ext_form/wrappers/mixin.rb