storefront 0.5.1 → 0.5.2

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.
@@ -1,7 +1,9 @@
1
1
  module Storefront
2
- class Form
3
- module Inputs
2
+ module Components
3
+ class Form
4
+ module Inputs
4
5
 
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,12 +1,14 @@
1
1
  module Storefront
2
- class Form
3
- class Checkbox < Input
4
- resolves :checkbox, :boolean
2
+ module Components
3
+ class Form
4
+ class Checkbox < Input
5
+ resolves :checkbox, :boolean
5
6
 
6
- def checkbox_input
7
- simple_input :checkbox
7
+ def checkbox_input
8
+ simple_input :checkbox
9
+ end
10
+ alias_method :boolean_input, :checkbox_input
8
11
  end
9
- alias_method :boolean_input, :checkbox_input
10
12
  end
11
13
  end
12
14
  end
@@ -1,15 +1,17 @@
1
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
2
+ module Components
3
+ class Form
4
+ # accepted attributes: autocomplete, autofocus, list, max, min, readonly, required, step
5
+ class Date < Input
6
+ resolves :date, :datetime, :time, :month, :week
6
7
 
7
- def range_input(options = {})
8
+ def range_input(options = {})
8
9
 
9
- end
10
+ end
10
11
 
11
- def date_range_input(options = {})
12
+ def date_range_input(options = {})
12
13
 
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -1,11 +1,13 @@
1
1
  module Storefront
2
- class Form
3
- # :accept => "image/gif, image/jpg, image/png, image/jpeg"
4
- class File < Input
5
- resolves :file
2
+ module Components
3
+ class Form
4
+ # :accept => "image/gif, image/jpg, image/png, image/jpeg"
5
+ class File < Input
6
+ resolves :file
6
7
 
7
- def file_input(options = {})
8
- simple_input :file, options
8
+ def file_input(options = {})
9
+ simple_input :file, options
10
+ end
9
11
  end
10
12
  end
11
13
  end
@@ -1,10 +1,12 @@
1
1
  module Storefront
2
- class Form
3
- class Hidden < Input
4
- resolves :hidden
2
+ module Components
3
+ class Form
4
+ class Hidden < Input
5
+ resolves :hidden
5
6
 
6
- def hidden_input(options = {})
7
- simple_input :hidden, options
7
+ def hidden_input(options = {})
8
+ simple_input :hidden, options
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -1,10 +1,12 @@
1
1
  module Storefront
2
- class Form
3
- class Radio < Input
4
- resolves :radio, :radiobutton
2
+ module Components
3
+ class Form
4
+ class Radio < Input
5
+ resolves :radio, :radiobutton
5
6
 
6
- def radio_input(options = {})
7
+ def radio_input(options = {})
7
8
 
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -1,14 +1,16 @@
1
1
  module Storefront
2
- class Form
3
- class Range < Input
4
- resolves :range, :slider
2
+ module Components
3
+ class Form
4
+ class Range < Input
5
+ resolves :range, :slider
5
6
 
6
- def range_input(options = {})
7
+ def range_input(options = {})
7
8
 
8
- end
9
+ end
9
10
 
10
- def slider_input(options = {})
11
+ def slider_input(options = {})
11
12
 
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -1,67 +1,69 @@
1
1
  module Storefront
2
- class Form
3
- # attributes: prompt, blank, multiple
4
- class Select < Input
5
- resolves :select
2
+ module Components
3
+ class Form
4
+ # attributes: prompt, blank, multiple
5
+ class Select < Input
6
+ resolves :select
6
7
 
7
- def select_input(options = {})
8
- collection = self.collection
9
- collection = [[prompt, ""]] + collection if prompt.present?
10
- @value = attributes.delete(:value).to_s
8
+ def select_input(options = {})
9
+ collection = self.collection
10
+ collection = [[prompt, ""]] + collection if prompt.present?
11
+ @value = attributes.delete(:value).to_s
11
12
 
12
- base_input :select, attributes.merge(options) do
13
- collection_iterator(collection, value)
13
+ base_input :select, attributes.merge(options) do
14
+ collection_iterator(collection, value)
15
+ end
14
16
  end
