storefront 0.2.1 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/storefront.rb +21 -3
- data/lib/storefront/configuration.rb +154 -0
- data/lib/storefront/dashboard.rb +8 -7
- data/lib/storefront/form.rb +70 -53
- data/lib/storefront/form/base.rb +50 -0
- data/lib/storefront/form/builder.rb +124 -0
- data/lib/storefront/form/errors.rb +20 -46
- data/lib/storefront/form/field.rb +102 -0
- data/lib/storefront/form/fieldset.rb +44 -0
- data/lib/storefront/form/hint.rb +34 -0
- data/lib/storefront/form/input.rb +191 -0
- data/lib/storefront/form/inputs/checkbox.rb +12 -0
- data/lib/storefront/form/inputs/date.rb +16 -0
- data/lib/storefront/form/inputs/file.rb +12 -0
- data/lib/storefront/form/inputs/hidden.rb +11 -0
- data/lib/storefront/form/inputs/radio.rb +11 -0
- data/lib/storefront/form/inputs/range.rb +15 -0
- data/lib/storefront/form/inputs/select.rb +68 -0
- data/lib/storefront/form/inputs/string.rb +89 -0
- data/lib/storefront/form/inputs/submit.rb +24 -0
- data/lib/storefront/form/inputs/textarea.rb +19 -0
- data/lib/storefront/form/inputs/value.rb +16 -0
- data/lib/storefront/form/label.rb +35 -0
- data/lib/storefront/helpers/attribute_helper.rb +29 -8
- data/lib/storefront/helpers/body_helper.rb +1 -1
- data/lib/storefront/helpers/cache_helper.rb +2 -2
- data/lib/storefront/helpers/component_helper.rb +34 -19
- data/lib/storefront/helpers/dashboard_helper.rb +9 -17
- data/lib/storefront/helpers/definition_list_helper.rb +82 -14
- data/lib/storefront/helpers/form_helper.rb +7 -2
- data/lib/storefront/helpers/head_helper.rb +2 -2
- data/lib/storefront/helpers/image_helper.rb +1 -25
- data/lib/storefront/helpers/list_helper.rb +120 -32
- data/lib/storefront/helpers/locale_helper.rb +98 -28
- data/lib/storefront/helpers/page_helper.rb +78 -60
- data/lib/storefront/helpers/request_helper.rb +3 -0
- data/lib/storefront/helpers/table_helper.rb +1 -1
- data/lib/storefront/helpers/template_helper.rb +11 -0
- data/lib/storefront/helpers/time_helper.rb +2 -2
- data/lib/storefront/helpers/widget_helper.rb +153 -2
- data/lib/storefront/model_helper.rb +17 -0
- data/lib/storefront/proxies/attribute_proxy.rb +150 -0
- data/lib/storefront/proxies/model_proxy.rb +249 -0
- data/lib/storefront/railtie.rb +4 -2
- data/lib/storefront/table.rb +7 -0
- data/test/form_helper_test.rb +1 -1
- metadata +25 -27
- data/init.rb +0 -1
- data/lib/storefront/form/elements.rb +0 -101
- data/lib/storefront/form/fields.rb +0 -420
- data/lib/storefront/form/hints.rb +0 -18
- data/lib/storefront/form/inputs.rb +0 -258
- data/lib/storefront/form/labels.rb +0 -81
- data/lib/storefront/form/model.rb +0 -84
- data/lib/storefront/microdata/address.rb +0 -7
- data/lib/storefront/microdata/event.rb +0 -13
- data/lib/storefront/microdata/geo.rb +0 -7
- data/lib/storefront/microdata/organization.rb +0 -7
- data/lib/storefront/microdata/person.rb +0 -7
- data/lib/storefront/microformat/event.rb +0 -7
- data/lib/storefront/microformat/person.rb +0 -7
- data/lib/storefront/models/container.rb +0 -0
- data/lib/storefront/models/element.rb +0 -15
- data/lib/storefront/models/form.rb +0 -0
- data/lib/storefront/models/form_element.rb +0 -0
- data/lib/storefront/models/link.rb +0 -0
- data/lib/storefront/models/list.rb +0 -0
- data/lib/storefront/models/list_element.rb +0 -0
- data/lib/storefront/models/table.rb +0 -0
- data/lib/storefront/models/term.rb +0 -0
- data/lib/storefront/models/term_list.rb +0 -0
- data/lib/storefront/models/validation.rb +0 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module Storefront
|
2
|
+
class Form
|
3
|
+
# accepted attributes: autocomplete, autofocus, list, max, min, readonly, required, step
|
4
|
+
class Date < Input
|
5
|
+
resolves :date, :datetime, :time, :month, :week
|
6
|
+
|
7
|
+
def range_input(options = {})
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def date_range_input(options = {})
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Storefront
|
2
|
+
class Form
|
3
|
+
# attributes: prompt, blank, multiple
|
4
|
+
class Select < Input
|
5
|
+
resolves :select
|
6
|
+
|
7
|
+
def select_input(options = {})
|
8
|
+
collection = self.collection
|
9
|
+
collection = [[prompt, ""]] + collection if prompt.present?
|
10
|
+
@value = attributes.delete(:value)
|
11
|
+
|
12
|
+
base_input :select, attributes.merge(options) do
|
13
|
+
collection_iterator(collection, value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def collection_iterator(collection, selected = nil)
|
18
|
+
collection.map do |item|
|
19
|
+
name, options = item, {}
|
20
|
+
optgroup = false
|
21
|
+
case item
|
22
|
+
when Array
|
23
|
+
name = item[0]
|
24
|
+
options[:value] = item[1]
|
25
|
+
when Hash
|
26
|
+
name = item[:name]
|
27
|
+
options[:value] = item[:value]
|
28
|
+
optgroup = item[:children].present?
|
29
|
+
when ::String, ::Float, ::Integer, ::BigDecimal
|
30
|
+
options[:value] = item.to_s
|
31
|
+
else
|
32
|
+
name = item.name.strip.humanize
|
33
|
+
options[:value] = item.id
|
34
|
+
end
|
35
|
+
if optgroup
|
36
|
+
template.capture_haml do
|
37
|
+
template.haml_tag :optgroup, :label => options[:name], :"data-value" => options[:value] do
|
38
|
+
collection_iterator(item[:children], selected)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
else
|
42
|
+
options[:selected] = "true" if selected.present? && options[:value] == selected
|
43
|
+
template.haml_tag :option, name, options
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def boolean_collection(options = {})
|
49
|
+
[["Yes", true], ["No", false]]
|
50
|
+
end
|
51
|
+
|
52
|
+
def collection
|
53
|
+
if @collection.nil?
|
54
|
+
@collection = Array(attributes.delete(:collection) || [])
|
55
|
+
end
|
56
|
+
|
57
|
+
@collection
|
58
|
+
end
|
59
|
+
|
60
|
+
def prompt
|
61
|
+
if @prompt.nil? && include_blank
|
62
|
+
@prompt = localize(:prompts, attribute.name, attributes.delete(:prompt), :allow_blank => true)
|
63
|
+
end
|
64
|
+
@prompt
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Storefront
|
2
|
+
class Form
|
3
|
+
# email attributes: autocomplete, autofocus, list, maxlength, multiple, pattern, placeholder, readonly, required, size
|
4
|
+
# password attributes: autocomplete, autofocus, maxlength, pattern, placeholder, readonly, required, size
|
5
|
+
# text, search, url, tel attributes: autocomplete, autofocus, list, maxlength, pattern, placeholder, readonly, required, size
|
6
|
+
class String < Input
|
7
|
+
resolves :string, :phone, :url, :email, :search, :date, :datetime, :time, :numeric, :number, :money, :percent, :password
|
8
|
+
|
9
|
+
# autofocus, pattern, placeholder, title, size, data-validate, data-validate-match, data-validate-unique
|
10
|
+
def string_input
|
11
|
+
simple_input :string
|
12
|
+
end
|
13
|
+
|
14
|
+
def password_input
|
15
|
+
simple_input :password
|
16
|
+
end
|
17
|
+
|
18
|
+
def email_input
|
19
|
+
simple_input :email
|
20
|
+
end
|
21
|
+
|
22
|
+
def url_input
|
23
|
+
simple_input :url
|
24
|
+
end
|
25
|
+
|
26
|
+
def number_input
|
27
|
+
simple_input :string, :class => "numeric", "data-type" => "numeric"
|
28
|
+
end
|
29
|
+
|
30
|
+
def numeric_input
|
31
|
+
simple_input :string, :class => "numeric", "data-type" => "numeric"
|
32
|
+
end
|
33
|
+
|
34
|
+
def search_input
|
35
|
+
simple_input :search, :class => "search", "data-type" => "search"
|
36
|
+
end
|
37
|
+
|
38
|
+
def phone_input
|
39
|
+
simple_input :tel, :class => "phone"
|
40
|
+
end
|
41
|
+
|
42
|
+
def fax_input
|
43
|
+
simple_input :tel, :class => "phone fax"
|
44
|
+
end
|
45
|
+
|
46
|
+
def date_input
|
47
|
+
simple_input :string, :class => "date", "data-type" => "date"
|
48
|
+
end
|
49
|
+
|
50
|
+
def money_input
|
51
|
+
simple_input :string, :class => "money", "data-type" => "money"
|
52
|
+
end
|
53
|
+
|
54
|
+
def percent_input
|
55
|
+
simple_input :string, :class => "percent", "data-type" => "percent"
|
56
|
+
end
|
57
|
+
|
58
|
+
def color_input
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def autocomplete_input
|
63
|
+
=begin
|
64
|
+
default = options[:default]
|
65
|
+
#attribute = "#{attribute}".gsub(/_id$/, "")
|
66
|
+
if default.present?
|
67
|
+
name = default.name rescue ""
|
68
|
+
else
|
69
|
+
name = (object.send("#{attribute}".gsub(/_id$/, "")).name || "") rescue ""
|
70
|
+
end
|
71
|
+
|
72
|
+
options[:value] ||= default_id_for(default || object.send("#{attribute}".gsub(/_id$/, "")))
|
73
|
+
value = User.find_by_id(options[:value])
|
74
|
+
name = value.name if value
|
75
|
+
value = value.id if value
|
76
|
+
|
77
|
+
result = input(attribute, :as => :hidden, :input_html => {:class => "hidden-autocomplete", :value => value})
|
78
|
+
|
79
|
+
options[:input_html] ||= {}
|
80
|
+
options[:input_html].merge!(:class => "autocomplete-two", :value => name)
|
81
|
+
|
82
|
+
result += input("#{attribute}".gsub(/_id$/, ""), options)
|
83
|
+
|
84
|
+
result
|
85
|
+
=end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Storefront
|
2
|
+
class Form
|
3
|
+
class Submit < Input
|
4
|
+
resolves :submit, :confirm, :button
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
super
|
8
|
+
|
9
|
+
attributes.delete(:name)
|
10
|
+
attributes.delete(:accesskey)
|
11
|
+
end
|
12
|
+
|
13
|
+
def submit_input
|
14
|
+
if config.rich_input
|
15
|
+
rich_input :submit
|
16
|
+
else
|
17
|
+
simple_input :submit
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias_method :confirm_input, :submit_input
|
21
|
+
alias_method :button_input, :submit_input
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Storefront
|
2
|
+
class Form
|
3
|
+
# attributes: maxlength, placeholder, required, wrap, readonly
|
4
|
+
class Textarea < Input
|
5
|
+
resolves :text, :textarea, :watched
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
super
|
9
|
+
|
10
|
+
@value = attributes.delete(:value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def textarea_input(options = {})
|
14
|
+
base_input :textarea, value, options
|
15
|
+
end
|
16
|
+
alias_method :text_input, :textarea_input
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Storefront
|
2
|
+
class Form
|
3
|
+
class Label < Storefront::Form::Base
|
4
|
+
def initialize(options = {})
|
5
|
+
super
|
6
|
+
|
7
|
+
attributes.merge!(options[:label_html]) if options[:label_html]
|
8
|
+
attributes.delete :label_html
|
9
|
+
attributes.delete :label
|
10
|
+
|
11
|
+
unless options[:label] == false
|
12
|
+
merge_class! attributes, config.label_class
|
13
|
+
attributes[:id] ||= attribute.to_id(:type => :error, :index => index, :parent_index => parent_index) if config.id_enabled_on.include?("label")
|
14
|
+
attributes[:for] ||= attribute.to_id(:type => :input, :index => index, :parent_index => parent_index)
|
15
|
+
|
16
|
+
@value = localize(:labels, attribute.name, options[:label].is_a?(::String) ? options[:label] : nil)
|
17
|
+
@value = attribute.to_label if @value.blank?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def render(&block)
|
22
|
+
template.capture_haml do
|
23
|
+
template.haml_tag :label, attributes do
|
24
|
+
template.haml_tag :span, value
|
25
|
+
if attribute.required?
|
26
|
+
template.haml_tag :abbr, config.required_abbr, :title => config.required_title, :class => config.required_class
|
27
|
+
else
|
28
|
+
template.haml_tag :abbr, config.optional_abbr, :title => config.optional_title, :class => config.optional_class
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,30 +1,51 @@
|
|
1
1
|
module Storefront
|
2
2
|
module AttributeHelper
|
3
|
+
def clone_attributes(hash)
|
4
|
+
result = {}
|
5
|
+
return result if hash.blank?
|
6
|
+
hash.each do |key, value|
|
7
|
+
result[key] = value.is_a?(::Hash) ? clone_attributes(value) : value
|
8
|
+
end
|
9
|
+
result
|
10
|
+
end
|
11
|
+
|
12
|
+
def storefront_config
|
13
|
+
Storefront.configuration
|
14
|
+
end
|
15
|
+
|
3
16
|
def underscore_class_name(record)
|
4
17
|
record.class.base_class.snake_case
|
5
18
|
end
|
6
|
-
|
19
|
+
|
7
20
|
def datetime_for(time)
|
8
21
|
with_time_at time
|
9
22
|
end
|
10
|
-
|
23
|
+
|
11
24
|
def record_method(method, *args, &block)
|
12
|
-
record
|
13
|
-
sent_method
|
25
|
+
record = args.shift
|
26
|
+
sent_method = "#{method}_for_#{underscore_class_name(record)}"
|
14
27
|
if args.length > 0 && options = args.pop
|
15
|
-
|
28
|
+
if !respond_to?(sent_method) && record.respond_to?(:presenter) && record.presenter.present? && record.presenter.respond_to?(method)
|
29
|
+
record.presenter.send(method, options)
|
30
|
+
else
|
31
|
+
send(sent_method, record, options, &block)
|
32
|
+
end
|
16
33
|
else
|
17
|
-
|
34
|
+
if !respond_to?(sent_method) && record.respond_to?(:presenter) && record.presenter.present? && record.presenter.respond_to?(method)
|
35
|
+
record.presenter.send(method)
|
36
|
+
else
|
37
|
+
send(sent_method, record, &block)
|
38
|
+
end
|
18
39
|
end
|
19
40
|
end
|
20
|
-
|
41
|
+
|
21
42
|
def merge_class!(attributes, *values)
|
22
43
|
return {} if attributes.nil?
|
23
44
|
hash = merge_class(attributes, *values)
|
24
45
|
attributes[:class] = hash[:class] if hash
|
25
46
|
attributes
|
26
47
|
end
|
27
|
-
|
48
|
+
|
28
49
|
def merge_class(attributes, *values)
|
29
50
|
if values.present?
|
30
51
|
if attributes[:class].present?
|
@@ -3,7 +3,7 @@ module Storefront
|
|
3
3
|
def optional_cache(key, &block)
|
4
4
|
cache(key, &block) unless session[:disable_caching]
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def conditional_cache(key, options = {}, &block)
|
8
8
|
condition = true
|
9
9
|
condition = false if options.has_key?(:if) && options[:if] != true
|
@@ -13,7 +13,7 @@ module Storefront
|
|
13
13
|
haml_concat capture_haml(&block)
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def set_cache_buster
|
18
18
|
if request.xhr?
|
19
19
|
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
@@ -1,35 +1,50 @@
|
|
1
1
|
module Storefront
|
2
2
|
# Encapsulates common browser hacks
|
3
3
|
module ComponentHelper
|
4
|
-
def
|
4
|
+
def rich_image_tag(label, path, options = {})
|
5
5
|
capture_haml do
|
6
6
|
haml_tag :span
|
7
|
-
haml_concat image_tag()
|
7
|
+
haml_concat image_tag(label, path, options)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
11
|
+
def rich_button(*args, &block)
|
12
|
+
attributes = args.extract_options!
|
13
|
+
label = args.shift
|
14
|
+
path = args.shift
|
15
|
+
tag = attributes.delete(:as)
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
17
|
+
#locale_options = attributes.delete(:locale_options) || {}
|
18
|
+
#label = t?(label, locale_options.reverse_merge(:scope => :"buttons"))
|
19
|
+
|
20
|
+
inner_html = attributes.delete(:inner_html) || {}
|
21
|
+
outer_html = attributes.delete(:outer_html) || {}
|
22
|
+
|
23
|
+
inner_html.merge! clone_attributes(attributes)
|
24
|
+
outer_html.merge! clone_attributes(attributes.except(:rel, :target))
|
25
|
+
|
26
|
+
merge_class! outer_html, "button"
|
26
27
|
|
27
28
|
capture_haml do
|
28
|
-
haml_tag :
|
29
|
-
|
30
|
-
|
29
|
+
haml_tag :div, :<, outer_html do
|
30
|
+
result = succeed "<span></span>".html_safe do
|
31
|
+
if block_given?
|
32
|
+
haml_concat capture_haml(&block).gsub("\n", "").strip
|
33
|
+
else
|
34
|
+
if tag
|
35
|
+
haml_tag tag, :>, :<, inner_html
|
36
|
+
else
|
37
|
+
haml_concat link_to(label, path, inner_html)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
haml_concat result
|
31
42
|
end
|
32
43
|
end
|
33
44
|
end
|
45
|
+
|
46
|
+
def rich_input(*args, &block)
|
47
|
+
|
48
|
+
end
|
34
49
|
end
|
35
50
|
end
|