recurring_select 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MWJkOGI0NDIxNzQ1MzU4MTBmOGI1MGM4OTI3YThlZTQxNzQyNTIyMg==
5
+ data.tar.gz: !binary |-
6
+ NTM0NDE2OGRiZDYxOWFiZWM4ZjM4OTVhNDBiNGNmZGUzMGQ2NTNiYQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NGJhMzZhZTA3ZWFlNTg1OWQwNTVhMWE0MDIyYzJmYjQwM2NkNDllNDhlZGU0
10
+ NDA5ZjhjNzBhYWRhMGZhNzkwYmExMTkwYTgwMDIzOWM4ZjQwNjk5ZGJjMWE4
11
+ YzFkM2M4NWJhZjNmYWIxZTk2MDEzYjBhYjU3ZmUyM2QyMTY5M2U=
12
+ data.tar.gz: !binary |-
13
+ MmY2OGVhNzFlNWQ0NDgzOGZiYTAyN2NmNzk1OTA5NzkzOGQyY2Q5NDFmYzJl
14
+ OTkxZDhmYWU1MTJhOGM3OWQxMTk5ZWZiOTIwMzU2Njk4YzRmZTM1NjJiYTMz
15
+ Y2Q3ODRjNDc5ZDM2ZWMyYmNmNzkzYzA3ZDIwMGQwODYxODYyN2Y=
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  RecurringSelect
2
2
  =============
3
3
 
4
- [![Build Status](https://travis-ci.org/GetJobber/recurring_select.png)](https://travis-ci.org/GetJobber/recurring_select)
4
+ [![Build Status](https://travis-ci.org/GetJobber/recurring_select.png?branch=master)](https://travis-ci.org/GetJobber/recurring_select) [![Code Climate](https://codeclimate.com/github/GetJobber/recurring_select.png)](https://codeclimate.com/github/GetJobber/recurring_select)
5
5
 
6
6
  This is a gem to add a number of selectors and helpers for working with recurring schedules in a rails app.
7
7
  It uses the [IceCube](https://github.com/seejohnrun/ice_cube) recurring scheduling gem.
8
8
 
9
9
  Created by the [Jobber](http://getjobber.com) team for Jobber, the leading business management tool for field service companies.
10
10
 
11
- Check out the [live demo](http://recurring-select-demo.herokuapp.com/)
11
+ Check out the [live demo](http://recurring-select-demo.herokuapp.com/) (code in [spec\dummy](https://github.com/GetJobber/recurring_select/tree/master/spec/dummy) folder)
12
12
 
13
13
 
14
14
  Usage
@@ -19,18 +19,18 @@ Basic selector:
19
19
  Load the gem:
20
20
  `gem 'recurring_select`
21
21
 
22
- Require assets
23
- Desktop view
24
- application.js
25
- `//= require recurring_select`
26
- application.css
27
- `//= require recurring_select`
22
+ Require assets
23
+ Desktop view
24
+ application.js
25
+ `//= require recurring_select`
26
+ application.css
27
+ `//= require recurring_select`
28
28
 
29
- or jQueryMobile interface
30
- application.js
31
- `//= require jquery-mobile-rs`
32
- application.css
33
- `//= require jquery-mobile-rs`
29
+ or jQueryMobile interface
30
+ application.js
31
+ `//= require jquery-mobile-rs`
32
+ application.css
33
+ `//= require jquery-mobile-rs`
34
34
 
35
35
 
36
36
  In the form view call the helper:
@@ -78,6 +78,13 @@ Start the dummy server for clicking around the interface:
78
78
  Use [Guard](https://github.com/guard/guard) and RSpec for all tests. I'd
79
79
  love to get jasmine running also, but haven't had time yet.
80
80
 
81
+ Tests can be ran against different versions of Rails like so:
82
+
83
+ ```
84
+ rake appraisal:install
85
+ rake appraisal
86
+ ```
87
+
81
88
  Feel free to open issues or send pull requests.
82
89
 
83
90
  Licensing
data/Rakefile CHANGED
@@ -1,17 +1,16 @@
1
1
  #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'appraisal'
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task :default => :spec
14
9
 
10
+ require 'rubygems/package_task'
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ require 'rdoc/task'
15
14
  RDoc::Task.new(:rdoc) do |rdoc|
16
15
  rdoc.rdoc_dir = 'rdoc'
17
16
  rdoc.title = 'RecurringSelect'
@@ -20,20 +19,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
19
  rdoc.rdoc_files.include('lib/**/*.rb')
21
20
  end
22
21
 
23
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
22
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
23
  load 'rails/tasks/engine.rake'
25
24
 
26
-
27
- Bundler::GemHelper.install_tasks
28
-
29
- require 'rake/testtask'
30
-
31
- Rake::TestTask.new(:test) do |t|
32
- t.libs << 'lib'
33
- t.libs << 'test'
34
- t.pattern = 'test/**/*_test.rb'
35
- t.verbose = false
36
- end
37
-
38
-
39
- task :default => :test
@@ -49,10 +49,10 @@ methods =
49
49
 
50
50
 
51
51
  insert_option: (new_rule_str, new_rule_json) ->
52
- seperator = @find("option:disabled")
53
- if seperator.length == 0
54
- seperator = @find("option")
55
- seperator = seperator.last()
52
+ separator = @find("option:disabled")
53
+ if separator.length == 0
54
+ separator = @find("option")
55
+ separator = separator.last()
56
56
 
57
57
  new_option = $(document.createElement("option"))
58
58
  new_option.attr "data-custom", true
@@ -62,7 +62,7 @@ methods =
62
62
 
63
63
  new_option.text new_rule_str
64
64
  new_option.val new_rule_json
65
- new_option.insertBefore seperator
65
+ new_option.insertBefore separator
66
66
 
67
67
  methods: ->
68
68
  methods
@@ -1,97 +1,17 @@
1
1
  require "ice_cube"
2
+ require_relative "utilities/form_options_ext"
3
+ require_relative "utilities/tag_ext"
2
4
 
3
5
  module RecurringSelectHelper
4
6
  module FormHelper
5
7
  def select_recurring(object, method, default_schedules = nil, options = {}, html_options = {})
6
- InstanceTag.new(object, method, self, options.delete(:object)).to_recurring_select_tag(default_schedules, options, html_options)
7
- end
8
- end
9
-
10
- module FormOptionsHelper
11
- def recurring_options_for_select(currently_selected_rule = nil, default_schedules = nil, options = {})
12
-
13
- options_array = []
14
- blank_option_label = options[:blank_label] || "- not recurring -"
15
- blank_option = [blank_option_label, "null"]
16
- seperator = ["or", {:disabled => true}]
17
-
18
- if default_schedules.blank?
19
- if currently_selected_rule
20
- options_array << blank_option if options[:allow_blank]
21
- options_array << ice_cube_rule_to_option(currently_selected_rule)
22
- options_array << seperator
23
- options_array << ["Change schedule...", "custom"]
24
- else
25
- options_array << blank_option
26
- options_array << ["Set schedule...", "custom"]
27
- end
28
- else
29
- options_array << blank_option if options[:allow_blank]
30
-
31
- options_array += default_schedules.collect{|dc|
32
- ice_cube_rule_to_option(dc)
33
- }
34
-
35
- if currently_selected_rule and not current_rule_in_defaults?(currently_selected_rule, default_schedules)
36
- options_array << ice_cube_rule_to_option(currently_selected_rule, true)
37
- custom_label = ["New custom schedule...", "custom"]
38
- else
39
- custom_label = ["Custom schedule...", "custom"]
40
- end
41
-
42
- options_array << seperator
43
- options_array << custom_label
44
- end
45
-
46
- options_for_select(options_array, currently_selected_rule.to_json)
47
- end
48
-
49
- private
50
-
51
- def ice_cube_rule_to_option(supplied_rule, custom = false)
52
- return supplied_rule unless RecurringSelect.is_valid_rule?(supplied_rule)
53
-
54
- rule = RecurringSelect.dirty_hash_to_rule(supplied_rule)
55
- ar = [rule.to_s, rule.to_hash.to_json]
56
-
57
- if custom
58
- ar[0] << "*"
59
- ar << {"data-custom" => true}
8
+ if defined?(RecurringSelectHelper::RecurringSelectTag)
9
+ # === Rails 4
10
+ RecurringSelectTag.new(object, method, self, default_schedules, options, html_options).render
11
+ elsif defined?(RecurringSelectHelper::InstanceTag)
12
+ # === Rails 3
13
+ InstanceTag.new(object, method, self, options.delete(:object)).to_recurring_select_tag(default_schedules, options, html_options)
60
14
  end
61
-
62
- ar
63
- end
64
-
65
- def current_rule_in_defaults?(currently_selected_rule, default_schedules)
66
- default_schedules.any?{|option|
67
- option == currently_selected_rule or
68
- (option.is_a?(Array) and option[1] == currently_selected_rule)
69
- }
70
- end
71
-
72
- end
73
-
74
- class InstanceTag < ActionView::Helpers::InstanceTag
75
- include FormOptionsHelper
76
-
77
- def to_recurring_select_tag(default_schedules, options, html_options)
78
- html_options = recurring_select_html_options(html_options)
79
- add_default_name_and_id(html_options)
80
- value = value(object)
81
- content_tag("select",
82
- add_options(
83
- recurring_options_for_select(value, default_schedules, options),
84
- options, value
85
- ), html_options
86
- )
87
- end
88
-
89
- private
90
-
91
- def recurring_select_html_options(html_options)
92
- html_options = html_options.stringify_keys
93
- html_options["class"] = ((html_options["class"] || "").split() + ["recurring_select"]).join(" ")
94
- html_options
95
15
  end
96
16
  end
97
17
 
@@ -0,0 +1,64 @@
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] || "- not recurring -"
7
+ blank_option = [blank_option_label, "null"]
8
+ separator = ["or", {:disabled => true}]
9
+
10
+ if default_schedules.blank?
11
+ if currently_selected_rule
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 << ["Change schedule...", "custom"]
16
+ else
17
+ options_array << blank_option
18
+ options_array << ["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 currently_selected_rule 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 = ["New custom schedule...", "custom"]
30
+ else
31
+ custom_label = ["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
@@ -0,0 +1,53 @@
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 defined?(ActionView::Helpers::Tags::Base)
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
+ elsif defined?(ActionView::Helpers::InstanceTag)
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
@@ -1,3 +1,3 @@
1
1
  module RecurringSelect
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recurring_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jobber
@@ -11,12 +10,11 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-04-30 00:00:00.000000000 Z
13
+ date: 2013-06-27 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: rails
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
19
  - - ! '>='
22
20
  - !ruby/object:Gem::Version
@@ -24,7 +22,6 @@ dependencies:
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
26
  - - ! '>='
30
27
  - !ruby/object:Gem::Version
@@ -32,7 +29,6 @@ dependencies:
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: jquery-rails
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
33
  - - ! '>='
38
34
  - !ruby/object:Gem::Version
@@ -40,7 +36,6 @@ dependencies:
40
36
  type: :runtime
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
40
  - - ! '>='
46
41
  - !ruby/object:Gem::Version
@@ -48,7 +43,6 @@ dependencies:
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: ice_cube
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
47
  - - ! '>='
54
48
  - !ruby/object:Gem::Version
@@ -56,7 +50,6 @@ dependencies:
56
50
  type: :runtime
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
54
  - - ! '>='
62
55
  - !ruby/object:Gem::Version
@@ -64,7 +57,6 @@ dependencies:
64
57
  - !ruby/object:Gem::Dependency
65
58
  name: sass-rails
66
59
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
60
  requirements:
69
61
  - - ! '>='
70
62
  - !ruby/object:Gem::Version
@@ -72,7 +64,6 @@ dependencies:
72
64
  type: :runtime
73
65
  prerelease: false
74
66
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
67
  requirements:
77
68
  - - ! '>='
78
69
  - !ruby/object:Gem::Version
@@ -80,7 +71,6 @@ dependencies:
80
71
  - !ruby/object:Gem::Dependency
81
72
  name: coffee-rails
82
73
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
74
  requirements:
85
75
  - - ! '>='
86
76
  - !ruby/object:Gem::Version
@@ -88,15 +78,13 @@ dependencies:
88
78
  type: :runtime
89
79
  prerelease: false
90
80
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
81
  requirements:
93
82
  - - ! '>='
94
83
  - !ruby/object:Gem::Version
95
84
  version: '3.1'
96
85
  - !ruby/object:Gem::Dependency
97
- name: pry
86
+ name: appraisal
98
87
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
88
  requirements:
101
89
  - - ! '>='
102
90
  - !ruby/object:Gem::Version
@@ -104,11 +92,24 @@ dependencies:
104
92
  type: :development
105
93
  prerelease: false
106
94
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
95
  requirements:
109
96
  - - ! '>='
110
97
  - !ruby/object:Gem::Version
111
98
  version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rspec
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '='
104
+ - !ruby/object:Gem::Version
105
+ version: 2.13.0
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '='
111
+ - !ruby/object:Gem::Version
112
+ version: 2.13.0
112
113
  description: This gem provides a useful interface for creating recurring rules for
113
114
  the ice_cube gem.
114
115
  email:
@@ -127,6 +128,8 @@ files:
127
128
  - app/assets/stylesheets/utilities.scss
128
129
  - app/assets/templates/recurring_select/dialog_template.html
129
130
  - app/helpers/recurring_select_helper.rb
131
+ - app/helpers/utilities/form_options_ext.rb
132
+ - app/helpers/utilities/tag_ext.rb
130
133
  - app/middleware/recurring_select_middleware.rb
131
134
  - config/routes.rb
132
135
  - lib/recurring_select/engine.rb
@@ -137,27 +140,25 @@ files:
137
140
  - README.md
138
141
  homepage: http://github.com/getjobber/recurring_select
139
142
  licenses: []
143
+ metadata: {}
140
144
  post_install_message:
141
145
  rdoc_options: []
142
146
  require_paths:
143
147
  - lib
144
148
  required_ruby_version: !ruby/object:Gem::Requirement
145
- none: false
146
149
  requirements:
147
150
  - - ! '>='
148
151
  - !ruby/object:Gem::Version
149
152
  version: '0'
150
153
  required_rubygems_version: !ruby/object:Gem::Requirement
151
- none: false
152
154
  requirements:
153
155
  - - ! '>='
154
156
  - !ruby/object:Gem::Version
155
157
  version: '0'
156
158
  requirements: []
157
159
  rubyforge_project:
158
- rubygems_version: 1.8.24
160
+ rubygems_version: 2.0.3
159
161
  signing_key:
160
- specification_version: 3
162
+ specification_version: 4
161
163
  summary: A select helper which gives you magical powers to generate ice_cube rules.
162
164
  test_files: []
163
- has_rdoc: