storefront 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +4 -4
- data/lib/storefront.rb +22 -35
- data/lib/storefront/components/base.rb +99 -0
- data/lib/storefront/components/breadcrumb.rb +7 -0
- data/lib/storefront/components/button.rb +37 -0
- data/lib/storefront/components/definition_list.rb +34 -0
- data/lib/storefront/components/definition_list_item.rb +63 -0
- data/lib/storefront/components/flash.rb +12 -0
- data/lib/storefront/components/footer.rb +19 -0
- data/lib/storefront/components/form.rb +82 -0
- data/lib/storefront/{form → components/form}/base.rb +3 -3
- data/lib/storefront/{form → components/form}/builder.rb +3 -3
- data/lib/storefront/{form → components/form}/errors.rb +1 -3
- data/lib/storefront/{form → components/form}/field.rb +1 -1
- data/lib/storefront/{form → components/form}/fieldset.rb +0 -0
- data/lib/storefront/{form → components/form}/hint.rb +0 -0
- data/lib/storefront/{form → components/form}/input.rb +7 -5
- data/lib/storefront/components/form/inputs.rb +7 -0
- data/lib/storefront/{form → components/form}/inputs/checkbox.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/date.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/file.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/hidden.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/radio.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/range.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/select.rb +6 -6
- data/lib/storefront/{form → components/form}/inputs/string.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/submit.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/textarea.rb +0 -0
- data/lib/storefront/{form → components/form}/inputs/value.rb +0 -0
- data/lib/storefront/{form → components/form}/label.rb +1 -1
- data/lib/storefront/components/header.rb +73 -0
- data/lib/storefront/components/image.rb +12 -0
- data/lib/storefront/components/javascript_template.rb +21 -0
- data/lib/storefront/components/list.rb +27 -0
- data/lib/storefront/components/menu.rb +41 -0
- data/lib/storefront/components/nav.rb +78 -0
- data/lib/storefront/components/sidebar.rb +23 -0
- data/lib/storefront/components/table.rb +232 -0
- data/lib/storefront/components/text.rb +29 -0
- data/lib/storefront/configuration.rb +53 -5
- data/lib/storefront/helpers/cache_helper.rb +37 -19
- data/lib/storefront/helpers/component_helper.rb +80 -41
- data/lib/storefront/helpers/content_helper.rb +211 -0
- data/lib/storefront/helpers/dom_helper.rb +136 -0
- data/lib/storefront/helpers/head_helper.rb +277 -205
- data/lib/storefront/helpers/model_helper.rb +21 -0
- data/lib/storefront/helpers/request_helper.rb +301 -53
- data/lib/storefront/helpers/tag_helper.rb +29 -0
- data/lib/storefront/{proxies/attribute_proxy.rb → models/attribute.rb} +1 -1
- data/lib/storefront/{proxies/model_proxy.rb → models/model.rb} +4 -6
- data/lib/storefront/railtie.rb +3 -16
- metadata +48 -64
- data/lib/storefront/dashboard.rb +0 -185
- data/lib/storefront/form.rb +0 -82
- data/lib/storefront/helpers/attribute_helper.rb +0 -81
- data/lib/storefront/helpers/body_helper.rb +0 -18
- data/lib/storefront/helpers/browser_helper.rb +0 -54
- data/lib/storefront/helpers/collection_helper.rb +0 -14
- data/lib/storefront/helpers/dashboard_helper.rb +0 -29
- data/lib/storefront/helpers/debug_helper.rb +0 -11
- data/lib/storefront/helpers/definition_list_helper.rb +0 -110
- data/lib/storefront/helpers/error_helper.rb +0 -11
- data/lib/storefront/helpers/flash_helper.rb +0 -14
- data/lib/storefront/helpers/form_helper.rb +0 -13
- data/lib/storefront/helpers/format_helper.rb +0 -59
- data/lib/storefront/helpers/image_helper.rb +0 -30
- data/lib/storefront/helpers/list_helper.rb +0 -135
- data/lib/storefront/helpers/locale_helper.rb +0 -245
- data/lib/storefront/helpers/open_graph_helper.rb +0 -5
- data/lib/storefront/helpers/page_helper.rb +0 -91
- data/lib/storefront/helpers/presenter_helper.rb +0 -5
- data/lib/storefront/helpers/semantic/location_helper.rb +0 -18
- data/lib/storefront/helpers/semantic/time_helper.rb +0 -14
- data/lib/storefront/helpers/sidebar_helper.rb +0 -27
- data/lib/storefront/helpers/system_helper.rb +0 -18
- data/lib/storefront/helpers/table_helper.rb +0 -38
- data/lib/storefront/helpers/template_helper.rb +0 -11
- data/lib/storefront/helpers/time_helper.rb +0 -21
- data/lib/storefront/helpers/url_helper.rb +0 -32
- data/lib/storefront/helpers/user_helper.rb +0 -15
- data/lib/storefront/helpers/widget_helper.rb +0 -142
- data/lib/storefront/helpers/workflow_helper.rb +0 -50
- data/lib/storefront/model_helper.rb +0 -17
- data/lib/storefront/table.rb +0 -198
- data/rails/init.rb +0 -1
- data/test/form_helper_test.rb +0 -5
- data/test/support/mock_controller.rb +0 -15
- data/test/support/mock_response.rb +0 -14
- data/test/support/models.rb +0 -0
- data/test/test_helper.rb +0 -34
data/Rakefile
CHANGED
|
@@ -5,14 +5,14 @@ require 'rake/gempackagetask'
|
|
|
5
5
|
spec = Gem::Specification.new do |s|
|
|
6
6
|
s.name = "storefront"
|
|
7
7
|
s.authors = ["Lance Pollard"]
|
|
8
|
-
s.version = "0.
|
|
9
|
-
s.description = "
|
|
10
|
-
s.summary = "A simple and semantic FormBuilder, TableBuilder, Locale Interpolator, and Widget API for Rails 3"
|
|
8
|
+
s.version = "0.5.0"
|
|
9
|
+
s.description = "Opinionated Forms, Tables, and Widgets for Rails and Sinatra"
|
|
10
|
+
s.summary = "A simple and semantic FormBuilder, TableBuilder, Locale Interpolator, and Widget API for Rails 3 and Sinatra"
|
|
11
11
|
s.homepage = "http://github.com/viatropos/storefront"
|
|
12
12
|
s.email = "lancejpollard@gmail.com"
|
|
13
13
|
s.rubyforge_project = "storefront"
|
|
14
14
|
s.platform = Gem::Platform::RUBY
|
|
15
|
-
s.files = %w(Rakefile) + Dir["{lib
|
|
15
|
+
s.files = %w(Rakefile) + Dir["{lib}/**/*"]
|
|
16
16
|
s.require_path = "lib"
|
|
17
17
|
end
|
|
18
18
|
|
data/lib/storefront.rb
CHANGED
|
@@ -1,39 +1,26 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
require 'i18n'
|
|
4
|
+
require 'active_support'
|
|
5
|
+
require 'active_support/core_ext'
|
|
6
|
+
# require 'deli'
|
|
7
|
+
# require 'html-schema'
|
|
8
|
+
# require 'user_agent'
|
|
9
|
+
# require 'sanitize'
|
|
10
|
+
# require 'stringex'
|
|
11
|
+
# require 'kronic'
|
|
12
|
+
# require 'htmlentities'
|
|
13
|
+
# require 'smartypants'
|
|
14
|
+
require 'haml'
|
|
1
15
|
|
|
2
|
-
|
|
3
|
-
# for an SEO and easy to build page.
|
|
4
|
-
# It includes: metadata helpers, grid helpers (e.g. for photo gallerys),
|
|
5
|
-
# navigation helpers (menus and breadcrumbs),
|
|
6
|
-
# better render method so you can pass a block to partials
|
|
7
|
-
# http://github.com/rpheath/navigation_helper.git
|
|
8
|
-
# http://github.com/justinfrench/lovely-layouts.git
|
|
9
|
-
# http://github.com/ianwhite/truncate_html
|
|
10
|
-
# http://github.com/dekart/breadcrumbs.git
|
|
11
|
-
# http://github.com/html/once/blob/master/lib/once.rb
|
|
12
|
-
# http://github.com/fnando/breadcrumbs.git
|
|
13
|
-
# http://github.com/semanticart/smart-meta
|
|
14
|
-
base = "#{File.expand_path(File.dirname(__FILE__))}/storefront"
|
|
15
|
-
Dir["#{base}/railtie"]
|
|
16
|
-
Dir["#{base}/helpers/*"].each do |path|
|
|
17
|
-
require path unless ::File.directory?(path)
|
|
18
|
-
end
|
|
16
|
+
this = File.expand_path(File.dirname(__FILE__))
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
require "#{base}/form/input"
|
|
22
|
-
require "#{base}/form/builder"
|
|
18
|
+
$:.unshift this
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
require path unless ::File.directory?(path) || path =~ /helpers/
|
|
27
|
-
end
|
|
20
|
+
require "storefront/railtie"
|
|
21
|
+
require "storefront/configuration"
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def configuration
|
|
36
|
-
@configuration ||= Storefront::Configuration.new
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
23
|
+
Dir["#{this}/storefront/helpers/**/*"].each { |path| require path unless ::File.directory?(path) }
|
|
24
|
+
require "storefront/components/base"
|
|
25
|
+
Dir["#{this}/storefront/components/**/*"].each { |path| require path unless ::File.directory?(path) }
|
|
26
|
+
Dir["#{this}/storefront/models/**/*"].each { |path| require path unless ::File.directory?(path) }
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
module Storefront
|
|
2
|
+
module Components
|
|
3
|
+
class << self
|
|
4
|
+
def pointer
|
|
5
|
+
@pointer ||= []
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class Base
|
|
10
|
+
include Storefront::Helpers::ContentHelper
|
|
11
|
+
|
|
12
|
+
attr_reader :options, :template
|
|
13
|
+
|
|
14
|
+
def initialize(template, *args)
|
|
15
|
+
@template = template
|
|
16
|
+
@options = extract_options!(*args)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# The +to_s+ actually renders the object to HAML.
|
|
20
|
+
#
|
|
21
|
+
# This allows you to pass the widget into a variable the same way you would
|
|
22
|
+
# actually render it in HAML.
|
|
23
|
+
def render(&block)
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def render_with_pointer(&block)
|
|
28
|
+
pointer.push(component_name)
|
|
29
|
+
result = render(&block)
|
|
30
|
+
pointer.pop
|
|
31
|
+
result
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def inside?(key)
|
|
35
|
+
index = pointer.index(key)
|
|
36
|
+
!!(index && index >= 0 && index < pointer.length - 1)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def pointer
|
|
40
|
+
Storefront::Components.pointer
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_s
|
|
44
|
+
render
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def extract_options!(*args)
|
|
48
|
+
options = args.extract_options!
|
|
49
|
+
key = args.shift
|
|
50
|
+
|
|
51
|
+
options[:title] ||= false
|
|
52
|
+
options[:key] ||= key
|
|
53
|
+
options[:outer_html] ||= {}
|
|
54
|
+
|
|
55
|
+
options[:body_html] ||= {}
|
|
56
|
+
options[:footer_html] ||= {}
|
|
57
|
+
|
|
58
|
+
unless options[:widget_class] == false
|
|
59
|
+
merge_class! options[:outer_html], *extract_classes!(component_name)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
options
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def component_name
|
|
66
|
+
@component_name ||= self.class.name.split("::").last.underscore
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def extract_classes!(type)
|
|
70
|
+
[
|
|
71
|
+
storefront_config.widget_class,
|
|
72
|
+
type.to_s.strip.gsub(/[\s|_]+/, storefront_config.separator).squeeze(storefront_config.separator)
|
|
73
|
+
]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
protected
|
|
77
|
+
def config
|
|
78
|
+
Storefront.configuration
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def view_context
|
|
82
|
+
config.current_scope[:context].send(:view_context)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def method_missing(method, *args, &block)
|
|
86
|
+
if view_context.respond_to?(method)
|
|
87
|
+
self.class.class_eval %{
|
|
88
|
+
def #{method}(*args, &block)
|
|
89
|
+
view_context.#{method}(*args, &block)
|
|
90
|
+
end
|
|
91
|
+
}
|
|
92
|
+
send method, *args, &block
|
|
93
|
+
else
|
|
94
|
+
super
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Storefront
|
|
2
|
+
module Components
|
|
3
|
+
class Button < Base
|
|
4
|
+
def initialize(*args, &block)
|
|
5
|
+
attributes = args.extract_options!
|
|
6
|
+
label = args.shift
|
|
7
|
+
path = args.shift
|
|
8
|
+
tag = attributes.delete(:as)
|
|
9
|
+
|
|
10
|
+
inner_html = attributes.delete(:inner_html) || {}
|
|
11
|
+
outer_html = attributes.delete(:outer_html) || {}
|
|
12
|
+
|
|
13
|
+
inner_html.merge! clone_attributes(attributes)
|
|
14
|
+
outer_html.merge! clone_attributes(attributes.except(:rel, :target))
|
|
15
|
+
|
|
16
|
+
merge_class! outer_html, "button"
|
|
17
|
+
|
|
18
|
+
capture_haml do
|
|
19
|
+
haml_tag :div, :<, outer_html do
|
|
20
|
+
result = succeed "<span></span>".html_safe do
|
|
21
|
+
if block_given?
|
|
22
|
+
haml_concat capture_haml(&block).gsub("\n", "").strip
|
|
23
|
+
else
|
|
24
|
+
if tag
|
|
25
|
+
haml_tag tag, :>, :<, inner_html
|
|
26
|
+
else
|
|
27
|
+
haml_concat link_to(label, path, inner_html)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
haml_concat result
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Storefront
|
|
2
|
+
module Components
|
|
3
|
+
class DefinitionList < Storefront::Components::Base
|
|
4
|
+
def render(&block)
|
|
5
|
+
template.capture_haml do
|
|
6
|
+
template.haml_tag options[:as], options[:outer_html] do
|
|
7
|
+
@separator = options.has_key?(:separator) ? options[:separator] : config.term_separator
|
|
8
|
+
header = template.header_widget(options)
|
|
9
|
+
template.haml_concat header.gsub(/\n$/, "") if header.present?
|
|
10
|
+
|
|
11
|
+
template.haml_tag options[:tag], options[:content_html], &block
|
|
12
|
+
|
|
13
|
+
if options[:footer_html].present?
|
|
14
|
+
template.haml_concat template.footer_widget(options[:footer_html])
|
|
15
|
+
end
|
|
16
|
+
@separator = nil
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def extract_options!(*args)
|
|
22
|
+
options = super(*args)
|
|
23
|
+
|
|
24
|
+
options[:as] ||= :section
|
|
25
|
+
options[:tag] ||= config.terms_tag
|
|
26
|
+
|
|
27
|
+
options[:content_html] ||= {}
|
|
28
|
+
merge_class! options[:content_html], config.content_class
|
|
29
|
+
|
|
30
|
+
options
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Storefront
|
|
2
|
+
module Components
|
|
3
|
+
class DefinitionListItem < Storefront::Components::Base
|
|
4
|
+
def render(&block)
|
|
5
|
+
template.capture_haml do
|
|
6
|
+
template.haml_tag :dt, options[:key], options[:key_html] unless options[:key].nil?
|
|
7
|
+
|
|
8
|
+
if block_given? # i.e. multiple definitions for a term
|
|
9
|
+
template.haml_tag :dd, options[:value_html], &block
|
|
10
|
+
else
|
|
11
|
+
template.haml_tag :dd, options[:value], options[:value_html] unless options[:value].nil?
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def extract_options!(*args)
|
|
17
|
+
options = args.extract_options!
|
|
18
|
+
key = args.shift || options[:key]
|
|
19
|
+
value = args.shift || options[:value]
|
|
20
|
+
|
|
21
|
+
unless key.nil?
|
|
22
|
+
locale_options = options.delete(:locale_options) || {}
|
|
23
|
+
label = t?(key, locale_options.reverse_merge(:scope => :"terms.labels"))
|
|
24
|
+
|
|
25
|
+
if options[:auto_id] == true && !value.nil?
|
|
26
|
+
id_base = label.underscore.strip.gsub(/[\s|_]+/, config.separator).squeeze(config.separator)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
key_html = options.delete(:key_html) || {}
|
|
30
|
+
merge_class! key_html, config.term_key_class
|
|
31
|
+
|
|
32
|
+
if id_base
|
|
33
|
+
key_html[:id] ||= "#{id_base}-key"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
separator = options[:separator] || @separator
|
|
37
|
+
|
|
38
|
+
label.gsub!(/#{separator}?$/, separator) if separator.present?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
value_html = options.delete(:value_html) || {}
|
|
42
|
+
merge_class! value_html, config.term_value_class
|
|
43
|
+
|
|
44
|
+
if id_base
|
|
45
|
+
value_html[:id] ||= "#{id_base}-value"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if config.include_aria
|
|
49
|
+
value_html[:role] ||= :definition
|
|
50
|
+
value_html[:"aria-labelledby"] = key_html[:id] if key_html && key_html[:id]
|
|
51
|
+
#value_html[:"aria-describedby"] = hint_html[:id]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
options.merge(
|
|
55
|
+
:key => label,
|
|
56
|
+
:key_html => key_html,
|
|
57
|
+
:value => value,
|
|
58
|
+
:value_html => value_html
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Storefront
|
|
2
|
+
module Components
|
|
3
|
+
class Flash < Base
|
|
4
|
+
def render
|
|
5
|
+
flash_to_render = [:success, :failure, :notice, :error]
|
|
6
|
+
flash.select { |type, _| flash_to_render.include?(type) }.map do |type, content|
|
|
7
|
+
content_tag(:output, content, :class => "flash-#{type}")
|
|
8
|
+
end.join
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Storefront
|
|
2
|
+
module Components
|
|
3
|
+
class Footer < Base
|
|
4
|
+
def render(&block)
|
|
5
|
+
template.capture_haml do
|
|
6
|
+
if block_given?
|
|
7
|
+
template.haml_tag :footer, options[:outer_html], &block
|
|
8
|
+
else
|
|
9
|
+
template.haml_tag :footer, options[:outer_html]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def extract_options!(*args)
|
|
15
|
+
super(*args).reverse_merge(:title => false)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'storefront/components/form/base'
|
|
2
|
+
|
|
3
|
+
module Storefront
|
|
4
|
+
module Components
|
|
5
|
+
class Form < Base
|
|
6
|
+
attr_reader :model, :template, :tabindex, :access_keys, :attributes
|
|
7
|
+
delegate :object, :parent, :to => :model
|
|
8
|
+
|
|
9
|
+
def initialize(template, *args)
|
|
10
|
+
options = args.extract_options!
|
|
11
|
+
@template = template
|
|
12
|
+
@model = Storefront::Model.new(:object => extract_object!(args.shift))
|
|
13
|
+
@attributes = extract_attributes!(options)
|
|
14
|
+
@builder = Storefront::Form::Builder.new(
|
|
15
|
+
:template => template,
|
|
16
|
+
:tabindex => 1,
|
|
17
|
+
:access_keys => {},
|
|
18
|
+
:model => model
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def render(&block)
|
|
23
|
+
template.capture_haml do
|
|
24
|
+
template.haml_tag :form, attributes do
|
|
25
|
+
@builder.render(&block) if block_given?
|
|
26
|
+
|
|
27
|
+
unless attributes[:"data-method"] == attributes[:method]
|
|
28
|
+
template.haml_tag :input, :type => :hidden, :name => :_method, :value => attributes[:"data-method"]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
protected
|
|
35
|
+
def extract_object!(object)
|
|
36
|
+
if (object.is_a?(::Symbol) || object.is_a?(::String))
|
|
37
|
+
begin
|
|
38
|
+
"::#{object.to_s.camelize}".constantize.new
|
|
39
|
+
rescue Exception => e
|
|
40
|
+
result = ::OpenStruct.new
|
|
41
|
+
result.klass = object.to_s.camelize
|
|
42
|
+
result
|
|
43
|
+
end
|
|
44
|
+
else
|
|
45
|
+
object
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def config
|
|
50
|
+
Storefront.configuration
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def extract_attributes!(options = {})
|
|
54
|
+
attributes = options[:html] || {}
|
|
55
|
+
attributes[:action] = options[:url]
|
|
56
|
+
attributes[:class] = options[:class] if options.has_key?(:class)
|
|
57
|
+
merge_class! attributes, config.form_class
|
|
58
|
+
attributes[:id] = options[:id] if options.has_key?(:id)
|
|
59
|
+
#attributes[:id] ||=
|
|
60
|
+
attributes[:enctype] = "multipart/form-data" if (options[:multipart] || attributes.delete(:multipart)).to_s == "true"
|
|
61
|
+
attributes[:role] = :form
|
|
62
|
+
attributes[:novalidate] = "true" # needs to be true b/c the error popups are horribly ugly!# if options[:validate] == false
|
|
63
|
+
attributes[:"data-validate"] = options[:validate].to_s if options.has_key?(:validate)
|
|
64
|
+
|
|
65
|
+
method = attributes[:method] || options[:method]
|
|
66
|
+
|
|
67
|
+
if method.blank?
|
|
68
|
+
if @model.new_record?
|
|
69
|
+
method = :put
|
|
70
|
+
else
|
|
71
|
+
method = :post
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
attributes[:"data-method"] = method
|
|
76
|
+
attributes[:method] = method == :get ? :get : :post
|
|
77
|
+
|
|
78
|
+
attributes
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|