date_select_separator 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -10
- data/Rakefile +28 -1
- data/lib/date_select_separator/action_view_extension.rb +86 -0
- data/lib/date_select_separator/railtie.rb +9 -0
- data/lib/date_select_separator/version.rb +1 -1
- data/lib/date_select_separator.rb +4 -92
- data/test/date_select_separator_test.rb +3817 -319
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/samples_controller.rb +58 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/sample.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/samples/_form.html.erb +29 -0
- data/test/dummy/app/views/samples/edit.html.erb +6 -0
- data/test/dummy/app/views/samples/index.html.erb +31 -0
- data/test/dummy/app/views/samples/new.html.erb +5 -0
- data/test/dummy/app/views/samples/show.html.erb +19 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +24 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +31 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +218 -0
- data/test/dummy/config/locales/ja.yml +208 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140214065227_create_samples.rb +11 -0
- data/test/dummy/db/schema.rb +24 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +1537 -0
- data/test/dummy/log/test.log +435691 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/restart.txt +0 -0
- data/test/test_helper.rb +12 -0
- metadata +134 -17
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/date_select_separator.gemspec +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb54a4895e0f3b1d091b1aa1dc57762773c570bc
|
4
|
+
data.tar.gz: 3390de920b13d01948d61f20658ffc27565db450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54e1647eee9b17b5d4089ed9cdae47cd546cad2826eacedda0d788452834b47ad1242494e579a4e1c2ad37e7776e3f6b3f3996bd1f0be5b9a64b335ae0e5fae3
|
7
|
+
data.tar.gz: cb19585216815a897cfa1c47d950403d275467fcbbcb018fed4b8eac797d74eb89ff7f495ccb041f17d5f6542d46dd3f6b69cef54339ceee25dc3e0abb731ac9
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# DateSelectSeparator
|
2
2
|
|
3
|
-
Add separators to data_select on Rails.
|
3
|
+
Add separators to data_select and datetime_select on Ruby on Rails.
|
4
|
+
|
5
|
+
![](https://dl.dropboxusercontent.com/u/177616/images/github/date_select_separator/1.png)
|
6
|
+
![](https://dl.dropboxusercontent.com/u/177616/images/github/date_select_separator/2.png)
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -14,7 +17,7 @@ And then execute:
|
|
14
17
|
|
15
18
|
## Usage
|
16
19
|
|
17
|
-
Add
|
20
|
+
Add translations to your locale file like below.
|
18
21
|
|
19
22
|
ja:
|
20
23
|
datetime:
|
@@ -26,20 +29,20 @@ Add these lines in your locale file like [config/locales/ja.yml](https://github.
|
|
26
29
|
minute: 分
|
27
30
|
second: 秒
|
28
31
|
|
29
|
-
|
32
|
+
Add `use_separators: true` option to data_select or datetime_select.
|
30
33
|
|
31
34
|
# Add a separator after each select_tags
|
32
35
|
<%= f.date_select :birthday, use_month_numbers: true, use_separators: true %>
|
33
36
|
<%= f.datetime_select :birthday, use_month_numbers: true, time_separator: '', use_separators: true %>
|
34
|
-
|
37
|
+
|
35
38
|
# Add a separator to each option_tags except month. Month is used a value like ja.data.month_names
|
36
|
-
<%= f.date_select :birthday, use_separators: {inline: true} %>
|
37
|
-
<%= f.datetime_select :birthday, time_separator: '', use_separators: {inline: true} %>
|
38
|
-
|
39
|
+
<%= f.date_select :birthday, use_separators: { inline: true } %>
|
40
|
+
<%= f.datetime_select :birthday, time_separator: '', use_separators: { inline: true } %>
|
41
|
+
|
39
42
|
# Options: html_tag, class_prefix etc
|
40
|
-
<%= f.date_select :birthday, use_month_numbers: true, use_separators: {html_tag: :div, class_prefix: 'foo'} %>
|
41
|
-
<%= f.date_select :birthday, use_month_numbers: true, use_separators: {year: 'yy', month: 'mm', day: 'dd'} %>
|
42
|
-
|
43
|
+
<%= f.date_select :birthday, use_month_numbers: true, use_separators: { html_tag: :div, class_prefix: 'foo' } %>
|
44
|
+
<%= f.date_select :birthday, use_month_numbers: true, use_separators: { year: 'yy', month: 'mm', day: 'dd' } %>
|
45
|
+
|
43
46
|
## Contributing
|
44
47
|
|
45
48
|
1. Fork it
|
data/Rakefile
CHANGED
@@ -1 +1,28 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'DateSelectSeparator'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'lib'
|
23
|
+
t.libs << 'test'
|
24
|
+
t.pattern = 'test/**/*_test.rb'
|
25
|
+
t.verbose = false
|
26
|
+
end
|
27
|
+
|
28
|
+
task default: :test
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module DateSelectSeparator
|
2
|
+
module ActionViewExtension
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
def select_month_with_separator
|
7
|
+
separators = @options[:use_separators]
|
8
|
+
select_tag = select_month_without_separator
|
9
|
+
|
10
|
+
if use_separators?(:month, separators) && !inline_separator?(separators)
|
11
|
+
select_tag << separator_tag(:month, separators)
|
12
|
+
end
|
13
|
+
|
14
|
+
select_tag
|
15
|
+
end
|
16
|
+
alias_method_chain :select_month, :separator
|
17
|
+
|
18
|
+
private
|
19
|
+
def use_separators?(type, separators)
|
20
|
+
discard_type = "discard_#{type}".to_sym
|
21
|
+
!@options[:use_hidden] && !@options[discard_type] && separators
|
22
|
+
end
|
23
|
+
|
24
|
+
def inline_separator?(separators)
|
25
|
+
separators.is_a?(Hash) && separators[:inline]
|
26
|
+
end
|
27
|
+
|
28
|
+
def separator_text(type, separators)
|
29
|
+
if separators.is_a?(Hash) && separators[type]
|
30
|
+
separators[type]
|
31
|
+
else
|
32
|
+
key = 'datetime.separators.' + type.to_s
|
33
|
+
I18n.translate(key, locale: @options[:locale])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def separator_tag(type, separators)
|
38
|
+
default_options = { html_tag: :span, class_prefix: 'separator' }
|
39
|
+
options = separators.is_a?(Hash) ? default_options.merge!(separators) : default_options
|
40
|
+
text = separator_text(type, separators)
|
41
|
+
class_name = options[:class_prefix] + "_#{type}"
|
42
|
+
content_tag(options[:html_tag], text, class: class_name) + "\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_options_and_select_with_separator(type, selected, options = {})
|
46
|
+
separators = @options[:use_separators]
|
47
|
+
|
48
|
+
unless use_separators?(type, separators)
|
49
|
+
return build_options_and_select_without_separator(type, selected, options)
|
50
|
+
end
|
51
|
+
|
52
|
+
if inline_separator?(separators)
|
53
|
+
options.merge!(separator: separator_text(type, separators))
|
54
|
+
build_select(type, build_options_with_separator(selected, options))
|
55
|
+
else
|
56
|
+
build_select(type, build_options(selected, options)) + separator_tag(type, separators)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
alias_method_chain :build_options_and_select, :separator
|
60
|
+
|
61
|
+
def build_options_with_separator(selected, options = {})
|
62
|
+
options = {
|
63
|
+
leading_zeros: true, ampm: false, use_two_digit_numbers: false, separator: false
|
64
|
+
}.merge!(options)
|
65
|
+
|
66
|
+
start = options.delete(:start) || 0
|
67
|
+
stop = options.delete(:end) || 59
|
68
|
+
step = options.delete(:step) || 1
|
69
|
+
leading_zeros = options.delete(:leading_zeros)
|
70
|
+
|
71
|
+
select_options = []
|
72
|
+
start.step(stop, step) do |i|
|
73
|
+
value = leading_zeros ? sprintf("%02d", i) : i
|
74
|
+
tag_options = { value: value }
|
75
|
+
tag_options[:selected] = "selected" if selected == i
|
76
|
+
text = options[:use_two_digit_numbers] ? sprintf("%02d", i) : value
|
77
|
+
text = options[:ampm] ? AMPM_TRANSLATION[i] : text
|
78
|
+
text = options[:separator] ? text.to_s + options[:separator] : text
|
79
|
+
select_options << content_tag(:option, text, tag_options)
|
80
|
+
end
|
81
|
+
|
82
|
+
(select_options.join("\n") + "\n").html_safe
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module DateSelectSeparator
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer 'date_select_separator' do |app|
|
4
|
+
ActiveSupport.on_load(:action_view) do
|
5
|
+
::ActionView::Helpers::DateTimeSelector.send :include, DateSelectSeparator::ActionViewExtension
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,93 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module ActionView
|
4
|
-
module Helpers
|
5
|
-
class DateTimeSelector
|
6
|
-
def select_month_with_separator
|
7
|
-
separators = @options[:use_separators]
|
8
|
-
select_tag = select_month_without_separator
|
9
|
-
|
10
|
-
if @options[:use_hidden].blank? && @options[:discard_month].blank? && separators.present?
|
11
|
-
select_tag << separator_tag(:month, separators)
|
12
|
-
end
|
13
|
-
|
14
|
-
select_tag
|
15
|
-
end
|
16
|
-
alias_method_chain :select_month, :separator
|
17
|
-
|
18
|
-
def build_options_and_select_with_separator(type, selected, options = {})
|
19
|
-
separators = @options[:use_separators]
|
20
|
-
|
21
|
-
if separators.present?
|
22
|
-
if use_inline_separator?(separators)
|
23
|
-
options.merge!({:use_separator => separator_name(type, separators)})
|
24
|
-
build_select(type, build_options_with_separator(selected, options))
|
25
|
-
else
|
26
|
-
build_select(type, build_options(selected, options)) + separator_tag(type, separators)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
build_options_and_select_without_separator(type, selected, options)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
alias_method_chain :build_options_and_select, :separator
|
33
|
-
|
34
|
-
private
|
35
|
-
def use_inline_separator?(separators)
|
36
|
-
(separators.class == Hash && separators[:inline] == true)
|
37
|
-
end
|
38
|
-
|
39
|
-
def translated_separator_name(type)
|
40
|
-
key = 'datetime.separators.' + type.to_s
|
41
|
-
I18n.translate(key, :locale => @options[:locale])
|
42
|
-
end
|
43
|
-
|
44
|
-
def separator_name(type, separators)
|
45
|
-
if separators.class == Hash && separators[type].present?
|
46
|
-
separators[type]
|
47
|
-
else
|
48
|
-
key = 'datetime.separators.' + type.to_s
|
49
|
-
I18n.translate(key, :locale => @options[:locale])
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def separator_tag(type, separators)
|
54
|
-
return '' if use_inline_separator?(separators)
|
55
|
-
|
56
|
-
default_options = {:html_tag => :span, :class_prefix => 'separator'}
|
57
|
-
options = (separators.class == Hash) ? default_options.merge!(separators) : default_options
|
58
|
-
|
59
|
-
if options
|
60
|
-
name = separator_name(type, separators)
|
61
|
-
class_name = options[:class_prefix] + "_#{type}"
|
62
|
-
content_tag(options[:html_tag], name, :class => class_name) + "\n"
|
63
|
-
else
|
64
|
-
''
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def build_options_with_separator(selected, options = {})
|
69
|
-
options = {
|
70
|
-
leading_zeros: true, ampm: false, use_two_digit_numbers: false, use_separator: false
|
71
|
-
}.merge!(options)
|
72
|
-
|
73
|
-
start = options.delete(:start) || 0
|
74
|
-
stop = options.delete(:end) || 59
|
75
|
-
step = options.delete(:step) || 1
|
76
|
-
leading_zeros = options.delete(:leading_zeros)
|
77
|
-
|
78
|
-
select_options = []
|
79
|
-
start.step(stop, step) do |i|
|
80
|
-
value = leading_zeros ? sprintf("%02d", i) : i
|
81
|
-
tag_options = { :value => value }
|
82
|
-
tag_options[:selected] = "selected" if selected == i
|
83
|
-
text = options[:use_two_digit_numbers] ? sprintf("%02d", i) : value
|
84
|
-
text = options[:ampm] ? AMPM_TRANSLATION[i] : text
|
85
|
-
text = options[:use_separator] ? text.to_s + options[:use_separator] : text
|
86
|
-
select_options << content_tag(:option, text, tag_options)
|
87
|
-
end
|
88
|
-
|
89
|
-
(select_options.join("\n") + "\n").html_safe
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
1
|
+
module DateSelectSeparator
|
93
2
|
end
|
3
|
+
|
4
|
+
require 'date_select_separator/action_view_extension'
|
5
|
+
require 'date_select_separator/railtie'
|