Sha256: d6a8edd8d2d1390604ff4a317747269cafbf9a6af7913ee12f5b9ae32ec18698

Contents?: true

Size: 884 Bytes

Versions: 5

Compression:

Stored size: 884 Bytes

Contents

module Formtastic
  module Inputs
    module Base
      module Inputmask
        def input_html_options
          super.tap do |options|
            if self.options.fetch(:mask, nil)
              options[:class] = [options[:class], 'inputmask'].compact.join(' ')
              options[:data] ||= {}
              options[:data].merge!(mask_options)
            end
          end
        end

        private

        def mask_options
          options = self.options.fetch(:mask)

          options =
            case options
            when Hash
              Hash[options.map { |k, v| [k.to_s.underscore.dasherize, v] }]
            when String
              { alias: options }
            else
              raise "Expected Hash or String got #{options.class}"
            end

          Hash[options.map { |k, v| ["inputmask-#{k}", v] }]
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
formtastic-jquery_inputmask-0.2.2 lib/formtastic/inputs/base/inputmask.rb
formtastic-jquery_inputmask-0.2.1 lib/formtastic/inputs/base/inputmask.rb
formtastic-jquery_inputmask-0.2.0 lib/formtastic/inputs/base/inputmask.rb
formtastic-jquery_inputmask-0.1.1 lib/formtastic/inputs/base/inputmask.rb
formtastic-jquery_inputmask-0.1.0 lib/formtastic/inputs/base/inputmask.rb