15
- end
16
17
 
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].to_s
24
- options[:value] = item[1].to_s
25
- when Hash
26
- name = item[:name].to_s
27
- options[:value] = item[:value].to_s
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.to_s
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)
18
+ def collection_iterator(collection, selected = nil)
19
+ collection.map do |item|
20
+ name, options = item, {}
21
+ optgroup = false
22
+ case item
23
+ when Array
24
+ name = item[0].to_s
25
+ options[:value] = item[1].to_s
26
+ when Hash
27
+ name = item[:name].to_s
28
+ options[:value] = item[:value].to_s
29
+ optgroup = item[:children].present?
30
+ when ::String, ::Float, ::Integer, ::BigDecimal
31
+ options[:value] = item.to_s
32
+ else
33
+ name = item.name.strip.humanize
34
+ options[:value] = item.id.to_s
35
+ end
36
+ if optgroup
37
+ template.capture_haml do
38
+ template.haml_tag :optgroup, :label => options[:name], :"data-value" => options[:value] do
39
+ collection_iterator(item[:children], selected)
40
+ end
39
41
  end
42
+ else
43
+ options[:selected] = "true" if selected.present? && options[:value] == selected
44
+ template.haml_tag :option, name, options
40
45
  end
41
- else
42
- options[:selected] = "true" if selected.present? && options[:value] == selected
43
- template.haml_tag :option, name, options
44
46
  end
45
47
  end
46
- end
47
-
48
- def boolean_collection(options = {})
49
- [["Yes", true], ["No", false]]
50
- end
51
48
 
52
- def collection
53
- if @collection.nil?
54
- @collection = Array(attributes.delete(:collection) || [])
49
+ def boolean_collection(options = {})
50
+ [["Yes", true], ["No", false]]
55
51
  end
52
+
53
+ def collection
54
+ if @collection.nil?
55
+ @collection = Array(attributes.delete(:collection) || [])
56
+ end
56
57
 
57
- @collection
58
- end
58
+ @collection
59
+ end
59
60
 
60
- def prompt
61
- if @prompt.nil? && include_blank
62
- @prompt = localize(:prompts, attribute.name, attributes.delete(:prompt), :allow_blank => true)
61
+ def prompt
62
+ if @prompt.nil? && include_blank
63
+ @prompt = localize(:prompts, attribute.name, attributes.delete(:prompt), :allow_blank => true)
64
+ end
65
+ @prompt
63
66
  end
64
- @prompt
65
67
  end
66
68
  end
67
69
  end
@@ -1,88 +1,90 @@
1
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
2
+ module Components
3
+ class Form
4
+ # email attributes: autocomplete, autofocus, list, maxlength, multiple, pattern, placeholder, readonly, required, size
5
+ # password attributes: autocomplete, autofocus, maxlength, pattern, placeholder, readonly, required, size
6
+ # text, search, url, tel attributes: autocomplete, autofocus, list, maxlength, pattern, placeholder, readonly, required, size
7
+ class String < Input
8
+ resolves :string, :phone, :url, :email, :search, :date, :datetime, :time, :numeric, :number, :money, :percent, :password
8
9
 
9
- # autofocus, pattern, placeholder, title, size, data-validate, data-validate-match, data-validate-unique
10
- def string_input
11
- simple_input :string
12
- end
10
+ # autofocus, pattern, placeholder, title, size, data-validate, data-validate-match, data-validate-unique
11
+ def string_input
12
+ simple_input :string
13
+ end
13
14
 
14
- def password_input
15
- simple_input :password
16
- end
15
+ def password_input
16
+ simple_input :password
17
+ end
17
18
 
18
- def email_input
19
- simple_input :email
20
- end
19
+ def email_input
20
+ simple_input :email
21
+ end
21
22
 
22
- def url_input
23
- simple_input :url
24
- end
23
+ def url_input
24
+ simple_input :url
25
+ end
25
26
 
26
- def number_input
27
- simple_input :string, :class => "numeric", "data-type" => "numeric"
28
- end
27
+ def number_input
28
+ simple_input :string, :class => "numeric", "data-type" => "numeric"
29
+ end
29
30
 
