formatic 0.1.4 → 0.1.5
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/app/assets/stylesheets/formatic/components/time.sass +15 -0
- data/app/assets/stylesheets/formatic/index.sass +1 -0
- data/app/components/formatic/date.rb +1 -1
- data/app/components/formatic/time.rb +87 -0
- data/lib/formatic/engine.rb +1 -0
- data/lib/formatic/templates/date.rb +31 -29
- data/lib/formatic/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb6984b1bcf7834695c46f425ad5509875e0b229883c660d267fc9c341ec268
|
4
|
+
data.tar.gz: ef9149dc91f5c04c9529b032f54af58eeaa1dfb006adc52febe7cf5f880f8871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10744bf1137b25a36d2a3503b86618ed4116554647bb66616d5f300ec0b0e023a9fd5e7e73d8e92eb0a0587645861170ef29021e77982343821a75c5af5ae74b
|
7
|
+
data.tar.gz: 532356801b253199ccf7a4e003f80e07926dc83c48555a69d6d1c79ed0984482664b1819b745afb097c6c4a3f4a07931342dd7b7e1c1037912ff0d83b4fa440e
|
@@ -0,0 +1,15 @@
|
|
1
|
+
@use "sass:color"
|
2
|
+
@use "iglu/spacing"
|
3
|
+
@use "formatic/tools/mandatory"
|
4
|
+
|
5
|
+
.c-formatic-time
|
6
|
+
|
7
|
+
&__inputs
|
8
|
+
display: grid
|
9
|
+
grid-auto-flow: column
|
10
|
+
grid-gap: 0.5em
|
11
|
+
+spacing.margin-bottom--small
|
12
|
+
|
13
|
+
&__select
|
14
|
+
.c-formatic-wrapper.is-required &
|
15
|
+
+mandatory.indicator
|
@@ -77,7 +77,7 @@ module Formatic
|
|
77
77
|
"#{f.object.model_name.param_key}_#{attribute_name}_1i"
|
78
78
|
end
|
79
79
|
|
80
|
-
def calendar(now: Time.current)
|
80
|
+
def calendar(now: ::Time.current)
|
81
81
|
from = 5.days.ago.to_date
|
82
82
|
till = now.beginning_of_month.advance(months: 2).end_of_month.to_date
|
83
83
|
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'formatic/templates/date'
|
4
|
+
|
5
|
+
module Formatic
|
6
|
+
# Date/calendar
|
7
|
+
class Time < ::Formatic::Base
|
8
|
+
option :minute_step, default: -> { 5 }
|
9
|
+
|
10
|
+
erb_template <<~ERB
|
11
|
+
<%= render wrapper do |wrap| -%>
|
12
|
+
|
13
|
+
<% wrap.with_input do -%>
|
14
|
+
<div class="c-formatic-time s-formatic">
|
15
|
+
|
16
|
+
<% if readonly %>
|
17
|
+
<div class="s-markdown">
|
18
|
+
<p>
|
19
|
+
<%= value.to_fs(:time) %>
|
20
|
+
</p>
|
21
|
+
</div>
|
22
|
+
<% else %>
|
23
|
+
|
24
|
+
<div class="c-formatic-time__inputs">
|
25
|
+
<%= select_tag hour_attribute_name,
|
26
|
+
options_for_hour,
|
27
|
+
id: hour_input_id,
|
28
|
+
class: 'c-formatic-time__select' %>
|
29
|
+
|
30
|
+
<%= select_tag minute_attribute_name,
|
31
|
+
options_for_minute,
|
32
|
+
id: minute_input_id,
|
33
|
+
class: 'c-formatic-time__select' %>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<% end -%>
|
37
|
+
<% end -%>
|
38
|
+
<% end -%>
|
39
|
+
ERB
|
40
|
+
|
41
|
+
# Usually the time component is used below the date component (for a DateTime attribute).
|
42
|
+
# So, normally we don't want the label to be shown twice.
|
43
|
+
def label
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
def options_for_hour
|
48
|
+
options_for_select collection_for_hour, f.object.public_send(attribute_name)&.hour
|
49
|
+
end
|
50
|
+
|
51
|
+
def options_for_minute
|
52
|
+
options_for_select collection_for_minute, f.object.public_send(attribute_name)&.min
|
53
|
+
end
|
54
|
+
|
55
|
+
def hour_attribute_name
|
56
|
+
"#{f.object.model_name.param_key}[#{attribute_name}(4i)]"
|
57
|
+
end
|
58
|
+
|
59
|
+
def minute_attribute_name
|
60
|
+
"#{f.object.model_name.param_key}[#{attribute_name}(5i)]"
|
61
|
+
end
|
62
|
+
|
63
|
+
def hour_input_id
|
64
|
+
"#{f.object.model_name.param_key}_#{attribute_name}_4i"
|
65
|
+
end
|
66
|
+
|
67
|
+
def minute_input_id
|
68
|
+
"#{f.object.model_name.param_key}_#{attribute_name}_5i"
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def collection_for_hour
|
74
|
+
result = (0..23).map { [_1, _1] }
|
75
|
+
result.prepend([nil, nil]) if wrapper.optional?
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
def collection_for_minute
|
80
|
+
sanitized_minute_step = minute_step.clamp(1, 60)
|
81
|
+
steps = (0..59).step(sanitized_minute_step).to_a
|
82
|
+
result = steps.map { [_1, _1] }
|
83
|
+
result.prepend([nil, nil]) if wrapper.optional?
|
84
|
+
result
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/formatic/engine.rb
CHANGED
@@ -31,6 +31,7 @@ module Formatic
|
|
31
31
|
require_relative '../../app/components/formatic/string'
|
32
32
|
require_relative '../../app/components/formatic/stepper'
|
33
33
|
require_relative '../../app/components/formatic/textarea'
|
34
|
+
require_relative '../../app/components/formatic/time'
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -20,45 +20,47 @@ module Formatic
|
|
20
20
|
|
21
21
|
<div class="c-formatic-date__inputs">
|
22
22
|
<% if discard_day %>
|
23
|
-
|
23
|
+
<%= hidden_field_tag day_attribute_name, (day_value || 1) %>
|
24
24
|
<% else %>
|
25
25
|
<%= select_tag day_attribute_name,
|
26
26
|
options_for_day,
|
27
27
|
id: day_input_id,
|
28
28
|
class: 'c-formatic-date__select js-formatic-date__day' %>
|
29
|
+
<% end %>
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
<%= select_tag month_attribute_name,
|
32
|
+
options_for_month,
|
33
|
+
id: month_input_id,
|
34
|
+
class: 'c-formatic-date__select js-formatic-date__month' %>
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
<% end %>
|
36
|
+
<%= select_tag year_attribute_name,
|
37
|
+
options_for_year,
|
38
|
+
id: year_input_id,
|
39
|
+
class: 'c-formatic-date__select js-formatic-date__year' %>
|
40
40
|
</div>
|
41
|
-
|
42
|
-
<
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
X
|
48
|
-
</a>
|
49
|
-
<% calendar.each do |day| %>
|
50
|
-
<a class="c-formatic-date__flick <%= day.classes %> js-formatic-date__shortcut"
|
51
|
-
href='#'
|
52
|
-
data-day="<%= day.date.day %>"
|
53
|
-
data-month="<%= day.date.month %>"
|
54
|
-
data-year="<%= day.date.year %>"
|
41
|
+
<% unless discard_day %>
|
42
|
+
<div class="c-formatic-date__calendar">
|
43
|
+
<a class="c-formatic-date__flick c-formatic-date__clear js-formatic-date__shortcut" href="#"
|
44
|
+
data-day=""
|
45
|
+
data-month=""
|
46
|
+
data-year=""
|
55
47
|
>
|
56
|
-
|
57
|
-
<span class="c-formatic-date__calendar-month"><%= I18n.l(day.date, format: "%b") %></span>
|
58
|
-
<span class="c-formatic-date__calendar-year"><%= I18n.l(day.date, format: "%y") %></span>
|
48
|
+
X
|
59
49
|
</a>
|
60
|
-
|
61
|
-
|
50
|
+
<% calendar.each do |day| %>
|
51
|
+
<a class="c-formatic-date__flick <%= day.classes %> js-formatic-date__shortcut"
|
52
|
+
href='#'
|
53
|
+
data-day="<%= day.date.day %>"
|
54
|
+
data-month="<%= day.date.month %>"
|
55
|
+
data-year="<%= day.date.year %>"
|
56
|
+
>
|
57
|
+
<span class="c-formatic-date__calendar-day-number"><%= I18n.l(day.date, format: "%e").strip %></span>
|
58
|
+
<span class="c-formatic-date__calendar-month"><%= I18n.l(day.date, format: "%b") %></span>
|
59
|
+
<span class="c-formatic-date__calendar-year"><%= I18n.l(day.date, format: "%y") %></span>
|
60
|
+
</a>
|
61
|
+
<% end %>
|
62
|
+
</div>
|
63
|
+
<% end %>
|
62
64
|
<% end %>
|
63
65
|
|
64
66
|
</div>
|
data/lib/formatic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- halo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03
|
11
|
+
date: 2025-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- app/assets/stylesheets/formatic/components/stepper.sass
|
119
119
|
- app/assets/stylesheets/formatic/components/string.sass
|
120
120
|
- app/assets/stylesheets/formatic/components/textarea.sass
|
121
|
+
- app/assets/stylesheets/formatic/components/time.sass
|
121
122
|
- app/assets/stylesheets/formatic/components/toggle.sass
|
122
123
|
- app/assets/stylesheets/formatic/components/wrapper.sass
|
123
124
|
- app/assets/stylesheets/formatic/generics/flip.sass
|
@@ -138,6 +139,7 @@ files:
|
|
138
139
|
- app/components/formatic/stepper.rb
|
139
140
|
- app/components/formatic/string.rb
|
140
141
|
- app/components/formatic/textarea.rb
|
142
|
+
- app/components/formatic/time.rb
|
141
143
|
- app/components/formatic/toggle.rb
|
142
144
|
- app/components/formatic/wrapper.rb
|
143
145
|
- config/locales/formatic.de.yml
|