recurring_select 1.2.1.rc2 → 1.2.1.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb330f53dbb9e927ef6e926b82ed842e6f5fa405
4
- data.tar.gz: 110685ad736abe16f880e317dcb80fa92eaa1385
3
+ metadata.gz: 9812313e5f81141d2f0350d36ead49d4bbc0fd7b
4
+ data.tar.gz: e938685e8b6e8ba0760665a66c46ebbb1974c863
5
5
  SHA512:
6
- metadata.gz: 33c79b15c93c3dfe966f8c5fc01eeeb715fbb1529460ac5935aa69f72d8d7b8f4207464580de1450bf7b9f07076c654a7ff0d1fc5f746e3678aa49a1e49708d0
7
- data.tar.gz: 9aec0d6cb1a1fc90755b11cf9df882a7e1c30ce9f8c30437b64678f030168798afacf1a103efd24c3ba3b0a3b273cecc6479f93285696d4f65396a5e10148dc6
6
+ metadata.gz: 027fd4813b29ec2e514102a26a63825895c86a27af6990780ee169c7acbe2df53584c1ac636494e0e30977edf3a5f004a47fb65083b6a08472907a57294bac3d
7
+ data.tar.gz: db6869e807c21b95ec7e9cdae8a84f88f77cd455575f8095b0d6bbaffa5be8b6eb79ffbb46e9bfd954b1113815a31892821848451b66e19d04a3e257648deef4
@@ -1,6 +1,4 @@
1
1
  require "ice_cube"
2
- require_relative "utilities/form_options_ext"
3
- require_relative "utilities/tag_ext"
4
2
 
5
3
  module RecurringSelectHelper
6
4
  module FormHelper
@@ -24,4 +22,121 @@ module RecurringSelectHelper
24
22
  @template.select_recurring(@object_name, method, default_schedules, options.merge(:object => @object), html_options)
25
23
  end
26
24
  end
