datetime_picker_input 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +15 -0
- data/Gemfile +25 -0
- data/LICENSE +21 -0
- data/README.md +114 -0
- data/Rakefile +12 -0
- data/app/inputs/date_time_picker_input.rb +53 -0
- data/datetime_picker_input.gemspec +23 -0
- data/lib/datetime_picker_input.rb +8 -0
- data/lib/datetime_picker_input/version.rb +3 -0
- data/lib/generators/datetime_picker_input.rb/install_generator.rb +15 -0
- data/lib/generators/templates/inputs/date_time_picker_input.rb +53 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +6 -0
- data/spec/dummy/app/assets/stylesheets/application.scss +3 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/appointments_controller.rb +15 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/appointment.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/appointments/index.html.slim +13 -0
- data/spec/dummy/app/views/appointments/new.html.slim +6 -0
- data/spec/dummy/app/views/layouts/application.html.slim +11 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +40 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/simple_form.rb +166 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/locales/simple_form.en.yml +31 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150224051923_create_appointments.rb +7 -0
- data/spec/dummy/db/schema.rb +20 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/log/development.log +3657 -0
- data/spec/dummy/log/test.log +2263 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/feature_helper.rb +37 -0
- data/spec/features/datetime_picker_input_spec.rb +12 -0
- data/spec/rails_helper.rb +19 -0
- data/vendor/assets/javascripts/datetime_picker_input.js +9 -0
- data/vendor/assets/stylesheets/datetime_picker_input.scss +1 -0
- metadata +196 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 060d125217e9a24c62332cc6d277388c7ebfd376
|
4
|
+
data.tar.gz: dac91ac1bd6a48d09ae53e1a5ed0b0c888166549
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c12d534e522da0954c5c2462a67a0d9a4eea35d40f068db45b9f8c03a4a10af4a5947614b24c227a4498d2ce918f29286eefe8efb1db8f27bea355df22c2ae18
|
7
|
+
data.tar.gz: 0cb51d401cdc5c0ba554c0e898007fa4d72afab7825dee7dd35963578e5c0273692b86b7467579d21e53a4c3d797928b99f5d932c7535f3d89063e807b3980ec
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
- 2.1
|
5
|
+
- 2.2
|
6
|
+
- ruby-head
|
7
|
+
sudo: false
|
8
|
+
bundler_args: --retry=3 --jobs=3
|
9
|
+
matrix:
|
10
|
+
allow_failures:
|
11
|
+
- rvm: ruby-head
|
12
|
+
fast_finish: true
|
13
|
+
notifications:
|
14
|
+
slack:
|
15
|
+
secure: SH+hAIMND0/8N1jouaAKaI7dv03ousdepfvnin9eSoSSiPBkEwAdC9WpiPihulat8UDUoxxGp5VstdZc2PkrgT+w8ullMXiLBp+1ZDntH7rGUnbtAG2gIyfApx8foKWYb3Pn4zp5NJnfASOSiJ91X6zn1n/JpjAY9x3CIwQsov4=
|
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem "rake"
|
5
|
+
gem "bundler"
|
6
|
+
|
7
|
+
gem "rails", ">= 4.1.9"
|
8
|
+
gem "slim-rails"
|
9
|
+
gem "sqlite3"
|
10
|
+
gem "sass-rails"
|
11
|
+
gem "coffee-rails"
|
12
|
+
gem "jquery-rails"
|
13
|
+
gem "turbolinks"
|
14
|
+
gem "bootstrap-sass"
|
15
|
+
|
16
|
+
gem "simple_form"
|
17
|
+
gem "rspec-rails"
|
18
|
+
gem "capybara"
|
19
|
+
gem "launchy"
|
20
|
+
gem "poltergeist"
|
21
|
+
gem "database_cleaner"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Specify your gem's dependencies in datetime_picker_input.gemspec
|
25
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Jolly Good Code
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# DatetimePickerInput
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/jollygoodcode/datetime_picker_input.svg?branch=feature%2Ftravis-ci)](https://travis-ci.org/jollygoodcode/datetime_picker_input)
|
4
|
+
|
5
|
+
DatetimePickerInput allows you to easily add a [JavaScript datetime picker](http://eonasdan.github.io/bootstrap-datetimepicker/) to your Ruby on Rails, Bootstrap-enabled Simple Form input.
|
6
|
+
|
7
|
+
## Prerequisites
|
8
|
+
|
9
|
+
Rails 3.1 and 4+ compatible, and your app should already have Bootstrap and Simple Form installed.
|
10
|
+
|
11
|
+
Otherwise, set up [Bootstrap](https://github.com/twbs/bootstrap-sass) and [Simple Form](https://github.com/plataformatec/simple_form) now.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this to your application's Gemfile then run `bundle install`:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'datetime_picker_input'
|
19
|
+
```
|
20
|
+
|
21
|
+
In the JavaScript manifest file `application.js`, add:
|
22
|
+
|
23
|
+
```js
|
24
|
+
//= require datetime_picker_input
|
25
|
+
```
|
26
|
+
|
27
|
+
In the CSS manifest file `application.scss`, add:
|
28
|
+
|
29
|
+
```scss
|
30
|
+
@import 'datetime_picker_input';
|
31
|
+
```
|
32
|
+
|
33
|
+
or `application.css`:
|
34
|
+
|
35
|
+
```css
|
36
|
+
*= require datetime_picker_input
|
37
|
+
```
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
Demo app is available at [http://datetime-picker-input.herokuapp.com](http://datetime-picker-input.herokuapp.com).
|
42
|
+
|
43
|
+
### Simple Usage
|
44
|
+
|
45
|
+
```slim
|
46
|
+
= simple_form_for Event.new do |f|
|
47
|
+
f.input :when, as: :date_time_picker
|
48
|
+
```
|
49
|
+
|
50
|
+
### Customized Options
|
51
|
+
|
52
|
+
```slim
|
53
|
+
= f.input :when, as: :date_time_picker, input_html:
|
54
|
+
{ data:
|
55
|
+
{
|
56
|
+
date_format: "YYYY-MM-DD hh:mm A",
|
57
|
+
date_day_view_header_format: 'MMM YYYY',
|
58
|
+
date_side_by_side: true,
|
59
|
+
date_min_date: Time.current.strftime('%Y-%m-%d')
|
60
|
+
}
|
61
|
+
}
|
62
|
+
```
|
63
|
+
|
64
|
+
[Bootstrap 3 Datepicker](https://github.com/Eonasdan/bootstrap-datetimepicker/blob/master/src/js/bootstrap-datetimepicker.js#L291) is able to initialize a datetime picker through the use of `data` attributes on the `input` field.
|
65
|
+
|
66
|
+
To do that, modify any of the options specified in [Bootstrap 3 Datepicker's Doc](http://eonasdan.github.io/bootstrap-datetimepicker/Options/) by adding a prefix of `date` and underscoring the resulting option name.
|
67
|
+
|
68
|
+
For example:
|
69
|
+
|
70
|
+
- `dayViewHeaderFormat` to `date_day_view_header_format`
|
71
|
+
- `minDate` to `date_min_date`
|
72
|
+
|
73
|
+
## Customization
|
74
|
+
|
75
|
+
To [customize the input field](https://github.com/plataformatec/simple_form/wiki/Adding-custom-input-components), you can copy `datetime_picker_input.rb` from the gem to your app by using the generator included in `datetime_picker_input`.
|
76
|
+
|
77
|
+
Simple do:
|
78
|
+
|
79
|
+
```bash
|
80
|
+
$ rails g datetime_picker_input:install
|
81
|
+
```
|
82
|
+
|
83
|
+
This will generate `datetime_picker_input.rb` under `app/inputs` directory which you can modify.
|
84
|
+
|
85
|
+
## Dependencies
|
86
|
+
|
87
|
+
This gem is heavily dependent on and only possible because of the great work done in these gems:
|
88
|
+
|
89
|
+
- https://github.com/TrevorS/bootstrap3-datetimepicker-rails
|
90
|
+
- https://github.com/derekprior/momentjs-rails
|
91
|
+
|
92
|
+
## Versioning
|
93
|
+
|
94
|
+
Since this gem is ultimately dependent on https://github.com/Eonasdan/bootstrap-datetimepicker, this gem shall have the same version as the JavaScript plugin - current release version is 4.0.0.
|
95
|
+
|
96
|
+
Any bug fix release of this gem will have a 4th decimal added, e.g. 4.0.0.1, 4.0.0.2.
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork it ( https://github.com/jollygoodcode/datetime_picker_input/fork )
|
101
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
102
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
103
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
104
|
+
5. Create a new Pull Request
|
105
|
+
|
106
|
+
## Credits
|
107
|
+
|
108
|
+
A huge THANK YOU to all our [contributors] (https://github.com/jollygoodcode/datetime_picker_input/graphs/contributors)! :heart:
|
109
|
+
|
110
|
+
This project is maintained by [Jolly Good Code](http://www.jollygoodcode.com).
|
111
|
+
|
112
|
+
## License
|
113
|
+
|
114
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
5
|
+
load "rails/tasks/engine.rake"
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
Dir[File.join(File.dirname(__FILE__), "tasks/**/*.rake")].each {|f| load f }
|
8
|
+
require "rspec/core"
|
9
|
+
require "rspec/core/rake_task"
|
10
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
11
|
+
RSpec::Core::RakeTask.new(spec: "app:db:test:prepare")
|
12
|
+
task default: :spec
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Example:
|
2
|
+
#
|
3
|
+
# = simple_form_for Event.new do |f|
|
4
|
+
# = f.input :when, as: :date_time_picker, input_html: \
|
5
|
+
# { data: \
|
6
|
+
# { \
|
7
|
+
# date_format: "YYYY-MM-DD hh:mm A", \
|
8
|
+
# date_day_view_header_format: 'MMM YYYY', \
|
9
|
+
# date_side_by_side: true, \
|
10
|
+
# date_min_date: Time.current.strftime('%Y-%m-%d') \
|
11
|
+
# } \
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# Refer to http://eonasdan.github.io/bootstrap-datetimepicker/#options for a full list of options.
|
15
|
+
#
|
16
|
+
class DateTimePickerInput < SimpleForm::Inputs::StringInput
|
17
|
+
def input(wrapper_options)
|
18
|
+
input_html_options[:type] = "text"
|
19
|
+
|
20
|
+
input_html_options[:data] ||= {}
|
21
|
+
input_html_options[:data].reverse_merge!(date_format: picker_pattern)
|
22
|
+
|
23
|
+
input_html_options[:value] ||= I18n.localize(attr_value, format: display_pattern) if attr_value.present?
|
24
|
+
|
25
|
+
template.content_tag :div, class: "input-group date datetime_picker" do
|
26
|
+
input = super(wrapper_options)
|
27
|
+
input += template.content_tag :span, class: "input-group-btn" do
|
28
|
+
template.content_tag :button, class: "btn btn-default", type: "button" do
|
29
|
+
template.content_tag :i, "", class: "glyphicon glyphicon-calendar"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
input
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def input_html_classes
|
37
|
+
super.push "" # 'form-control'
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def display_pattern
|
43
|
+
I18n.t("datepicker.dformat", default: "%d/%m/%Y") + " " + I18n.t("timepicker.dformat", default: "%R")
|
44
|
+
end
|
45
|
+
|
46
|
+
def picker_pattern
|
47
|
+
I18n.t("datepicker.pformat", default: "DD/MM/YYYY") + " " + I18n.t("timepicker.pformat", default: "HH:mm")
|
48
|
+
end
|
49
|
+
|
50
|
+
def attr_value
|
51
|
+
object.send(attribute_name) if object.respond_to? attribute_name
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "datetime_picker_input/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "datetime_picker_input"
|
8
|
+
spec.version = DatetimePickerInput::VERSION
|
9
|
+
spec.authors = %w(Juanito Fatas)
|
10
|
+
spec.email = %w(katehuang0320@gmail.com)
|
11
|
+
spec.summary = %(Datetime picker wrapper of https://github.com/TrevorS/bootstrap3-datetimepicker-rails, for use with simple_form on Rails 4+.)
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/jollygoodcode/datetime_picker_input"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = Dir["spec/**/*"]
|
19
|
+
spec.require_paths = %w(lib)
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "bootstrap3-datetimepicker-rails", "~> 4.0.0"
|
22
|
+
spec.add_runtime_dependency "momentjs-rails", ">= 2.9.0"
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rails"
|
2
|
+
|
3
|
+
module DatetimePickerInput
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
desc "This generator installs DatetimePickerInput #{DatetimePickerInput::VERSION}"
|
7
|
+
source_root File.expand_path("../../templates", __FILE__)
|
8
|
+
|
9
|
+
def install_datetime_picker_input
|
10
|
+
say_status("Installing", "DatetimePickerInput (#{DatetimePickerInput::VERSION})", :green)
|
11
|
+
template "inputs/datetime_picker_input.rb", "app/inputs/datetime_picker_input.rb" if !File.exist?("app/inputs/datetime_picker_input.rb")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Example:
|
2
|
+
#
|
3
|
+
# = simple_form_for Event.new do |f|
|
4
|
+
# = f.input :when, as: :date_time_picker, input_html: \
|
5
|
+
# { data: \
|
6
|
+
# { \
|
7
|
+
# date_format: "YYYY-MM-DD hh:mm A", \
|
8
|
+
# date_day_view_header_format: 'MMM YYYY', \
|
9
|
+
# date_side_by_side: true, \
|
10
|
+
# date_min_date: Time.current.strftime('%Y-%m-%d') \
|
11
|
+
# } \
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# Refer to http://eonasdan.github.io/bootstrap-datetimepicker/#options for a full list of options.
|
15
|
+
#
|
16
|
+
class DateTimePickerInput < SimpleForm::Inputs::StringInput
|
17
|
+
def input(wrapper_options)
|
18
|
+
input_html_options[:type] = "text"
|
19
|
+
|
20
|
+
input_html_options[:data] ||= {}
|
21
|
+
input_html_options[:data].reverse_merge!(date_format: picker_pattern)
|
22
|
+
|
23
|
+
input_html_options[:value] ||= I18n.localize(attr_value, format: display_pattern) if attr_value.present?
|
24
|
+
|
25
|
+
template.content_tag :div, class: "input-group date datetime_picker" do
|
26
|
+
input = super(wrapper_options)
|
27
|
+
input += template.content_tag :span, class: "input-group-btn" do
|
28
|
+
template.content_tag :button, class: "btn btn-default", type: "button" do
|
29
|
+
template.content_tag :i, "", class: "glyphicon glyphicon-calendar"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
input
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def input_html_classes
|
37
|
+
super.push "" # 'form-control'
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def display_pattern
|
43
|
+
I18n.t("datepicker.dformat", default: "%d/%m/%Y") + " " + I18n.t("timepicker.dformat", default: "%R")
|
44
|
+
end
|
45
|
+
|
46
|
+
def picker_pattern
|
47
|
+
I18n.t("datepicker.pformat", default: "DD/MM/YYYY") + " " + I18n.t("timepicker.pformat", default: "HH:mm")
|
48
|
+
end
|
49
|
+
|
50
|
+
def attr_value
|
51
|
+
object.send(attribute_name) if object.respond_to? attribute_name
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
File without changes
|