time_wrapper 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/time_wrapper.rb +24 -17
- data/lib/time_wrapper/locale/da.yml +4 -0
- data/lib/time_wrapper/locale/en.yml +4 -0
- data/lib/time_wrapper/orm/active_record.rb +6 -0
- data/lib/time_wrapper/time_attribute.rb +46 -0
- data/lib/time_wrapper/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5905e9ffebb39684dbabb6f6d47eb7b7819f3961
|
4
|
+
data.tar.gz: 340a0082a7cb53437aac82104289a9514cf19c2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9314b2ad7909c2ef8e1cd6b3460ddb38b13c01b618224ac8272aba3e23fd4f98d95ecdb4f63f6a335eddbdd139ae72d3fadeecb93c5a39316f63150e87e7b661
|
7
|
+
data.tar.gz: 4d47af8a5abf1aa3be86da665ef506277683133b5ef8a2c75f57384206886433cce3b3548811bc5e3766042be8f7dbd0cb727697765062ccf0d3dd0fffa97604
|
data/README.md
CHANGED
data/lib/time_wrapper.rb
CHANGED
@@ -1,26 +1,33 @@
|
|
1
1
|
require "time_wrapper/version"
|
2
2
|
|
3
|
+
require "time_wrapper/orm/active_record"
|
4
|
+
|
3
5
|
module TimeWrapper
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
module Rails
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
initializer 'time_wrapper.setup_simple_form' do
|
9
|
+
::SimpleForm.setup do |config|
|
10
|
+
config.wrappers :time, tag: 'div', class: 'form-group', error_class: 'has-danger' do |b|
|
11
|
+
b.use :html5
|
12
|
+
b.use :placeholder
|
13
|
+
b.use :label, class: 'form-control-label'
|
14
|
+
b.wrapper tag: 'div', class: 'input-group time timepicker' do |input|
|
15
|
+
input.use :input, class: 'form-control', autocomplete: :off
|
16
|
+
input.wrapper tag: 'span', class: 'input-group-addon' do |addon|
|
17
|
+
addon.wrapper tag: 'i', class: "fa fa-clock-o" do |_|
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
b.use :error, wrap_with: { tag: 'small', class: 'text-help text-muted' }
|
22
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'text-help text-muted' }
|
13
23
|
end
|
14
24
|
end
|
15
25
|
end
|
16
|
-
b.use :error, wrap_with: { tag: 'small', class: 'text-help text-muted' }
|
17
|
-
b.use :hint, wrap_with: { tag: 'p', class: 'text-help text-muted' }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module Rails
|
22
|
-
class Engine < ::Rails::Engine
|
23
|
-
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
30
|
+
ActiveSupport.on_load(:i18n) do
|
31
|
+
I18n.load_path << "#{File.dirname(__FILE__)}/time_wrapper/locale/en.yml"
|
32
|
+
I18n.load_path << "#{File.dirname(__FILE__)}/time_wrapper/locale/da.yml"
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module TimeWrapper
|
2
|
+
module TimeAttribute
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def time_attribute(*options)
|
6
|
+
options.each do |attribute|
|
7
|
+
raise TypeError.new("'#{attribute}' is not of column-type datetime") unless columns.detect{|column| column.name == attribute.to_s}.type.to_s == 'datetime'
|
8
|
+
|
9
|
+
include ClassMethods
|
10
|
+
|
11
|
+
define_method "#{attribute}=" do |value| set_time_wrapper_attribute(attribute,value) end
|
12
|
+
define_method attribute do get_time_wrapper_attribute(attribute) end
|
13
|
+
define_method "#{attribute}_time_wrapper_validation" do validate_time_wrapper_attribute(attribute) end
|
14
|
+
|
15
|
+
validate "#{attribute}_time_wrapper_validation".to_sym
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
def set_time_wrapper_attribute(attribute,value)
|
21
|
+
begin
|
22
|
+
if value.kind_of? Time
|
23
|
+
self[attribute] = value.utc
|
24
|
+
else
|
25
|
+
self[attribute] = Time.zone.parse(value)
|
26
|
+
end
|
27
|
+
rescue ArgumentError, NoMethodError
|
28
|
+
instance_variable_set("@#{attribute}_time_wrapper_validation", true)
|
29
|
+
instance_variable_set("@#{attribute}_wrong_value", value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_time_wrapper_attribute(attribute)
|
34
|
+
if instance_variable_get("@#{attribute}_time_wrapper_validation")
|
35
|
+
instance_variable_get("@#{attribute}_wrong_value")
|
36
|
+
else
|
37
|
+
Time.current.change({hour: self[attribute].hour, min: self[attribute].min}) if self[attribute]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate_time_wrapper_attribute(attribute)
|
42
|
+
errors.add(attribute,:wrong_time_format) unless send(attribute).blank? if instance_variable_get("@#{attribute}_time_wrapper_validation")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/time_wrapper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thies Pierdola
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: font-awesome-rails
|
@@ -144,6 +144,10 @@ files:
|
|
144
144
|
- lib/generators/time_wrapper/javascripts_generator.rb
|
145
145
|
- lib/generators/time_wrapper/stylesheets_generator.rb
|
146
146
|
- lib/time_wrapper.rb
|
147
|
+
- lib/time_wrapper/locale/da.yml
|
148
|
+
- lib/time_wrapper/locale/en.yml
|
149
|
+
- lib/time_wrapper/orm/active_record.rb
|
150
|
+
- lib/time_wrapper/time_attribute.rb
|
147
151
|
- lib/time_wrapper/version.rb
|
148
152
|
- time_wrapper.gemspec
|
149
153
|
homepage: https://github.com/thiesp/time-picker-for-simple-form
|