25
+
26
+ module FormOptionsHelper
27
+ def recurring_options_for_select(currently_selected_rule = nil, default_schedules = nil, options = {})
28
+
29
+ options_array = []
30
+ blank_option_label = options[:blank_label] || I18n.t("recurring_select.not_recurring")
31
+ blank_option = [blank_option_label, "null"]
32
+ separator = [I18n.t("recurring_select.or"), {:disabled => true}]
33
+
34
+ if default_schedules.blank?
35
+ if currently_selected_rule.present?
36
+ options_array << blank_option if options[:allow_blank]
37
+ options_array << ice_cube_rule_to_option(currently_selected_rule)
38
+ options_array << separator
39
+ options_array << [I18n.t("recurring_select.change_schedule"), "custom"]
40
+ else
41
+ options_array << blank_option
42
+ options_array << [I18n.t("recurring_select.set_schedule"), "custom"]
43
+ end
44
+ else
45
+ options_array << blank_option if options[:allow_blank]
46
+
47
+ options_array += default_schedules.collect{|dc|
48
+ ice_cube_rule_to_option(dc)
49
+ }
50
+
51
+ if currently_selected_rule.present? and !current_rule_in_defaults?(currently_selected_rule, default_schedules)
52
+ options_array << ice_cube_rule_to_option(currently_selected_rule, true)
53
+ custom_label = [I18n.t("recurring_select.new_custom_schedule"), "custom"]
54
+ else
55
+ custom_label = [I18n.t("recurring_select.custom_schedule"), "custom"]
56
+ end
57
+
58
+ options_array << separator
59
+ options_array << custom_label
60
+ end
61
+
62
+ options_for_select(options_array, currently_selected_rule.to_json)
63
+ end
64
+
65
+ private
66
+
67
+ def ice_cube_rule_to_option(supplied_rule, custom = false)
68
+ return supplied_rule unless RecurringSelect.is_valid_rule?(supplied_rule)
69
+
70
+ rule = RecurringSelect.dirty_hash_to_rule(supplied_rule)
71
+ ar = [rule.to_s, rule.to_hash.to_json]
72
+
73
+ if custom
74
+ ar[0] << "*"
75
+ ar << {"data-custom" => true}
76
+ end
77
+
78
+ ar
79
+ end
80
+
81
+ def current_rule_in_defaults?(currently_selected_rule, default_schedules)
82
+ default_schedules.any?{|option|
83
+ option == currently_selected_rule or
84
+ (option.is_a?(Array) and option[1] == currently_selected_rule)
85
+ }
86
+ end
87
+ end
88
+
89
+ module SelectHTMLOptions
90
+ private
91
+
92
+ def recurring_select_html_options(html_options)
93
+ html_options = html_options.stringify_keys
94
+ html_options["class"] = (html_options["class"].to_s.split + ["recurring_select"]).join(" ")
95
+ html_options
96
+ end
97
+ end
98
+
99
+ if Rails::VERSION::STRING.to_f >= 4.0
100
+ # === Rails 4
101
+ class RecurringSelectTag < ActionView::Helpers::Tags::Base
102
+ include RecurringSelectHelper::FormOptionsHelper
103
+ include SelectHTMLOptions
104
+
105
+ def initialize(object, method, template_object, default_schedules = nil, options = {}, html_options = {})
106
+ @default_schedules = default_schedules
107
+ @choices = @choices.to_a if @choices.is_a?(Range)
108
+ @method_name = method.to_s
109
+ @object_name = object.to_s
110
+ @html_options = recurring_select_html_options(html_options)
111
+ add_default_name_and_id(@html_options)
112
+
113
+ super(object, method, template_object, options)
114
+ end
115
+
116
+ def render
117
+ option_tags = add_options(recurring_options_for_select(value(object), @default_schedules, @options), @options, value(object))
118
+ select_content_tag(option_tags, @options, @html_options)
119
+ end
120
+ end
121
+
122
+ else
123
+ # === Rails 3
124
+ class InstanceTag < ActionView::Helpers::InstanceTag
125
+ include RecurringSelectHelper::FormOptionsHelper
126
+ include SelectHTMLOptions
127
+
128
+ def to_recurring_select_tag(default_schedules, options, html_options)
129
+ html_options = recurring_select_html_options(html_options)
130
+ add_default_name_and_id(html_options)
131
+ value = value(object)
132
+ options = add_options(
133
+ recurring_options_for_select(value, default_schedules, options),
134
+ options, value
135
+ )
136
+ content_tag("select", options, html_options)
137
+ end
138
+ end
139
+ end
140
+
141
+
27
142
  end
@@ -1,3 +1,3 @@
1
1
  module RecurringSelect
2
- VERSION = "1.2.1.rc2"
2
+ VERSION = "1.2.1.rc3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recurring_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1.rc2
4
+ version: 1.2.1.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jobber
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-30 00:00:00.000000000 Z
13
+ date: 2013-11-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -170,8 +170,6 @@ files:
170
170
  - app/assets/stylesheets/recurring_select.css.scss.erb
171
171
  - app/assets/stylesheets/utilities.scss
172
172
  - app/helpers/recurring_select_helper.rb
173
- - app/helpers/utilities/form_options_ext.rb
174
- - app/helpers/utilities/tag_ext.rb
175
173
  - app/middleware/recurring_select_middleware.rb
176
174
  - config/locales/en.yml
177
175
  - config/locales/fr.yml
