hellobase 0.1.10 → 0.1.11

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
  SHA256:
3
- metadata.gz: 3c5e628aa228c5ccc17184aa096c4b13207afa0d9971e7f3a70c9022273ba51e
4
- data.tar.gz: 91b1dd1327d4ba48a855afcc6cb4accccee0c9503a11518ed330da314d59441a
3
+ metadata.gz: 58d94618d33b35eb07fa61f5a1ec5dbffaf39184dd15ba53b952864ff87bc50a
4
+ data.tar.gz: 26ab6624cbf12e1a09e31e2e9959130f91ebf6ee4f4c237ded77d6daecfcd585
5
5
  SHA512:
6
- metadata.gz: ce2d8fbb8bdff6be2e47b3d9ac12950f1c2cc0c887d51595cfa22ec890b13931218eadeb6c12844cae7a52ad3a817cfb45d1a1747cfb6360119b77a2c12c8705
7
- data.tar.gz: 0f5e821adf40ecb6eeac769f0016fec799cf9578aa638bb9d8558e71cc37721f1a6e3f22327ddba778e682c46c2990e058cfff7719f1b60455bc7fee588e902c
6
+ metadata.gz: a94d80712b33120f7697250b4efc2410c0669ae612f87c70fbf383f69f7026635f9ef1914b4c0943416c67cc33132532f520d5f99113e7cf9e388ca31000cd15
7
+ data.tar.gz: a025c3bc76d3b544300087e2cfb5c2aa4c5c40ac8d0d84f7b65926f18568f899e6c5cc4d65956c0ad2cb1c0d8596b2a97d1c0ca58d0cbc47830e920f3b7e37b1
@@ -3,54 +3,64 @@ require 'active_admin/inputs'
3
3
  class DatepickerWithTimeInput
4
4
  include ::Formtastic::Inputs::Base
5
5
 
6
- def to_html
7
- init_object
6
+ def self.virtual_attributes(attr)
7
+ [:"_dpwt_#{attr}_d", :"_dpwt_#{attr}_t"]
8
+ end
8
9
 
9
- datepicker_html = ActiveAdmin::Inputs::DatepickerInput.new(builder, template, object, object_name, "#{method}_date", datepicker_options).to_html
10
- time_select_html = Formtastic::Inputs::SelectInput.new(builder, template, object, object_name, "#{method}_time", time_select_options).to_html
11
- zone_hidden_html = Formtastic::Inputs::HiddenInput.new(builder, template, object, object_name, "#{method}_tz", {}).to_html
12
- value_hidden_html = Formtastic::Inputs::HiddenInput.new(builder, template, object, object_name, method, {}).to_html
13
- zone_span_html = template.content_tag(:span, time_zone)
10
+ def self.define_virtual_attributes(klass, attr)
11
+ return if klass.respond_to? :_dpwt_defined
14
12
 
15
- wrapper_contents = [
16
- replace_li_tag(datepicker_html),
17
- replace_li_tag(time_select_html),
18
- replace_li_tag(zone_hidden_html),
19
- replace_li_tag(value_hidden_html),
20
- zone_span_html,
21
- error_html,
22
- hint_html,
23
- ].compact.join("\n").html_safe
13
+ klass.class_eval <<-RUBY
14
+ def self._dpwt_defined; end
24
15
 
25
- template.content_tag(:li, wrapper_contents, wrapper_html_options)
26
- end
16
+ def _dpwt_#{attr}_d
17
+ self.#{attr}&.strftime('%Y-%m-%d')
18
+ end
27
19
 
28
- private
20
+ def _dpwt_#{attr}_t
21
+ self.#{attr}&.strftime('%R')
22
+ end
29
23
 
30
- def init_object
31
- if value = object.send(method)
32
- object.send "#{method}=", value.in_time_zone(time_zone)
33
- end
24
+ def _dpwt_#{attr}_d=(val)
25
+ @_dpwt_#{attr}_d = val
26
+ _dpwt_set_#{attr}
34
27
 
35
- object.class_eval <<-RUBY
36
- define_method(:#{method}_buffer) do
37
- @#{method}_v ||= #{method}&.in_time_zone('#{time_zone}')
28
+ val
38
29
  end
39
30
 
40
- define_method(:#{method}_tz) do
41
- #{method}_buffer&.strftime('%z') || '#{time_zone}'
42
- end
31
+ def _dpwt_#{attr}_t=(val)
32
+ @_dpwt_#{attr}_t = val
33
+ _dpwt_set_#{attr}
43
34
 
44
- define_method(:#{method}_date) do
45
- #{method}_buffer&.strftime('%Y-%m-%d')
35
+ val
46
36
  end
47
37
 
48
- define_method(:#{method}_time) do
49
- #{method}_buffer&.strftime('%R')
38
+ private
39
+
40
+ def _dpwt_set_#{attr}
41
+ self.#{attr} = @_dpwt_#{attr}_d.blank? || @_dpwt_#{attr}_t.blank? ? nil : [@_dpwt_#{attr}_d, @_dpwt_#{attr}_t].join(' ')
50
42
  end
51
43
  RUBY
52
44
  end
53
45
 
46
+ def to_html
47
+ datepicker_html = ActiveAdmin::Inputs::DatepickerInput.new(builder, template, object, object_name, :"_dpwt_#{method}_d", datepicker_options).to_html
48
+ time_select_html = Formtastic::Inputs::SelectInput.new(builder, template, object, object_name, :"_dpwt_#{method}_t", time_select_options).to_html
49
+ zone_display_html = options[:time_zone] ? template.content_tag(:span, options[:time_zone]) : nil
50
+
51
+ wrapper_contents = [
52
+ replace_li_tag(datepicker_html),
53
+ replace_li_tag(time_select_html),
54
+ zone_display_html,
55
+ error_html,
56
+ hint_html,
57
+ ].compact.join("\n").html_safe
58
+
59
+ template.content_tag(:li, wrapper_contents, wrapper_html_options)
60
+ end
61
+
62
+ private
63
+
54
64
  def datepicker_options
55
65
  {
56
66
  label: label_text,
@@ -64,10 +74,6 @@ class DatepickerWithTimeInput
64
74
  }.merge(options[:time_select_options] || {})
65
75
  end
66
76
 
67
- def time_zone
68
- options[:time_zone] || 'UTC'
69
- end
70
-
71
77
  # formtastic inputs generate <li> with no way to override
72
78
  def replace_li_tag(html)
73
79
  html.strip.sub(/^<li /, '<span ').sub(/<\/li>$/, '</span>').html_safe
@@ -1,3 +1,3 @@
1
1
  module Hellobase
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hellobase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Wang