time_wrapper 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c4efa02a759bb9e733f3926e8ceb09af6583ca8
4
- data.tar.gz: 6ab5eb4acb35cad1edeb4e838bf465dda132f401
3
+ metadata.gz: 5905e9ffebb39684dbabb6f6d47eb7b7819f3961
4
+ data.tar.gz: 340a0082a7cb53437aac82104289a9514cf19c2d
5
5
  SHA512:
6
- metadata.gz: f50472000d822eccea76977f3ac25ea921c83940e7a69da6f38485112fab190695b640262fe3143e52e434e44362a5fd3ba286e223e2e04b7dc5e79bba7afbbf
7
- data.tar.gz: 32dd5b41270fb88e6b4be411af2a882fb87ccf268e2ccd7102bf809fdf1a6861d3fe20dc8c949efcdf63f4bd46304e954ed8c3cdef3e2743e38b937bd8f1a474
6
+ metadata.gz: 9314b2ad7909c2ef8e1cd6b3460ddb38b13c01b618224ac8272aba3e23fd4f98d95ecdb4f63f6a335eddbdd139ae72d3fadeecb93c5a39316f63150e87e7b661
7
+ data.tar.gz: 4d47af8a5abf1aa3be86da665ef506277683133b5ef8a2c75f57384206886433cce3b3548811bc5e3766042be8f7dbd0cb727697765062ccf0d3dd0fffa97604
data/README.md CHANGED
@@ -17,6 +17,12 @@ And then execute:
17
17
  Or install it yourself as:
18
18
 
19
19
  $ gem install time_wrapper
20
+
21
+ ### Setup dependencies
22
+ * bootstrap
23
+ * momentjs-rails
24
+ * font-awesome-rails
25
+ * simple_form
20
26
 
21
27
  ### In application.scss
22
28
 
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
- ::SimpleForm.setup do |config|
5
- config.wrappers :time, tag: 'div', class: 'form-group', error_class: 'has-danger' do |b|
6
- b.use :html5
7
- b.use :placeholder
8
- b.use :label, class: 'form-control-label'
9
- b.wrapper tag: 'div', class: 'input-group time timepicker' do |input|
10
- input.use :input, class: 'form-control', autocomplete: :off
11
- input.wrapper tag: 'span', class: 'input-group-addon' do |addon|
12
- addon.wrapper tag: 'i', class: "fa fa-clock-o" do |_|
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,4 @@
1
+ da:
2
+ errors:
3
+ messages:
4
+ wrong_time_format: forkert tidsformat
@@ -0,0 +1,4 @@
1
+ en:
2
+ errors:
3
+ messages:
4
+ wrong_time_format: wrong time format
@@ -0,0 +1,6 @@
1
+ require 'orm_adapter/adapters/active_record'
2
+ require 'time_wrapper/time_attribute'
3
+
4
+ ActiveSupport.on_load(:active_record) do
5
+ extend TimeWrapper::TimeAttribute
6
+ 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
@@ -1,3 +1,3 @@
1
1
  module TimeWrapper
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-10 00:00:00.000000000 Z
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