bootstrap_form-datetimepicker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +111 -0
- data/Rakefile +12 -0
- data/bootstrap_form-datetimepicker.gemspec +24 -0
- data/lib/bootstrap_form-datetimepicker.rb +1 -0
- data/lib/bootstrap_form/datetimepicker.rb +94 -0
- data/lib/bootstrap_form/datetimepicker/version.rb +5 -0
- data/test/bootstrap_form/datetimepicker_test.rb +188 -0
- data/test/fake_app/fake_app.rb +42 -0
- data/test/test_helper.rb +10 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 240250e1b15b92d84401ad7843be2ef5f872b51d
|
4
|
+
data.tar.gz: 9bf9f14b59afcf0eeba64348b301302c82759d3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e60a3bb0c21f91a50aef944a8062c60ac56f932e21dd51ba40cbed9b6b410e85f335648cd2f2fc1ad6842ee64917044f6f93f8e2dff00f1d9acd84d9d09b8a8
|
7
|
+
data.tar.gz: 0c441d9a24d6abceda0f9f0b0c6b8b7705372aed7677da81d58b5a86d409d766d3a289173717cfb487b6730a5fc05b64a2c5788b0cd8c9fa0bc144b61655c80b
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Masato Ikeda
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/a2ikm/bootstrap_form-datetimepicker.svg?branch=master)](https://travis-ci.org/a2ikm/bootstrap_form-datetimepicker)
|
2
|
+
|
3
|
+
# Datetime Picker for Rails Bootstrap Forms
|
4
|
+
|
5
|
+
bootstrap_form-datetimepicker is [bootstrap_form](http://rubygems.org/gems/bootstrap_form) add-on to embed [bootstrap-datetimepicker](http://eonasdan.github.io/bootstrap-datetimepicker/) simply.
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
* Ruby 2.1+
|
10
|
+
* Rails 4.1+
|
11
|
+
* Twitter Bootstrap 3.0+
|
12
|
+
* bootstrap-datetimepicker
|
13
|
+
* momentjs
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'bootstrap_form-datetimepicker'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install bootstrap_form-datetimepicker
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Call `datetime_picker` within `bootstrap_form_for`:
|
32
|
+
|
33
|
+
```erb
|
34
|
+
<%= bootstrap_form_for(@item) do |f| %>
|
35
|
+
<%= f.datetime_picker :available_since %>
|
36
|
+
<% end %>
|
37
|
+
```
|
38
|
+
|
39
|
+
will produce HTML like:
|
40
|
+
|
41
|
+
```html
|
42
|
+
<div class="form-group">
|
43
|
+
<label class="control-label" for="item_available_since">Available Since</label>
|
44
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MM-DD HH:mm:ss ZZ">
|
45
|
+
<input class="form-control" id="item_available_since" name="item[available_since]" type="text" value="1955-10-23 11:22:33" />
|
46
|
+
<span class="input-group-addon">
|
47
|
+
<span class="glyphicon glyphicon-calendar">
|
48
|
+
</span>
|
49
|
+
</span>
|
50
|
+
</div>
|
51
|
+
</div>
|
52
|
+
```
|
53
|
+
|
54
|
+
Note that `bootstrap_form-datetimepicker` class is used for wrapping div element. So you should initialize widgets like:
|
55
|
+
|
56
|
+
```javascript
|
57
|
+
$(function () {
|
58
|
+
$('.bootstrap_form-datetimepicker').datetimepicker();
|
59
|
+
});
|
60
|
+
```
|
61
|
+
|
62
|
+
You can specify the element's class with `:datetimepicker_class` option like:
|
63
|
+
|
64
|
+
```erb
|
65
|
+
<%= bootstrap_form_for(@item) do |f| %>
|
66
|
+
<%= f.datetime_picker :available_since, datetimepicker_class: "my-picker-class" %>
|
67
|
+
<% end %>
|
68
|
+
```
|
69
|
+
|
70
|
+
|
71
|
+
### Customizing format
|
72
|
+
|
73
|
+
You can specify datetime's format with `:format` option like:
|
74
|
+
|
75
|
+
```erb
|
76
|
+
<%= bootstrap_form_for(@item) do |f| %>
|
77
|
+
<%= f.datetime_picker :available_since, format: "%Y-%m-%d" %>
|
78
|
+
<% end %>
|
79
|
+
```
|
80
|
+
|
81
|
+
or format's name defined in `Time::DATE_FORMATS` like:
|
82
|
+
|
83
|
+
```erb
|
84
|
+
<%= bootstrap_form_for(@item) do |f| %>
|
85
|
+
<%= f.datetime_picker :available_since, format: :db %>
|
86
|
+
<% end %>
|
87
|
+
```
|
88
|
+
|
89
|
+
Also you can these globally like:
|
90
|
+
|
91
|
+
```
|
92
|
+
BootstrapForm::Datetimepicker.format = "%Y-%m-%d %H:%M:%S"
|
93
|
+
BootstrapForm::Datetimepicker.datetimepicker_format = "YYYY-MM-SS HH:mm:ss"
|
94
|
+
```
|
95
|
+
|
96
|
+
bootstrap-datetimepicker formats datetime with [momentjs](http://momentjs.com), whose [its formating syntax](http://momentjs.com/docs/#/parsing/string-format/) differs from ruby's that. So this gem converts between them automatically, but in some cases, it can't (using `proc`, `%e`, etc). At that time, you should specify bootstrap-datetimepicker's format with `:datetimepicker_format` option like:
|
97
|
+
|
98
|
+
```erb
|
99
|
+
<%= bootstrap_form_for(@item) do |f| %>
|
100
|
+
<%= f.datetime_picker :available_since, format: "%e %b", datetimepicker_format: "dd MMM" %>
|
101
|
+
<% end %>
|
102
|
+
```
|
103
|
+
|
104
|
+
|
105
|
+
## Contributing
|
106
|
+
|
107
|
+
1. Fork it ( https://github.com/a2ikm/bootstrap_form-datetimepicker/fork )
|
108
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
109
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
110
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
111
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bootstrap_form/datetimepicker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bootstrap_form-datetimepicker"
|
8
|
+
spec.version = BootstrapForm::Datetimepicker::VERSION
|
9
|
+
spec.authors = ["Masato Ikeda"]
|
10
|
+
spec.email = ["masato.ikeda@gmail.com"]
|
11
|
+
spec.summary = %q{bootstrap_form add-on to embed bootstrap-datetimepicker simply.}
|
12
|
+
spec.description = %q{bootstrap_form add-on to embed bootstrap-datetimepicker simply.}
|
13
|
+
spec.homepage = "https://github.com/a2ikm/bootstrap_form-datetimepicker"
|
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 = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "bootstrap_form"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "bootstrap_form/datetimepicker"
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "bootstrap_form/datetimepicker/version"
|
2
|
+
require "bootstrap_form"
|
3
|
+
require "active_support/core_ext/date"
|
4
|
+
require "active_support/core_ext/time"
|
5
|
+
|
6
|
+
module BootstrapForm
|
7
|
+
module Datetimepicker
|
8
|
+
|
9
|
+
STRFTIME_MOMENTJS = {
|
10
|
+
"a" => "ddd",
|
11
|
+
"A" => "dddd",
|
12
|
+
"b" => "MMM",
|
13
|
+
"B" => "MMMM",
|
14
|
+
"d" => "DD",
|
15
|
+
"H" => "HH",
|
16
|
+
"I" => "hh",
|
17
|
+
"j" => "DDDD",
|
18
|
+
"m" => "MM",
|
19
|
+
"M" => "mm",
|
20
|
+
"p" => "A",
|
21
|
+
"S" => "ss",
|
22
|
+
"Z" => "z",
|
23
|
+
"z" => "ZZ",
|
24
|
+
"w" => "d",
|
25
|
+
"y" => "YY",
|
26
|
+
"Y" => "YYYY",
|
27
|
+
}
|
28
|
+
|
29
|
+
def datetime_picker(method, options = {})
|
30
|
+
datetimepicker_class = options.delete(:datetimepicker_class) || "bootstrap_form-datetimepicker"
|
31
|
+
|
32
|
+
format = options.delete(:format) || config.format
|
33
|
+
if format
|
34
|
+
format = Time::DATE_FORMATS[format] if Time::DATE_FORMATS.has_key?(format)
|
35
|
+
else
|
36
|
+
format = "%Y-%m-%d %H:%M:%S %z"
|
37
|
+
end
|
38
|
+
|
39
|
+
initial_value = object.send(method)
|
40
|
+
if format.respond_to?(:call)
|
41
|
+
options[:value] = format.call(initial_value)
|
42
|
+
elsif initial_value.try(:acts_like_time?)
|
43
|
+
options[:value] = initial_value.strftime(format)
|
44
|
+
else
|
45
|
+
options[:value] = initial_value
|
46
|
+
end
|
47
|
+
|
48
|
+
datetimepicker_format =
|
49
|
+
options.delete(:datetimepicker_format) || config.datetimepicker_format
|
50
|
+
if datetimepicker_format
|
51
|
+
# do nothing
|
52
|
+
elsif format.is_a?(String)
|
53
|
+
datetimepicker_format = strftime2momentjs(format)
|
54
|
+
else
|
55
|
+
datetimepicker_format = "YYYY-MM-DD HH:mm:ss ZZ"
|
56
|
+
end
|
57
|
+
|
58
|
+
form_group_builder(method, options) do
|
59
|
+
prepend_and_append_input(options) do
|
60
|
+
|
61
|
+
input_tag = @template.text_field(object_name, method, options)
|
62
|
+
span_tag = content_tag :span, :class => "input-group-addon" do
|
63
|
+
content_tag :span, "", :class => "glyphicon glyphicon-calendar"
|
64
|
+
end
|
65
|
+
content_tag :div, input_tag.concat(span_tag),
|
66
|
+
:class => "#{datetimepicker_class} input-group date",
|
67
|
+
:data => {
|
68
|
+
"date-format" => datetimepicker_format
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def config
|
75
|
+
::BootstrapForm::Datetimepicker
|
76
|
+
end
|
77
|
+
|
78
|
+
class <<self
|
79
|
+
attr_accessor :format, :datetimepicker_format
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def strftime2momentjs(format)
|
85
|
+
replaced = format.dup
|
86
|
+
STRFTIME_MOMENTJS.each do |key, replacement|
|
87
|
+
replaced.gsub!("%#{key}", replacement)
|
88
|
+
end
|
89
|
+
replaced
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
FormBuilder.send :include, Datetimepicker
|
94
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BootstrapFromDatetimepickerTest < ActionView::TestCase
|
4
|
+
def setup
|
5
|
+
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? "schedules"
|
6
|
+
Schedule.delete_all
|
7
|
+
|
8
|
+
@schedule = Schedule.new
|
9
|
+
@builder = BootstrapForm::FormBuilder.new(:schedule, @schedule, self, {})
|
10
|
+
@horizontal_builder = BootstrapForm::FormBuilder.new(:schedule, @schedule, self, { layout: :horizontal })
|
11
|
+
end
|
12
|
+
|
13
|
+
test "render datetimepicker correctly in normal layout" do
|
14
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
15
|
+
<div class="form-group">
|
16
|
+
<label class="control-label" for="schedule_until">Until</label>
|
17
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MM-DD HH:mm:ss ZZ">
|
18
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" />
|
19
|
+
<span class="input-group-addon">
|
20
|
+
<span class="glyphicon glyphicon-calendar">
|
21
|
+
</span>
|
22
|
+
</span>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
HTML
|
26
|
+
|
27
|
+
assert_equal expected, @builder.datetime_picker(:until)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "render datetimepicker correctly in horizontal layout" do
|
31
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
32
|
+
<div class="form-group">
|
33
|
+
<label class="control-label col-sm-2" for="schedule_until">Until</label>
|
34
|
+
<div class="col-sm-10">
|
35
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MM-DD HH:mm:ss ZZ">
|
36
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" />
|
37
|
+
<span class="input-group-addon">
|
38
|
+
<span class="glyphicon glyphicon-calendar">
|
39
|
+
</span>
|
40
|
+
</span>
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
HTML
|
45
|
+
|
46
|
+
assert_equal expected, @horizontal_builder.datetime_picker(:until)
|
47
|
+
end
|
48
|
+
|
49
|
+
test "use :datetimepicker_class option for wrapping div element's class" do
|
50
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
51
|
+
<div class="form-group">
|
52
|
+
<label class="control-label col-sm-2" for="schedule_until">Until</label>
|
53
|
+
<div class="col-sm-10">
|
54
|
+
<div class="custom-datetimepicker-class input-group date" data-date-format="YYYY-MM-DD HH:mm:ss ZZ">
|
55
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" />
|
56
|
+
<span class="input-group-addon">
|
57
|
+
<span class="glyphicon glyphicon-calendar">
|
58
|
+
</span>
|
59
|
+
</span>
|
60
|
+
</div>
|
61
|
+
</div>
|
62
|
+
</div>
|
63
|
+
HTML
|
64
|
+
|
65
|
+
assert_equal expected, @horizontal_builder.datetime_picker(:until, :datetimepicker_class => "custom-datetimepicker-class")
|
66
|
+
end
|
67
|
+
|
68
|
+
test "put object's value for value attribute" do
|
69
|
+
@schedule.until = Time.now
|
70
|
+
|
71
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
72
|
+
<div class="form-group">
|
73
|
+
<label class="control-label" for="schedule_until">Until</label>
|
74
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MM-DD HH:mm:ss ZZ">
|
75
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" value="#{@schedule.until.to_s}" />
|
76
|
+
<span class="input-group-addon">
|
77
|
+
<span class="glyphicon glyphicon-calendar">
|
78
|
+
</span>
|
79
|
+
</span>
|
80
|
+
</div>
|
81
|
+
</div>
|
82
|
+
HTML
|
83
|
+
|
84
|
+
assert_equal expected, @builder.datetime_picker(:until)
|
85
|
+
end
|
86
|
+
|
87
|
+
test "use Time::DATE_FORMATS' format for value attribute and data-date-format attribute when :format option is specified by its name" do
|
88
|
+
@schedule.until = Time.now
|
89
|
+
Time::DATE_FORMATS[:custom] = "%Y-%m-%d"
|
90
|
+
|
91
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
92
|
+
<div class="form-group">
|
93
|
+
<label class="control-label" for="schedule_until">Until</label>
|
94
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MM-DD">
|
95
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" value="#{@schedule.until.to_s(:custom)}" />
|
96
|
+
<span class="input-group-addon">
|
97
|
+
<span class="glyphicon glyphicon-calendar">
|
98
|
+
</span>
|
99
|
+
</span>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
HTML
|
103
|
+
|
104
|
+
assert_equal expected, @builder.datetime_picker(:until, :format => :custom)
|
105
|
+
end
|
106
|
+
|
107
|
+
test "use format specified with :format option for value attribute and data-date-format attribute" do
|
108
|
+
@schedule.until = Time.now
|
109
|
+
|
110
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
111
|
+
<div class="form-group">
|
112
|
+
<label class="control-label" for="schedule_until">Until</label>
|
113
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MM-DD">
|
114
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" value="#{@schedule.until.strftime("%Y-%m-%d")}" />
|
115
|
+
<span class="input-group-addon">
|
116
|
+
<span class="glyphicon glyphicon-calendar">
|
117
|
+
</span>
|
118
|
+
</span>
|
119
|
+
</div>
|
120
|
+
</div>
|
121
|
+
HTML
|
122
|
+
|
123
|
+
assert_equal expected, @builder.datetime_picker(:until, :format => "%Y-%m-%d")
|
124
|
+
end
|
125
|
+
|
126
|
+
test "use :datetimepicker_format option for data-date-format attribute" do
|
127
|
+
@schedule.until = Time.now
|
128
|
+
|
129
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
130
|
+
<div class="form-group">
|
131
|
+
<label class="control-label" for="schedule_until">Until</label>
|
132
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MMMM-DDDD">
|
133
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" value="#{@schedule.until.strftime("%Y-%m-%d")}" />
|
134
|
+
<span class="input-group-addon">
|
135
|
+
<span class="glyphicon glyphicon-calendar">
|
136
|
+
</span>
|
137
|
+
</span>
|
138
|
+
</div>
|
139
|
+
</div>
|
140
|
+
HTML
|
141
|
+
|
142
|
+
assert_equal expected, @builder.datetime_picker(:until, :format => "%Y-%m-%d", :datetimepicker_format => "YYYY-MMMM-DDDD")
|
143
|
+
end
|
144
|
+
|
145
|
+
test "configure global :format" do
|
146
|
+
old_config = ::BootstrapForm::Datetimepicker.format
|
147
|
+
::BootstrapForm::Datetimepicker.format = "%Y-%m-%d"
|
148
|
+
|
149
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
150
|
+
<div class="form-group">
|
151
|
+
<label class="control-label" for="schedule_until">Until</label>
|
152
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MM-DD">
|
153
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" />
|
154
|
+
<span class="input-group-addon">
|
155
|
+
<span class="glyphicon glyphicon-calendar">
|
156
|
+
</span>
|
157
|
+
</span>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
HTML
|
161
|
+
|
162
|
+
assert_equal expected, @builder.datetime_picker(:until)
|
163
|
+
|
164
|
+
::BootstrapForm::Datetimepicker.format = old_config
|
165
|
+
end
|
166
|
+
|
167
|
+
test "configure global :datetimepicker_format" do
|
168
|
+
old_config = ::BootstrapForm::Datetimepicker.datetimepicker_format
|
169
|
+
::BootstrapForm::Datetimepicker.datetimepicker_format = "YYYY-MM-DD"
|
170
|
+
|
171
|
+
expected = <<-HTML.gsub(/ *\n */, "")
|
172
|
+
<div class="form-group">
|
173
|
+
<label class="control-label" for="schedule_until">Until</label>
|
174
|
+
<div class="bootstrap_form-datetimepicker input-group date" data-date-format="YYYY-MM-DD">
|
175
|
+
<input class="form-control" id="schedule_until" name="schedule[until]" type="text" />
|
176
|
+
<span class="input-group-addon">
|
177
|
+
<span class="glyphicon glyphicon-calendar">
|
178
|
+
</span>
|
179
|
+
</span>
|
180
|
+
</div>
|
181
|
+
</div>
|
182
|
+
HTML
|
183
|
+
|
184
|
+
assert_equal expected, @builder.datetime_picker(:until)
|
185
|
+
|
186
|
+
::BootstrapForm::Datetimepicker.datetimepicker_format = old_config
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "action_controller/railtie"
|
3
|
+
require "action_view/railtie"
|
4
|
+
|
5
|
+
# config
|
6
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
7
|
+
|
8
|
+
module FakeApp
|
9
|
+
class Application < Rails::Application
|
10
|
+
config.secret_token = "All I've got to do is to bring my board."
|
11
|
+
config.session_store :cookie_store, :key => "_fake_app_session"
|
12
|
+
config.active_support.deprecation = :log
|
13
|
+
config.eager_load = false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
FakeApp::Application.initialize!
|
17
|
+
|
18
|
+
# routes
|
19
|
+
FakeApp::Application.routes.draw do
|
20
|
+
resources :schedules, :only => [:new]
|
21
|
+
end
|
22
|
+
|
23
|
+
# models
|
24
|
+
class Schedule < ActiveRecord::Base
|
25
|
+
end
|
26
|
+
|
27
|
+
# helpers
|
28
|
+
module ApplicationHelper; end
|
29
|
+
|
30
|
+
# controllers
|
31
|
+
class ApplicationController < ActionController::Base
|
32
|
+
self.append_view_path File.dirname(__FILE__)
|
33
|
+
end
|
34
|
+
|
35
|
+
# migrations
|
36
|
+
class CreateAllTables < ActiveRecord::Migration
|
37
|
+
def self.up
|
38
|
+
suppress_messages do
|
39
|
+
create_table(:schedules) { |t| t.datetime :until }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.expand_path("..", __FILE__))
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] = "test"
|
5
|
+
|
6
|
+
require "rails"
|
7
|
+
require "fake_app/fake_app"
|
8
|
+
require "rails/test_help"
|
9
|
+
|
10
|
+
require "bootstrap_form-datetimepicker"
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bootstrap_form-datetimepicker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masato Ikeda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bootstrap_form
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: bootstrap_form add-on to embed bootstrap-datetimepicker simply.
|
56
|
+
email:
|
57
|
+
- masato.ikeda@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bootstrap_form-datetimepicker.gemspec
|
70
|
+
- lib/bootstrap_form-datetimepicker.rb
|
71
|
+
- lib/bootstrap_form/datetimepicker.rb
|
72
|
+
- lib/bootstrap_form/datetimepicker/version.rb
|
73
|
+
- test/bootstrap_form/datetimepicker_test.rb
|
74
|
+
- test/fake_app/fake_app.rb
|
75
|
+
- test/test_helper.rb
|
76
|
+
homepage: https://github.com/a2ikm/bootstrap_form-datetimepicker
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.2.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: bootstrap_form add-on to embed bootstrap-datetimepicker simply.
|
100
|
+
test_files:
|
101
|
+
- test/bootstrap_form/datetimepicker_test.rb
|
102
|
+
- test/fake_app/fake_app.rb
|
103
|
+
- test/test_helper.rb
|
104
|
+
has_rdoc:
|