storefront 0.2.1 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,81 +0,0 @@
1
- module Storefront
2
- class Form
3
- module Labels
4
- def label_for(key, options = {})
5
- attributes = options[:label_attributes]
6
- text = attributes.delete(:value)
7
- result = template.capture_haml do
8
- template.haml_tag :label, options[:label_attributes] do
9
- template.haml_tag :span, text
10
- if options[:required] == true
11
- template.haml_tag :abbr, "*", :title => "required"
12
- else
13
- template.haml_tag :abbr, "", :title => "optional"
14
- end
15
- end
16
- end
17
- result
18
- end
19
-
20
- def label_method
21
- :titleize
22
- end
23
-
24
- def humanized_attribute_name(method) #:nodoc:
25
- if @object && @object.class.respond_to?(:human_attribute_name)
26
- humanized_name = @object.class.human_attribute_name(method.to_s)
27
- if humanized_name == method.to_s.send(:humanize)
28
- method.to_s.send(label_method)
29
- else
30
- humanized_name
31
- end
32
- else
33
- method.to_s.send(label_method)
34
- end
35
- end
36
-
37
- def localized_string(key, value, type, options = {}) #:nodoc:
38
- key = value if value.is_a?(::Symbol)
39
-
40
- if value.is_a?(::String)
41
- value.html_safe
42
- else
43
- use_i18n = true
44
-
45
- if use_i18n
46
- model_name, nested_model_name = normalize_model_name(self.model_name.underscore)
47
- action_name = template.params[:action].to_s rescue ''
48
- attribute_name = key.to_s
49
-
50
- defaults = ::Formtastic::I18n::SCOPES.reject do |i18n_scope|
51
- nested_model_name.nil? && i18n_scope.match(/nested_model/)
52
- end.collect do |i18n_scope|
53
- i18n_path = i18n_scope.dup
54
- i18n_path.gsub!('%{action}', action_name)
55
- i18n_path.gsub!('%{model}', model_name)
56
- i18n_path.gsub!('%{nested_model}', nested_model_name) unless nested_model_name.nil?
57
- i18n_path.gsub!('%{attribute}', attribute_name)
58
- i18n_path.gsub!('..', '.')
59
- i18n_path.to_sym
60
- end
61
- defaults << ''
62
-
63
- defaults.uniq!
64
-
65
- default_key = defaults.shift
66
- i18n_value = ::Formtastic::I18n.t(default_key,
67
- options.merge(:default => defaults, :scope => type.to_s.pluralize.to_sym))
68
- if i18n_value.blank? && type == :label
69
- # This is effectively what Rails label helper does for i18n lookup
70
- options[:scope] = [:helpers, type]
71
- options[:default] = defaults
72
- i18n_value = ::I18n.t(default_key, options)
73
- end
74
-
75
- i18n_value.blank? ? nil : i18n_value
76
- end
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,84 +0,0 @@
1
- module Storefront
2
- class Form
3
- module Model
4
- def model_name
5
- @object.present? ? @object.class.name : @object_name.to_s.classify
6
- end
7
-
8
- def normalize_model_name(name)
9
- if name =~ /(.+)\[(.+)\]/
10
- [$1, $2]
11
- else
12
- [name]
13
- end
14
- end
15
-
16
- # If an association method is passed in (f.input :author) try to find the
17
- # reflection object.
18
- #
19
- def reflection_for(method) #:nodoc:
20
- @object.class.reflect_on_association(method) if @object.class.respond_to?(:reflect_on_association)
21
- end
22
-
23
- # Get a column object for a specified attribute method - if possible.
24
- #
25
- def column_for(method) #:nodoc:
26
- @object.column_for_attribute(method) if @object.respond_to?(:column_for_attribute)
27
- end
28
-
29
- def validations_for(method, mode = :active)
30
- # ActiveModel?
31
- validations = if @object && @object.class.respond_to?(:validators_on)
32
- @object.class.validators_on(method)
33
- else
34
- # ValidationReflection plugin?
35
- if @object && @object.class.respond_to?(:reflect_on_validations_for)
36
- @object.class.reflect_on_validations_for(method)
37
- else
38
- []
39
- end
40
- end
41
-
42
- validations = validations.select do |validation|
43
- (validation.options.present? ? options_require_validation?(validation.options) : true)
44
- end unless mode == :all
45
-
46
- return validations
47
- end
48
-
49
- def sanitized_object_name #:nodoc:
50
- @sanitized_object_name ||= @object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
51
- end
52
-
53
- def get_maxlength_for(method)
54
- validation = validations_for(method).find do |validation|
55
- (validation.respond_to?(:macro) && validation.macro == :validates_length_of) || # Rails 2 validation
56
- (validation.respond_to?(:kind) && validation.kind == :length) # Rails 3 validator
57
- end
58
-
59
- if validation
60
- validation.options[:maximum] || (validation.options[:within].present? ? validation.options[:within].max : nil)
61
- else
62
- nil
63
- end
64
- end
65
-
66
- def default_string_options(method, type) #:nodoc:
67
- validation_max_limit = get_maxlength_for(method)
68
- column = column_for(method)
69
-
70
- if type == :text
71
- { :rows => default_text_area_height,
72
- :cols => default_text_area_width }
73
- elsif type == :numeric || column.nil? || !column.respond_to?(:limit) || column.limit.nil?
74
- { :maxlength => validation_max_limit,
75
- :size => default_text_field_size }
76
- else
77
- { :maxlength => validation_max_limit || column.limit,
78
- :size => default_text_field_size }
79
- end
80
- end
81
-
82
- end
83
- end
84
- end
@@ -1,7 +0,0 @@
1
- module Storefront
2
- module Microdata
3
- class Address
4
-
5
- end
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- module Storefront
2
- module Microdata
3
- class Event
4
- def initialize(options = {})
5
-
6
- end
7
-
8
- def root_attributes
9
- {:itemscope => "http://data-vocabulary.org/Event"}
10
- end
11
- end
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- module Storefront
2
- module Microdata
3
- class Geo
4
-
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module Storefront
2
- module Microdata
3
- class Organization
4
-
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module Storefront
2
- module Microdata
3
- class Person
4
-
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module Storefront
2
- module Microformat
3
- class Event
4
-
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module Storefront
2
- module Microformat
3
- class Person
4
-
5
- end
6
- end
7
- end
File without changes
@@ -1,15 +0,0 @@
1
- module Storefront
2
- class Element
3
- attr_accessor :label, :name, :id, :value, :url, :validations, :hint, :tip, :required, :disabled
4
-
5
- def initialize(attributes = {})
6
- attributes.each do |key, value|
7
- send("#{key}=", value)
8
- end
9
- end
10
-
11
- def to_json
12
-
13
- end
14
- end
15
- end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes