storefront 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/Rakefile +4 -4
  2. data/lib/storefront.rb +22 -35
  3. data/lib/storefront/components/base.rb +99 -0
  4. data/lib/storefront/components/breadcrumb.rb +7 -0
  5. data/lib/storefront/components/button.rb +37 -0
  6. data/lib/storefront/components/definition_list.rb +34 -0
  7. data/lib/storefront/components/definition_list_item.rb +63 -0
  8. data/lib/storefront/components/flash.rb +12 -0
  9. data/lib/storefront/components/footer.rb +19 -0
  10. data/lib/storefront/components/form.rb +82 -0
  11. data/lib/storefront/{form → components/form}/base.rb +3 -3
  12. data/lib/storefront/{form → components/form}/builder.rb +3 -3
  13. data/lib/storefront/{form → components/form}/errors.rb +1 -3
  14. data/lib/storefront/{form → components/form}/field.rb +1 -1
  15. data/lib/storefront/{form → components/form}/fieldset.rb +0 -0
  16. data/lib/storefront/{form → components/form}/hint.rb +0 -0
  17. data/lib/storefront/{form → components/form}/input.rb +7 -5
  18. data/lib/storefront/components/form/inputs.rb +7 -0
  19. data/lib/storefront/{form → components/form}/inputs/checkbox.rb +0 -0
  20. data/lib/storefront/{form → components/form}/inputs/date.rb +0 -0
  21. data/lib/storefront/{form → components/form}/inputs/file.rb +0 -0
  22. data/lib/storefront/{form → components/form}/inputs/hidden.rb +0 -0
  23. data/lib/storefront/{form → components/form}/inputs/radio.rb +0 -0
  24. data/lib/storefront/{form → components/form}/inputs/range.rb +0 -0
  25. data/lib/storefront/{form → components/form}/inputs/select.rb +6 -6
  26. data/lib/storefront/{form → components/form}/inputs/string.rb +0 -0
  27. data/lib/storefront/{form → components/form}/inputs/submit.rb +0 -0
  28. data/lib/storefront/{form → components/form}/inputs/textarea.rb +0 -0
  29. data/lib/storefront/{form → components/form}/inputs/value.rb +0 -0
  30. data/lib/storefront/{form → components/form}/label.rb +1 -1
  31. data/lib/storefront/components/header.rb +73 -0
  32. data/lib/storefront/components/image.rb +12 -0
  33. data/lib/storefront/components/javascript_template.rb +21 -0
  34. data/lib/storefront/components/list.rb +27 -0
  35. data/lib/storefront/components/menu.rb +41 -0
  36. data/lib/storefront/components/nav.rb +78 -0
  37. data/lib/storefront/components/sidebar.rb +23 -0
  38. data/lib/storefront/components/table.rb +232 -0
  39. data/lib/storefront/components/text.rb +29 -0
  40. data/lib/storefront/configuration.rb +53 -5
  41. data/lib/storefront/helpers/cache_helper.rb +37 -19
  42. data/lib/storefront/helpers/component_helper.rb +80 -41
  43. data/lib/storefront/helpers/content_helper.rb +211 -0
  44. data/lib/storefront/helpers/dom_helper.rb +136 -0
  45. data/lib/storefront/helpers/head_helper.rb +277 -205
  46. data/lib/storefront/helpers/model_helper.rb +21 -0
  47. data/lib/storefront/helpers/request_helper.rb +301 -53
  48. data/lib/storefront/helpers/tag_helper.rb +29 -0
  49. data/lib/storefront/{proxies/attribute_proxy.rb → models/attribute.rb} +1 -1
  50. data/lib/storefront/{proxies/model_proxy.rb → models/model.rb} +4 -6
  51. data/lib/storefront/railtie.rb +3 -16
  52. metadata +48 -64
  53. data/lib/storefront/dashboard.rb +0 -185
  54. data/lib/storefront/form.rb +0 -82
  55. data/lib/storefront/helpers/attribute_helper.rb +0 -81
  56. data/lib/storefront/helpers/body_helper.rb +0 -18
  57. data/lib/storefront/helpers/browser_helper.rb +0 -54
  58. data/lib/storefront/helpers/collection_helper.rb +0 -14
  59. data/lib/storefront/helpers/dashboard_helper.rb +0 -29
  60. data/lib/storefront/helpers/debug_helper.rb +0 -11
  61. data/lib/storefront/helpers/definition_list_helper.rb +0 -110
  62. data/lib/storefront/helpers/error_helper.rb +0 -11
  63. data/lib/storefront/helpers/flash_helper.rb +0 -14
  64. data/lib/storefront/helpers/form_helper.rb +0 -13
  65. data/lib/storefront/helpers/format_helper.rb +0 -59
  66. data/lib/storefront/helpers/image_helper.rb +0 -30
  67. data/lib/storefront/helpers/list_helper.rb +0 -135
  68. data/lib/storefront/helpers/locale_helper.rb +0 -245
  69. data/lib/storefront/helpers/open_graph_helper.rb +0 -5
  70. data/lib/storefront/helpers/page_helper.rb +0 -91
  71. data/lib/storefront/helpers/presenter_helper.rb +0 -5
  72. data/lib/storefront/helpers/semantic/location_helper.rb +0 -18
  73. data/lib/storefront/helpers/semantic/time_helper.rb +0 -14
  74. data/lib/storefront/helpers/sidebar_helper.rb +0 -27
  75. data/lib/storefront/helpers/system_helper.rb +0 -18
  76. data/lib/storefront/helpers/table_helper.rb +0 -38
  77. data/lib/storefront/helpers/template_helper.rb +0 -11
  78. data/lib/storefront/helpers/time_helper.rb +0 -21
  79. data/lib/storefront/helpers/url_helper.rb +0 -32
  80. data/lib/storefront/helpers/user_helper.rb +0 -15
  81. data/lib/storefront/helpers/widget_helper.rb +0 -142
  82. data/lib/storefront/helpers/workflow_helper.rb +0 -50
  83. data/lib/storefront/model_helper.rb +0 -17
  84. data/lib/storefront/table.rb +0 -198
  85. data/rails/init.rb +0 -1
  86. data/test/form_helper_test.rb +0 -5
  87. data/test/support/mock_controller.rb +0 -15
  88. data/test/support/mock_response.rb +0 -14
  89. data/test/support/models.rb +0 -0
  90. data/test/test_helper.rb +0 -34
@@ -1,8 +1,8 @@
1
1
  module Storefront
2
2
  class Form
3
- class Base
4
- include Storefront::LocaleHelper
5
- include Storefront::AttributeHelper
3
+ class Base < Storefront::Components::Base
4
+ include Storefront::Helpers::ContentHelper
5
+ include Storefront::Helpers::DomHelper
6
6
 
7
7
  def initialize(options = {})
8
8
  @template = options[:template]
@@ -38,9 +38,9 @@ module Storefront
38
38
  # do something here for counts
39
39
  sub_parent = model.object
40
40
  sub_object = args.shift
41
-
41
+
42
42
  index = options.delete(:index)
43
-
43
+
44
44
  unless index.present? && index.is_a?(::String)
45
45
  if sub_object.blank? && index.present?
46
46
  sub_object = sub_parent.send(attribute)[index]
@@ -71,7 +71,7 @@ module Storefront
71
71
  def field(*args, &block)
72
72
  options = args.extract_options!
73
73
  attribute_name = args.shift || attribute.name
74
- attribute = Storefront::AttributeProxy.new(
74
+ attribute = Storefront::Attribute.new(
75
75
  :name => attribute_name,
76
76
  :model => @model,
77
77
  :required => options[:required] == true,
@@ -18,9 +18,7 @@ module Storefront
18
18
  def render(&block)
19
19
  template.capture_haml do
20
20
  if value.present?
21
- template.haml_tag config.error_tag, attributes do
22
- template.haml_concat value.join("\n").html_safe.gsub(/\n$/)
23
- end
21
+ template.haml_tag config.error_tag, value.join("\n").html_safe.gsub(/\n$/, ""), attributes
24
22
  elsif config.always_include_error_tag
25
23
  template.haml_tag config.error_tag, attributes
26
24
  end
@@ -22,7 +22,7 @@ module Storefront
22
22
  attribute.required? ? config.required_class : config.optional_class,
23
23
  attribute.errors? ? config.error_class : config.valid_class,
24
24
  ]
25
- if attribute.validations.present?
25
+ if options[:validate] != false && attribute.validations.present?
26
26
  classes << config.validate_class
27
27
  end
28
28
  end
File without changes
@@ -39,6 +39,8 @@ module Storefront
39
39
  @dynamic = options[:dynamic] == true
40
40
  @rich_input = options.has_key?(:rich_input) ? !!options[:rich_input] : config.rich_input
41
41
 
42
+ @validate = attributes.delete(:validate) != false
43
+
42
44
  classes = [input_type, self.class.name.split("::").last.underscore, attribute.name.to_s.underscore.strip.gsub(/[_\s]+/, config.separator)]
43
45
 
44
46
  if options[:input_html].present?
@@ -52,7 +54,7 @@ module Storefront
52
54
  "input"
53
55
  ]
54
56
 
55
- if attribute.validations.present?
57
+ if @validate && attribute.validations.present?
56
58
  classes << config.validate_class
57
59
  end
58
60
  end
@@ -61,10 +63,12 @@ module Storefront
61
63
  merge_class! attributes, *classes.compact.uniq.map(&:to_s)
62
64
 
63
65
  # id
64
- attributes[:id] ||= attribute.to_id(:index => index, :parent_index => parent_index)
66
+ attributes[:id] ||= attribute.to_id(:index => index, :parent_index => parent_index) if config.id_enabled_on.include?("input")
65
67
 
66
68
  # validations
67
- attributes.merge!(attribute.validations) if config.inline_validations && attribute.validations.present?
69
+ if @validate
70
+ attributes.merge!(attribute.validations) if config.inline_validations && attribute.validations.present?
71
+ end
68
72
  attributes[:placeholder] = options[:placeholder] if options[:placeholder].present?
69
73
 
70
74
  # name
@@ -93,8 +97,6 @@ module Storefront
93
97
  attributes.delete :include_template
94
98
  attributes.delete :as
95
99
  attributes.delete :dynamic
96
- attributes.delete :max
97
- attributes.delete :min
98
100
  attributes.delete :parent_index
99
101
 
100
102
  attributes[:required] = "true" if attributes.delete(:required) == true
@@ -0,0 +1,7 @@
1
+ module Storefront
2
+ class Form
3
+ module Inputs
4
+
5
+ end
6
+ end
7
+ end
@@ -7,7 +7,7 @@ module Storefront
7
7
  def select_input(options = {})
8
8
  collection = self.collection
9
9
  collection = [[prompt, ""]] + collection if prompt.present?
10
- @value = attributes.delete(:value)
10
+ @value = attributes.delete(:value).to_s
11
11
 
12
12
  base_input :select, attributes.merge(options) do
13
13
  collection_iterator(collection, value)
@@ -20,17 +20,17 @@ module Storefront
20
20
  optgroup = false
21
21
  case item
22
22
  when Array
23
- name = item[0]
24
- options[:value] = item[1]
23
+ name = item[0].to_s
24
+ options[:value] = item[1].to_s
25
25
  when Hash
26
- name = item[:name]
27
- options[:value] = item[:value]
26
+ name = item[:name].to_s
27
+ options[:value] = item[:value].to_s
28
28
  optgroup = item[:children].present?
29
29
  when ::String, ::Float, ::Integer, ::BigDecimal
30
30
  options[:value] = item.to_s
31
31
  else
32
32
  name = item.name.strip.humanize
33
- options[:value] = item.id
33
+ options[:value] = item.id.to_s
34
34
  end
35
35
  if optgroup
36
36
  template.capture_haml do
@@ -11,7 +11,7 @@ module Storefront
11
11
  unless options[:label] == false
12
12
  merge_class! attributes, config.label_class
13
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)
14
+ attributes[:for] ||= attribute.to_id(:type => :input, :index => index, :parent_index => parent_index) if config.id_enabled_on.include?("input")
15
15
 
16
16
  @value = localize(:labels, attribute.name, options[:label].is_a?(::String) ? options[:label] : nil)
17
17
  @value = attribute.to_label if @value.blank?
@@ -0,0 +1,73 @@
1
+ module Storefront
2
+ module Components
3
+ class Header < Storefront::Components::Base
4
+ def render(&block)
5
+ return nil if options.blank?
6
+
7
+ template.capture_haml do
8
+ if block_given? && !pointer.include?("footer")
9
+ template.haml_tag :header, options[:header_html], &block
10
+ elsif options[:header] == false || pointer.include?("footer")
11
+ render_titles
12
+ else
13
+ if options[:title_html][:value].present?
14
+ template.haml_tag :header, options[:header_html] do
15
+ render_titles
16
+ end
17
+ else
18
+ template.haml_tag :header, options[:header_html]
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def render_titles
25
+ level = options[:level] || config.default_component_header_level
26
+ title = options[:title_html].delete(:value)
27
+ subtitle = options[:subtitle_html].delete(:value)
28
+
29
+ if title.present?
30
+ if subtitle.present?
31
+ if options[:header] == false || pointer.include?("footer")
32
+ template.haml_tag :"h#{level}", title, options[:title_html]
33
+ template.haml_tag :"h#{level + 1}", subtitle, options[:subtitle_html]
34
+ else
35
+ template.haml_tag :hgroup do
36
+ template.haml_tag :"h#{level}", title, options[:title_html]
37
+ template.haml_tag :"h#{level + 1}", subtitle, options[:subtitle_html]
38
+ end
39
+ end
40
+ else
41
+ template.haml_tag :"h#{level}", title, options[:title_html]
42
+ end
43
+ end
44
+ end
45
+
46
+ def extract_options!(*args)
47
+ options = args.extract_options!
48
+ return options if options[:skip_format]
49
+ return {} if options[:title] == false
50
+
51
+ header_html = options[:header_html] || {}
52
+ header_html.reverse_merge!(:class => config.header_class)
53
+
54
+ title_html = options[:title_html] || {}
55
+ title_html.reverse_merge!(:class => config.title_class)
56
+ title_html[:value] = options.delete(:title)
57
+
58
+ title_html[:value] = t?(title_html[:value], :scope => :"widgets.headers") if title_html[:value].is_a?(::Symbol)
59
+
60
+ subtitle_html = options[:subtitle_html] || {}
61
+ if subtitle_html.present? || options[:subtitle].present?
62
+ subtitle_html.reverse_merge!(:class => config.subtitle_class)
63
+ subtitle_html[:value] = options.delete(:subtitle)
64
+ subtitle_html[:value] = t?(subtitle_html[:value], :scope => :"widgets.headers") if subtitle_html[:value].is_a?(::Symbol)
65
+ end
66
+
67
+ options.merge! :header_html => header_html, :title_html => title_html, :subtitle_html => subtitle_html
68
+
69
+ options
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,12 @@
1
+ module Storefront
2
+ module Components
3
+ class Image < Base
4
+ def render(label, path, options = {})
5
+ capture_haml do
6
+ haml_tag :span
7
+ haml_concat image_tag(label, path, options)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ module Storefront
2
+ module Components
3
+ class JavascriptTemplate < Base
4
+ def render(&block)
5
+ template.capture_haml do
6
+ template.haml_tag :script, options, &block
7
+ end
8
+ end
9
+
10
+ def extract_options!(*args)
11
+ options = args.extract_options!
12
+ name = args.shift
13
+ if name
14
+ options[:id] ||= name.to_s.strip.gsub(/[\s|_]+/, config.separator).squeeze(config.separator)
15
+ end
16
+ options[:type] ||= "text/html"
17
+ options
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module Storefront
2
+ module Components
3
+ class List < Base
4
+ def render(&block)
5
+ template.capture_haml do
6
+ template.haml_tag options[:tag], options[:outer_html], &block
7
+ end
8
+ end
9
+
10
+ def extract_options!(*args)
11
+ options = super(*args)
12
+
13
+ options[:tag] ||= :ul
14
+
15
+ if config.include_aria
16
+ options[:outer_html][:role] ||= :list
17
+ end
18
+
19
+ merge_class! options[:outer_html], *[
20
+ "list"
21
+ ]
22
+
23
+ options
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ module Storefront
2
+ module Components
3
+ class Menu < Base
4
+ def render(&block)
5
+ template.capture_haml do
6
+ template.haml_tag :nav, options[:outer_html] do
7
+ header = template.header_widget(options)
8
+
9
+ if header.present?
10
+ template.haml_concat header
11
+ end
12
+
13
+ template.haml_tag options[:tag], options[:inner_html], &block
14
+
15
+ if options[:footer_html].present?
16
+ template.footer_widget(options[:footer_html])
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ def extract_options!(*args)
23
+ options = super(*args)
24
+
25
+ options[:tag] ||= :ol
26
+ options[:inner_html] ||= {}
27
+
28
+ if config.include_aria
29
+ options[:outer_html][:role] ||= :menu
30
+ options[:inner_html][:role] ||= :list
31
+ end
32
+
33
+ merge_class! options[:inner_html], *[
34
+ "list"
35
+ ]
36
+
37
+ options
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,78 @@
1
+ module Storefront
2
+ module Components
3
+ class Nav < Storefront::Components::Base
4
+ def render(&block)
5
+ template.capture_haml do
6
+ template.haml_tag options[:tag], options[:outer_html] do
7
+ if block_given?
8
+ case block.arity
9
+ when 1
10
+ yield(options[:value].strip)
11
+ else
12
+ yield
13
+ end
14
+ elsif options[:current] && options[:as] == :span
15
+ template.haml_tag :span, options[:value], options[:inner_html]
16
+ else
17
+ # inner_html[:title] ||= "Link to the #{text.strip} page."
18
+ template.haml_concat link_to(options[:value], options[:path], options[:inner_html])
19
+ end
20
+ template.haml_tag :span, options[:separator] if options[:separator]
21
+ end
22
+ end
23
+ end
24
+
25
+ def extract_options!(*args)
26
+ options = args.extract_options!
27
+ key, path = args
28
+
29
+ locale_options = options.delete(:locale_options) || {}
30
+ text = t?(key, locale_options.reverse_merge(:scope => :"widgets.nav"))
31
+
32
+ as = options.delete(:as) || :span
33
+ separator = options.delete(:separator)
34
+
35
+ if options.has_key?(:current)
36
+ current = options.delete(:current) == true
37
+ else
38
+ current = on_current_page?(path)
39
+ end
40
+
41
+ inner_html = options.delete(:inner_html) || {}
42
+ outer_html = options.delete(:outer_html) || {}
43
+
44
+ inner_html.merge! clone_attributes(options)
45
+
46
+ merge_class! outer_html, *[
47
+ config.nav_class,
48
+ current ? config.active_class : nil
49
+ ].compact.uniq
50
+
51
+ if config.include_aria
52
+ outer_html[:role] ||= if pointer.include?("menu")
53
+ :menuitem
54
+ else
55
+ :listitem
56
+ end
57
+ end
58
+
59
+ text.strip!
60
+
61
+ if config.auto_id_nav
62
+ outer_html[:id] ||= [text.underscore.parameterize, config.nav_class].join(config.separator).gsub(/[\s|_]+/, config.separator).squeeze(config.separator)
63
+ end
64
+
65
+ options.merge(
66
+ :inner_html => inner_html,
67
+ :outer_html => outer_html,
68
+ :separator => separator,
69
+ :current => current,
70
+ :as => as,
71
+ :value => text,
72
+ :path => path,
73
+ :tag => config.nav_tag
74
+ )
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,23 @@
1
+ module Storefront
2
+ module Components
3
+ class Sidebar < Base
4
+ def sidebar(*args)
5
+ locals = args.extract_options!
6
+ path = args.shift
7
+ if path.blank?
8
+ path = resource.class.name.underscore.pluralize.to_sym rescue nil
9
+ end
10
+ if path.is_a?(Symbol)
11
+ path = [path_namespace, path.to_s, "sidebar"].compact.join("/")
12
+ end
13
+ content_for :sidebar do
14
+ render :partial => path, :locals => locals
15
+ end
16
+ end
17
+
18
+ def sidebar_record
19
+ @sidebar_record
20
+ end
21
+ end
22
+ end
23
+ end