storefront 0.2.1 → 0.2.7

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.
Files changed (73) hide show
  1. data/Rakefile +2 -2
  2. data/lib/storefront.rb +21 -3
  3. data/lib/storefront/configuration.rb +154 -0
  4. data/lib/storefront/dashboard.rb +8 -7
  5. data/lib/storefront/form.rb +70 -53
  6. data/lib/storefront/form/base.rb +50 -0
  7. data/lib/storefront/form/builder.rb +124 -0
  8. data/lib/storefront/form/errors.rb +20 -46
  9. data/lib/storefront/form/field.rb +102 -0
  10. data/lib/storefront/form/fieldset.rb +44 -0
  11. data/lib/storefront/form/hint.rb +34 -0
  12. data/lib/storefront/form/input.rb +191 -0
  13. data/lib/storefront/form/inputs/checkbox.rb +12 -0
  14. data/lib/storefront/form/inputs/date.rb +16 -0
  15. data/lib/storefront/form/inputs/file.rb +12 -0
  16. data/lib/storefront/form/inputs/hidden.rb +11 -0
  17. data/lib/storefront/form/inputs/radio.rb +11 -0
  18. data/lib/storefront/form/inputs/range.rb +15 -0
  19. data/lib/storefront/form/inputs/select.rb +68 -0
  20. data/lib/storefront/form/inputs/string.rb +89 -0
  21. data/lib/storefront/form/inputs/submit.rb +24 -0
  22. data/lib/storefront/form/inputs/textarea.rb +19 -0
  23. data/lib/storefront/form/inputs/value.rb +16 -0
  24. data/lib/storefront/form/label.rb +35 -0
  25. data/lib/storefront/helpers/attribute_helper.rb +29 -8
  26. data/lib/storefront/helpers/body_helper.rb +1 -1
  27. data/lib/storefront/helpers/cache_helper.rb +2 -2
  28. data/lib/storefront/helpers/component_helper.rb +34 -19
  29. data/lib/storefront/helpers/dashboard_helper.rb +9 -17
  30. data/lib/storefront/helpers/definition_list_helper.rb +82 -14
  31. data/lib/storefront/helpers/form_helper.rb +7 -2
  32. data/lib/storefront/helpers/head_helper.rb +2 -2
  33. data/lib/storefront/helpers/image_helper.rb +1 -25
  34. data/lib/storefront/helpers/list_helper.rb +120 -32
  35. data/lib/storefront/helpers/locale_helper.rb +98 -28
  36. data/lib/storefront/helpers/page_helper.rb +78 -60
  37. data/lib/storefront/helpers/request_helper.rb +3 -0
  38. data/lib/storefront/helpers/table_helper.rb +1 -1
  39. data/lib/storefront/helpers/template_helper.rb +11 -0
  40. data/lib/storefront/helpers/time_helper.rb +2 -2
  41. data/lib/storefront/helpers/widget_helper.rb +153 -2
  42. data/lib/storefront/model_helper.rb +17 -0
  43. data/lib/storefront/proxies/attribute_proxy.rb +150 -0
  44. data/lib/storefront/proxies/model_proxy.rb +249 -0
  45. data/lib/storefront/railtie.rb +4 -2
  46. data/lib/storefront/table.rb +7 -0
  47. data/test/form_helper_test.rb +1 -1
  48. metadata +25 -27
  49. data/init.rb +0 -1
  50. data/lib/storefront/form/elements.rb +0 -101
  51. data/lib/storefront/form/fields.rb +0 -420
  52. data/lib/storefront/form/hints.rb +0 -18
  53. data/lib/storefront/form/inputs.rb +0 -258
  54. data/lib/storefront/form/labels.rb +0 -81
  55. data/lib/storefront/form/model.rb +0 -84
  56. data/lib/storefront/microdata/address.rb +0 -7
  57. data/lib/storefront/microdata/event.rb +0 -13
  58. data/lib/storefront/microdata/geo.rb +0 -7
  59. data/lib/storefront/microdata/organization.rb +0 -7
  60. data/lib/storefront/microdata/person.rb +0 -7
  61. data/lib/storefront/microformat/event.rb +0 -7
  62. data/lib/storefront/microformat/person.rb +0 -7
  63. data/lib/storefront/models/container.rb +0 -0
  64. data/lib/storefront/models/element.rb +0 -15
  65. data/lib/storefront/models/form.rb +0 -0
  66. data/lib/storefront/models/form_element.rb +0 -0
  67. data/lib/storefront/models/link.rb +0 -0
  68. data/lib/storefront/models/list.rb +0 -0
  69. data/lib/storefront/models/list_element.rb +0 -0
  70. data/lib/storefront/models/table.rb +0 -0
  71. data/lib/storefront/models/term.rb +0 -0
  72. data/lib/storefront/models/term_list.rb +0 -0
  73. data/lib/storefront/models/validation.rb +0 -0
@@ -0,0 +1,12 @@
1
+ module Storefront
2
+ class Form
3
+ class Checkbox < Input
4
+ resolves :checkbox, :boolean
5
+
6
+ def checkbox_input
7
+ simple_input :checkbox
8
+ end
9
+ alias_method :boolean_input, :checkbox_input
10
+ end
11
+ end
12
+ end
@@ -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,12 @@
1
+ module Storefront
2
+ class Form
3
+ # :accept => "image/gif, image/jpg, image/png, image/jpeg"
4
+ class File < Input
5
+ resolves :file
6
+
7
+ def file_input(options = {})
8
+ simple_input :file, options
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Storefront
2
+ class Form
3
+ class Hidden < Input
4
+ resolves :hidden
5
+
6
+ def hidden_input(options = {})
7
+ simple_input :hidden, options
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Storefront
2
+ class Form
3
+ class Radio < Input
4
+ resolves :radio, :radiobutton
5
+
6
+ def radio_input(options = {})
7
+
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Storefront
2
+ class Form
3
+ class Range < Input
4
+ resolves :range, :slider
5
+
6
+ def range_input(options = {})
7
+
8
+ end
9
+
10
+ def slider_input(options = {})
11
+
12
+ end
13
+ end
14
+ end
15
+ 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,16 @@
1
+ module Storefront
2
+ class Form
3
+ class Value < Input
4
+ resolves :value
5
+
6
+ def initialize(options = {})
7
+ super
8
+ @value = attributes.delete(:value)
9
+ end
10
+
11
+ def value_input
12
+ base_input :output, value
13
+ end
14
+ end
15
+ end
16
+ 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 = args.shift
13
- sent_method = "#{method}_#{underscore_class_name(record)}"
25
+ record = args.shift
26
+ sent_method = "#{method}_for_#{underscore_class_name(record)}"
14
27
  if args.length > 0 && options = args.pop
15
- send(sent_method, record, options, &block)
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
- send(sent_method, record, &block)
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?
@@ -11,7 +11,7 @@ module Storefront
11
11
  def body_attributes(options = {})
12
12
  options[:class] = @body_class if @body_class
13
13
  options[:id] = @body_id if @body_id
14
-
14
+
15
15
  options
16
16
  end
17
17
  end
@@ -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 component_image_tag
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 popup_button(label, path, message, subtitle, submit = nil, kind = :group)
12
- link_to "<span>#{label}</span>", path, :class => "delete", "data-message" => message, "data-subtitle" => subtitle, "data-model" => kind.to_s, "data-submit" => submit.to_s
13
- end
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
- def component_button(*args, &block)
16
- options = args.extract_options!
17
- button_options = options.delete(:button_options) || {}
18
-
19
- if block_given?
20
- content = capture(&block)
21
- else
22
- label = args.shift
23
- path = args.shift
24
- content = link_to(label, path, button_options)
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 :button, options.merge(:class => ["button", options[:class]].compact.uniq.join(" ")) do
29
- haml_concat content
30
- haml_tag :span
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