@@ -1,64 +0,0 @@
1
- module RecurringSelectHelper
2
- module FormOptionsHelper
3
- def recurring_options_for_select(currently_selected_rule = nil, default_schedules = nil, options = {})
4
-
5
- options_array = []
6
- blank_option_label = options[:blank_label] || I18n.t("recurring_select.not_recurring")
7
- blank_option = [blank_option_label, "null"]
8
- separator = [I18n.t("recurring_select.or"), {:disabled => true}]
9
-
10
- if default_schedules.blank?
11
- if not currently_selected_rule.blank?
12
- options_array << blank_option if options[:allow_blank]
13
- options_array << ice_cube_rule_to_option(currently_selected_rule)
14
- options_array << separator
15
- options_array << [I18n.t("recurring_select.change_schedule"), "custom"]
16
- else
17
- options_array << blank_option
18
- options_array << [I18n.t("recurring_select.set_schedule"), "custom"]
19
- end
20
- else
21
- options_array << blank_option if options[:allow_blank]
22
-
23
- options_array += default_schedules.collect{|dc|
24
- ice_cube_rule_to_option(dc)
25
- }
26
-
27
- if not currently_selected_rule.blank? and not current_rule_in_defaults?(currently_selected_rule, default_schedules)
28
- options_array << ice_cube_rule_to_option(currently_selected_rule, true)
29
- custom_label = [I18n.t("recurring_select.new_custom_schedule"), "custom"]
30
- else
31
- custom_label = [I18n.t("recurring_select.custom_schedule"), "custom"]
32
- end
33
-
34
- options_array << separator
35
- options_array << custom_label
36
- end
37
-
38
- options_for_select(options_array, currently_selected_rule.to_json)
39
- end
40
-
41
- private
42
-
43
- def ice_cube_rule_to_option(supplied_rule, custom = false)
44
- return supplied_rule unless RecurringSelect.is_valid_rule?(supplied_rule)
45
-
46
- rule = RecurringSelect.dirty_hash_to_rule(supplied_rule)
47
- ar = [rule.to_s, rule.to_hash.to_json]
48
-
49
- if custom
50
- ar[0] << "*"
51
- ar << {"data-custom" => true}
52
- end
53
-
54
- ar
55
- end
56
-
57
- def current_rule_in_defaults?(currently_selected_rule, default_schedules)
58
- default_schedules.any?{|option|
59
- option == currently_selected_rule or
60
- (option.is_a?(Array) and option[1] == currently_selected_rule)
61
- }
62
- end
63
- end
64
- end
@@ -1,53 +0,0 @@
1
- module RecurringSelectHelper
2
- module SelectHTMLOptions
3
- private
4
-
5
- def recurring_select_html_options(html_options)
6
- html_options = html_options.stringify_keys
7
- html_options["class"] = (html_options["class"].to_s.split + ["recurring_select"]).join(" ")
8
- html_options
9
- end
10
- end
11
-
12
- if Rails::VERSION::STRING.to_f >= 4.0
13
- # === Rails 4
14
- class RecurringSelectTag < ActionView::Helpers::Tags::Base
15
- include RecurringSelectHelper::FormOptionsHelper
16
- include SelectHTMLOptions
17
-
18
- def initialize(object, method, template_object, default_schedules = nil, options = {}, html_options = {})
19
- @default_schedules = default_schedules
20
- @choices = @choices.to_a if @choices.is_a?(Range)
21
- @method_name = method.to_s
22
- @object_name = object.to_s
23
- @html_options = recurring_select_html_options(html_options)
24
- add_default_name_and_id(@html_options)
25
-
26
- super(object, method, template_object, options)
27
- end
28
-
29
- def render
30
- option_tags = add_options(recurring_options_for_select(value(object), @default_schedules, @options), @options, value(object))
31
- select_content_tag(option_tags, @options, @html_options)
32
- end
33
- end
34
-
35
- else
36
- # === Rails 3
37
- class InstanceTag < ActionView::Helpers::InstanceTag
38
- include RecurringSelectHelper::FormOptionsHelper
39
- include SelectHTMLOptions
40
-
41
- def to_recurring_select_tag(default_schedules, options, html_options)
42
- html_options = recurring_select_html_options(html_options)
43
- add_default_name_and_id(html_options)
44
- value = value(object)
45
- options = add_options(
46
- recurring_options_for_select(value, default_schedules, options),
47
- options, value
48
- )
49
- content_tag("select", options, html_options)
50
- end
51
- end
52
- end
53
- end