30
- def numeric_input
31
- simple_input :string, :class => "numeric", "data-type" => "numeric"
32
- end
31
+ def numeric_input
32
+ simple_input :string, :class => "numeric", "data-type" => "numeric"
33
+ end
33
34
 
34
- def search_input
35
- simple_input :search, :class => "search", "data-type" => "search"
36
- end
35
+ def search_input
36
+ simple_input :search, :class => "search", "data-type" => "search"
37
+ end
37
38
 
38
- def phone_input
39
- simple_input :tel, :class => "phone"
40
- end
39
+ def phone_input
40
+ simple_input :tel, :class => "phone"
41
+ end
41
42
 
42
- def fax_input
43
- simple_input :tel, :class => "phone fax"
44
- end
43
+ def fax_input
44
+ simple_input :tel, :class => "phone fax"
45
+ end
45
46
 
46
- def date_input
47
- simple_input :string, :class => "date", "data-type" => "date"
48
- end
47
+ def date_input
48
+ simple_input :string, :class => "date", "data-type" => "date"
49
+ end
49
50
 
50
- def money_input
51
- simple_input :string, :class => "money", "data-type" => "money"
52
- end
51
+ def money_input
52
+ simple_input :string, :class => "money", "data-type" => "money"
53
+ end
53
54
 
54
- def percent_input
55
- simple_input :string, :class => "percent", "data-type" => "percent"
56
- end
55
+ def percent_input
56
+ simple_input :string, :class => "percent", "data-type" => "percent"
57
+ end
57
58
 
58
- def color_input
59
+ def color_input
59
60
 
60
- end
61
+ end
61
62
 
62
- def autocomplete_input
63
+ def autocomplete_input
63
64
  =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
65
+ default = options[:default]
66
+ #attribute = "#{attribute}".gsub(/_id$/, "")
67
+ if default.present?
68
+ name = default.name rescue ""
69
+ else
70
+ name = (object.send("#{attribute}".gsub(/_id$/, "")).name || "") rescue ""
71
+ end
71
72
 
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
73
+ options[:value] ||= default_id_for(default || object.send("#{attribute}".gsub(/_id$/, "")))
74
+ value = User.find_by_id(options[:value])
75
+ name = value.name if value
76
+ value = value.id if value
76
77
 
77
- result = input(attribute, :as => :hidden, :input_html => {:class => "hidden-autocomplete", :value => value})
78
+ result = input(attribute, :as => :hidden, :input_html => {:class => "hidden-autocomplete", :value => value})
78
79
 
79
- options[:input_html] ||= {}
80
- options[:input_html].merge!(:class => "autocomplete-two", :value => name)
80
+ options[:input_html] ||= {}
81
+ options[:input_html].merge!(:class => "autocomplete-two", :value => name)
81
82
 
82
- result += input("#{attribute}".gsub(/_id$/, ""), options)
83
+ result += input("#{attribute}".gsub(/_id$/, ""), options)
83
84
 
84
- result
85
+ result
85
86
  =end
87
+ end
86
88
  end
87
89
  end
88
90
  end
@@ -1,24 +1,26 @@
1
1
  module Storefront
2
- class Form
3
- class Submit < Input
4
- resolves :submit, :confirm, :button
2
+ module Components
3
+ class Form
4
+ class Submit < Input
5
+ resolves :submit, :confirm, :button
5
6
 
6
- def initialize(options = {})
7
- super
7
+ def initialize(options = {})
8
+ super
8
9
 
9
- attributes.delete(:name)
10
- attributes.delete(:accesskey)
11
- end
10
+ attributes.delete(:name)
11
+ attributes.delete(:accesskey)
12
+ end
12
13
 
13
- def submit_input
14
- if @rich_input
15
- rich_input :submit
16
- else
17
- simple_input :submit
14
+ def submit_input
15
+ if @rich_input
16
+ rich_input :submit
17
+ else
18
+ simple_input :submit
19
+ end
18
20
  end
21
+ alias_method :confirm_input, :submit_input
22
+ alias_method :button_input, :submit_input
19
23
  end
20
- alias_method :confirm_input, :submit_input
21
- alias_method :button_input, :submit_input
22
24
  end
23
25
  end
24
26
  end