module Storefront class Form class Base include Storefront::LocaleHelper include Storefront::AttributeHelper def initialize(options = {}) @template = options[:template] @model = options[:model] @attribute = options[:attribute] @parent_index = options[:parent_index] @index = options[:index] @tabindex = options[:tabindex] @access_keys = options[:access_keys] @attributes = clone_attributes(options.except(:template, :model, :attribute, :access_keys, :index, :tabindex)) end protected attr_accessor :template, :model, :attribute, :index, :parent_index attr_accessor :attributes, :value, :label, :access_keys, :tabindex, :input_type def default_options!(options = {}) options[:model] ||= model options[:index] ||= index options[:attribute] ||= attribute options[:template] ||= template options end def config Storefront.configuration end alias_method :storefront_config, :config def value? @value.present? end def localize(key, attribute, default, options = {}) if default.present? return default.to_s unless default.is_a?(::Symbol) attribute = default end t?(attribute, options.reverse_merge(:scope => :"forms.#{key}", :model => model.object)) end end end end