hellobase 0.1.6 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hellobase.rb +3 -31
- data/lib/hellobase/core_ext.rb +32 -0
- data/lib/hellobase/{array_access.rb → core_ext/array_access.rb} +0 -0
- data/lib/hellobase/{date_creation.rb → core_ext/date_creation.rb} +1 -1
- data/lib/hellobase/{datetime_creation.rb → core_ext/datetime_creation.rb} +7 -2
- data/lib/hellobase/{divide_by_zero.rb → core_ext/divide_by_zero.rb} +0 -0
- data/lib/hellobase/{duration_arithmetic.rb → core_ext/duration_arithmetic.rb} +0 -0
- data/lib/hellobase/{string_access.rb → core_ext/string_access.rb} +0 -0
- data/lib/hellobase/{time_creation.rb → core_ext/time_creation.rb} +1 -1
- data/lib/hellobase/formtastic.rb +7 -0
- data/lib/hellobase/formtastic/content_input.rb +8 -0
- data/lib/hellobase/formtastic/datepicker_with_time_input.rb +81 -0
- data/lib/hellobase/formtastic/inline_checkbox_input.rb +9 -0
- data/lib/hellobase/formtastic/time_of_day_input.rb +19 -0
- data/lib/hellobase/time_zones.rb +13 -0
- data/lib/hellobase/version.rb +1 -1
- metadata +92 -17
- data/lib/hellobase/duration_creation.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58d94618d33b35eb07fa61f5a1ec5dbffaf39184dd15ba53b952864ff87bc50a
|
4
|
+
data.tar.gz: 26ab6624cbf12e1a09e31e2e9959130f91ebf6ee4f4c237ded77d6daecfcd585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a94d80712b33120f7697250b4efc2410c0669ae612f87c70fbf383f69f7026635f9ef1914b4c0943416c67cc33132532f520d5f99113e7cf9e388ca31000cd15
|
7
|
+
data.tar.gz: a025c3bc76d3b544300087e2cfb5c2aa4c5c40ac8d0d84f7b65926f18568f899e6c5cc4d65956c0ad2cb1c0d8596b2a97d1c0ca58d0cbc47830e920f3b7e37b1
|
data/lib/hellobase.rb
CHANGED
@@ -1,34 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require 'active_support/core_ext/time'
|
5
|
-
require 'active_support/duration'
|
6
|
-
require 'tod'
|
7
|
-
|
8
|
-
require 'hellobase/array_access'
|
9
|
-
require 'hellobase/date_creation'
|
10
|
-
require 'hellobase/datetime_creation'
|
11
|
-
require 'hellobase/divide_by_zero'
|
12
|
-
require 'hellobase/duration_arithmetic'
|
13
|
-
require 'hellobase/duration_creation'
|
14
|
-
require 'hellobase/string_access'
|
15
|
-
require 'hellobase/time_creation'
|
1
|
+
require 'hellobase/core_ext'
|
2
|
+
require 'hellobase/formtastic'
|
3
|
+
require 'hellobase/time_zones'
|
16
4
|
|
17
5
|
module Hellobase
|
18
|
-
DATE_FORMAT = /^\d{4}-\d{2}-\d{2}$/
|
19
|
-
TIME_FORMAT = /^\d{2}:\d{2}:\d{2}$/
|
20
|
-
DATETIME_FORMAT = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC$/
|
21
|
-
DURATION_FORMAT = /^P-?\d+Y-?\d+M-?\d+DT-?\d+H-?\d+M-?\d+S$/
|
22
|
-
|
23
|
-
class Error < StandardError
|
24
|
-
attr_reader :type, :object
|
25
|
-
|
26
|
-
def initialize(type, object, *args)
|
27
|
-
@type = type
|
28
|
-
@object = object
|
29
|
-
@args = args
|
30
|
-
|
31
|
-
super "#{type}: #{object.inspect}, #{args.inspect}"
|
32
|
-
end
|
33
|
-
end
|
34
6
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
require 'date'
|
3
|
+
require 'active_support/core_ext/date'
|
4
|
+
require 'active_support/core_ext/time'
|
5
|
+
require 'active_support/duration'
|
6
|
+
require 'tod'
|
7
|
+
|
8
|
+
require 'hellobase/core_ext/array_access'
|
9
|
+
require 'hellobase/core_ext/date_creation'
|
10
|
+
require 'hellobase/core_ext/datetime_creation'
|
11
|
+
require 'hellobase/core_ext/divide_by_zero'
|
12
|
+
require 'hellobase/core_ext/duration_arithmetic'
|
13
|
+
require 'hellobase/core_ext/string_access'
|
14
|
+
require 'hellobase/core_ext/time_creation'
|
15
|
+
|
16
|
+
module Hellobase
|
17
|
+
DATE_FORMAT = /^\d{4}-\d{2}-\d{2}$/
|
18
|
+
TIME_FORMAT = /^\d{2}:\d{2}:\d{2}$/
|
19
|
+
DATETIME_FORMAT = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC$/
|
20
|
+
|
21
|
+
class Error < StandardError
|
22
|
+
attr_reader :type, :object
|
23
|
+
|
24
|
+
def initialize(type, object, *args)
|
25
|
+
@type = type
|
26
|
+
@object = object
|
27
|
+
@args = args
|
28
|
+
|
29
|
+
super "#{type}: #{object.inspect}, #{args.inspect}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Date.singleton_class.prepend(
|
2
2
|
Module.new do
|
3
3
|
def parse(string)
|
4
|
-
raise Hellobase::Error.new(:date_format, nil, string) unless string =~ Hellobase::DATE_FORMAT
|
4
|
+
raise Hellobase::Error.new(:date_format, nil, string) unless (string =~ Hellobase::DATE_FORMAT) || string.blank?
|
5
5
|
|
6
6
|
begin
|
7
7
|
super
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Time.singleton_class.prepend(
|
2
2
|
Module.new do
|
3
3
|
def parse(string)
|
4
|
-
raise Hellobase::Error.new(:datetime_format, nil, string) unless string =~ Hellobase::DATETIME_FORMAT
|
4
|
+
raise Hellobase::Error.new(:datetime_format, nil, string) unless (string =~ Hellobase::DATETIME_FORMAT) || string.blank?
|
5
5
|
|
6
6
|
begin
|
7
7
|
super
|
@@ -19,7 +19,12 @@ Time.singleton_class.prepend(
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def new(*args)
|
22
|
-
|
22
|
+
# only allow ActiveSupport::TimeZone to use Time.new
|
23
|
+
unless caller_locations(1, 1)[0].path.end_with? 'active_support/values/time_zone.rb'
|
24
|
+
raise Hellobase::Error.new(:datetime_new, nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
super
|
23
28
|
end
|
24
29
|
end
|
25
30
|
)
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Tod::TimeOfDay.singleton_class.prepend(
|
2
2
|
Module.new do
|
3
3
|
def parse(string)
|
4
|
-
raise Hellobase::Error.new(:time_format, nil, string) unless string =~ Hellobase::TIME_FORMAT
|
4
|
+
raise Hellobase::Error.new(:time_format, nil, string) unless (string =~ Hellobase::TIME_FORMAT) || string.blank?
|
5
5
|
|
6
6
|
begin
|
7
7
|
super
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'active_support' # formtastic needs ActiveSupport::Autoload
|
2
|
+
require 'formtastic'
|
3
|
+
|
4
|
+
require 'hellobase/formtastic/content_input'
|
5
|
+
require 'hellobase/formtastic/datepicker_with_time_input'
|
6
|
+
require 'hellobase/formtastic/inline_checkbox_input'
|
7
|
+
require 'hellobase/formtastic/time_of_day_input'
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'active_admin/inputs'
|
2
|
+
|
3
|
+
class DatepickerWithTimeInput
|
4
|
+
include ::Formtastic::Inputs::Base
|
5
|
+
|
6
|
+
def self.virtual_attributes(attr)
|
7
|
+
[:"_dpwt_#{attr}_d", :"_dpwt_#{attr}_t"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.define_virtual_attributes(klass, attr)
|
11
|
+
return if klass.respond_to? :_dpwt_defined
|
12
|
+
|
13
|
+
klass.class_eval <<-RUBY
|
14
|
+
def self._dpwt_defined; end
|
15
|
+
|
16
|
+
def _dpwt_#{attr}_d
|
17
|
+
self.#{attr}&.strftime('%Y-%m-%d')
|
18
|
+
end
|
19
|
+
|
20
|
+
def _dpwt_#{attr}_t
|
21
|
+
self.#{attr}&.strftime('%R')
|
22
|
+
end
|
23
|
+
|
24
|
+
def _dpwt_#{attr}_d=(val)
|
25
|
+
@_dpwt_#{attr}_d = val
|
26
|
+
_dpwt_set_#{attr}
|
27
|
+
|
28
|
+
val
|
29
|
+
end
|
30
|
+
|
31
|
+
def _dpwt_#{attr}_t=(val)
|
32
|
+
@_dpwt_#{attr}_t = val
|
33
|
+
_dpwt_set_#{attr}
|
34
|
+
|
35
|
+
val
|
36
|
+
end
|
37
|
+
|
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(' ')
|
42
|
+
end
|
43
|
+
RUBY
|
44
|
+
end
|
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
|
+
|
64
|
+
def datepicker_options
|
65
|
+
{
|
66
|
+
label: label_text,
|
67
|
+
}.merge(options[:datepicker_options] || {})
|
68
|
+
end
|
69
|
+
|
70
|
+
def time_select_options
|
71
|
+
{
|
72
|
+
label: false,
|
73
|
+
collection: (0..23).map {|h| (0..59).select {|m| m % 5 == 0 }.map {|m| ['%02i' % h, '%02i' % m].join(':') } }.flatten,
|
74
|
+
}.merge(options[:time_select_options] || {})
|
75
|
+
end
|
76
|
+
|
77
|
+
# formtastic inputs generate <li> with no way to override
|
78
|
+
def replace_li_tag(html)
|
79
|
+
html.strip.sub(/^<li /, '<span ').sub(/<\/li>$/, '</span>').html_safe
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class TimeOfDayInput < ::Formtastic::Inputs::SelectInput
|
2
|
+
def initialize(*)
|
3
|
+
super
|
4
|
+
|
5
|
+
@options[:collection] ||= build_times_collection
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def build_times_collection
|
11
|
+
hours = 0..23
|
12
|
+
minutes = (0..59).select {|m| m % 5 == 0 }
|
13
|
+
seconds = (0..59).select {|m| m % 60 == 0 }
|
14
|
+
times = hours.map {|h| minutes.map {|m| seconds.map {|s| Tod::TimeOfDay.new(h, m, s) } } }.flatten
|
15
|
+
|
16
|
+
format = '%I:%M %p'
|
17
|
+
times.map {|t| [t.strftime(format), t.to_s] }
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'tzinfo'
|
2
|
+
|
3
|
+
module Hellobase
|
4
|
+
class << self
|
5
|
+
def domestic_time_zone_select_values(country_code)
|
6
|
+
TZInfo::Country.get(country_code).zone_info.map {|z| [z.description || z.timezone.friendly_identifier(true), z.identifier] }
|
7
|
+
end
|
8
|
+
|
9
|
+
def foreign_time_zone_select_values(country_code)
|
10
|
+
TZInfo::Country.all.reject {|c| c.code == country_code }.map(&:zone_info).flatten.uniq.map {|z| [z.description || z.timezone.friendly_identifier(false), z.identifier] }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/hellobase/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hellobase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Wang
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activeadmin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: activesupport
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,48 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '2.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activemodel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '6.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '6.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '6.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '6.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: actionview
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '6.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '6.0'
|
41
97
|
- !ruby/object:Gem::Dependency
|
42
98
|
name: minitest
|
43
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +114,20 @@ dependencies:
|
|
58
114
|
- - "<"
|
59
115
|
- !ruby/object:Gem::Version
|
60
116
|
version: '5.14'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: nokogiri
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '1.10'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '1.10'
|
61
131
|
- !ruby/object:Gem::Dependency
|
62
132
|
name: warning
|
63
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +142,7 @@ dependencies:
|
|
72
142
|
- - "~>"
|
73
143
|
- !ruby/object:Gem::Version
|
74
144
|
version: '1.0'
|
75
|
-
description:
|
145
|
+
description:
|
76
146
|
email:
|
77
147
|
- awang@hellobase.com
|
78
148
|
executables: []
|
@@ -81,19 +151,25 @@ extra_rdoc_files: []
|
|
81
151
|
files:
|
82
152
|
- MIT-LICENSE
|
83
153
|
- lib/hellobase.rb
|
84
|
-
- lib/hellobase/
|
85
|
-
- lib/hellobase/
|
86
|
-
- lib/hellobase/
|
87
|
-
- lib/hellobase/
|
88
|
-
- lib/hellobase/
|
89
|
-
- lib/hellobase/
|
90
|
-
- lib/hellobase/string_access.rb
|
91
|
-
- lib/hellobase/time_creation.rb
|
154
|
+
- lib/hellobase/core_ext.rb
|
155
|
+
- lib/hellobase/core_ext/array_access.rb
|
156
|
+
- lib/hellobase/core_ext/date_creation.rb
|
157
|
+
- lib/hellobase/core_ext/datetime_creation.rb
|
158
|
+
- lib/hellobase/core_ext/divide_by_zero.rb
|
159
|
+
- lib/hellobase/core_ext/duration_arithmetic.rb
|
160
|
+
- lib/hellobase/core_ext/string_access.rb
|
161
|
+
- lib/hellobase/core_ext/time_creation.rb
|
162
|
+
- lib/hellobase/formtastic.rb
|
163
|
+
- lib/hellobase/formtastic/content_input.rb
|
164
|
+
- lib/hellobase/formtastic/datepicker_with_time_input.rb
|
165
|
+
- lib/hellobase/formtastic/inline_checkbox_input.rb
|
166
|
+
- lib/hellobase/formtastic/time_of_day_input.rb
|
167
|
+
- lib/hellobase/time_zones.rb
|
92
168
|
- lib/hellobase/version.rb
|
93
|
-
homepage:
|
169
|
+
homepage:
|
94
170
|
licenses: []
|
95
171
|
metadata: {}
|
96
|
-
post_install_message:
|
172
|
+
post_install_message:
|
97
173
|
rdoc_options: []
|
98
174
|
require_paths:
|
99
175
|
- lib
|
@@ -108,9 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
184
|
- !ruby/object:Gem::Version
|
109
185
|
version: '0'
|
110
186
|
requirements: []
|
111
|
-
|
112
|
-
|
113
|
-
signing_key:
|
187
|
+
rubygems_version: 3.1.4
|
188
|
+
signing_key:
|
114
189
|
specification_version: 4
|
115
190
|
summary: Ruby runtime environment for Hellobase
|
116
191
|
test_files: []
|