semantic_date_time_tags 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/semantic_date_time_tags/format_parser.rb +1 -1
- data/lib/semantic_date_time_tags/tag/date_range.rb +7 -0
- data/lib/semantic_date_time_tags/tag.rb +9 -0
- data/lib/semantic_date_time_tags/version.rb +1 -1
- data/test/semantic_date_time_tags/format_parser_test.rb +9 -0
- data/test/semantic_date_time_tags/view_helpers_test.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb0316eee2d0502118793403d13455ac95df6d4f
|
4
|
+
data.tar.gz: c57428b1211df6fc793f41e128af35e41c317c45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8e01cc7bd515255cd49e7aba68401eb07faa69200c64269cf88834a271e60a5d6edea6a7c9d3aec4d7178a2a9c785d61c4082f92277a673647a88bed1387eae
|
7
|
+
data.tar.gz: b59754e7a9f8174a7903fa37d76e9248d6d8d14ba77a0413e526dc23a04dd43fb5b3c715ca263a2d332f6c5b7e63db237051a4e2badc6d142eae22e02ebd6162
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
semantic_date_time_tags (0.1.
|
4
|
+
semantic_date_time_tags (0.1.5)
|
5
5
|
rails (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -76,7 +76,7 @@ GEM
|
|
76
76
|
domain_name (~> 0.5)
|
77
77
|
i18n (0.7.0)
|
78
78
|
json (1.8.3)
|
79
|
-
listen (3.0.
|
79
|
+
listen (3.0.4)
|
80
80
|
rb-fsevent (>= 0.9.3)
|
81
81
|
rb-inotify (>= 0.9)
|
82
82
|
loofah (2.0.3)
|
@@ -41,7 +41,7 @@ module SemanticDateTimeTags
|
|
41
41
|
when /%-?[aAdej]/ then ['day', comp[/\w/]]
|
42
42
|
when /%-?[HKIl]/ then ['hours', comp[/\w/]]
|
43
43
|
when /%-?[M]/ then ['minutes', comp[/\w/]]
|
44
|
-
when /%-?[
|
44
|
+
when /%-?[pP]/ then ['ampm', comp[/\w/]]
|
45
45
|
when /\W+/ then ['sep']
|
46
46
|
end
|
47
47
|
end
|
@@ -40,6 +40,12 @@ module SemanticDateTimeTags
|
|
40
40
|
date_from.year == ::Date.today.year
|
41
41
|
end
|
42
42
|
|
43
|
+
def same_meridian?
|
44
|
+
return false unless same_day?
|
45
|
+
(date_from.to_time.hour < 12 && date_to.to_time.hour < 12) ||
|
46
|
+
(date_from.to_time.hour >= 12 && date_to.to_time.hour >= 12)
|
47
|
+
end
|
48
|
+
|
43
49
|
# ---------------------------------------------------------------------
|
44
50
|
|
45
51
|
def dom_classes
|
@@ -51,6 +57,7 @@ module SemanticDateTimeTags
|
|
51
57
|
res << 'more_than_a_week' unless within_a_week?
|
52
58
|
res << 'same_day' if same_day?
|
53
59
|
res << 'same_time' if same_time?
|
60
|
+
res << 'same_meridian' if same_meridian?
|
54
61
|
res
|
55
62
|
end
|
56
63
|
|
@@ -29,6 +29,7 @@ module SemanticDateTimeTags
|
|
29
29
|
def dom_classes
|
30
30
|
[
|
31
31
|
'semantic',
|
32
|
+
am_pm_class,
|
32
33
|
type_class,
|
33
34
|
current_date_class,
|
34
35
|
current_year_class,
|
@@ -74,6 +75,14 @@ module SemanticDateTimeTags
|
|
74
75
|
'midnight' if obj == obj.midnight
|
75
76
|
end
|
76
77
|
|
78
|
+
def am_pm_class
|
79
|
+
return unless [::Time,::DateTime].any?{ |c| obj.instance_of? c }
|
80
|
+
case
|
81
|
+
when (0..11).include?(obj.hour) then 'am'
|
82
|
+
else 'pm'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
77
86
|
# ---------------------------------------------------------------------
|
78
87
|
|
79
88
|
def dom_data
|
@@ -52,5 +52,14 @@ describe SemanticDateTimeTags::FormatParser do
|
|
52
52
|
to_html.must_equal '<span class="day A">Saturday</span><span class="sep"> </span><span class="day d">12</span><span class="sep"> / </span><span class="month m">12</span><span class="sep"> / </span><span class="year Y">2014</span>'
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
describe '%-l:%M %P' do
|
57
|
+
let(:format) { '%-l:%M %P' }
|
58
|
+
let(:string) { '12:30 am' }
|
59
|
+
|
60
|
+
it 'marks up the am/pm' do
|
61
|
+
to_html.must_include '<span class="ampm P">'
|
62
|
+
end
|
63
|
+
end
|
55
64
|
end
|
56
65
|
end
|
@@ -17,6 +17,8 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
17
17
|
let(:time_object_noon) { Time.new(2015, 11, 3, 12, 00) }
|
18
18
|
let(:time_object_whole_hour) { Time.new(2014, 8, 21, 15) }
|
19
19
|
let(:time_object_whole_minute) { Time.new(2014, 8, 21, 15, 30) }
|
20
|
+
let(:time_object_before_noon) { Time.new(2014, 8, 21, 11, 00) }
|
21
|
+
let(:time_object_after_noon) { Time.new(2014, 8, 21, 12, 01) }
|
20
22
|
|
21
23
|
|
22
24
|
it 'does not work with a date object' do
|
@@ -59,6 +61,14 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
59
61
|
semantic_time_tag(time_object_midnight).must_match /\A<time.+?midnight.+?<\/time>\z/
|
60
62
|
end
|
61
63
|
|
64
|
+
it 'adds am class if time is before noon' do
|
65
|
+
semantic_time_tag(time_object_before_noon).must_match /\A<time.+?am.+?<\/time>\z/
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'adds pm class if time is after noon' do
|
69
|
+
semantic_time_tag(time_object_after_noon).must_match /\A<time.+?pm.+?<\/time>\z/
|
70
|
+
end
|
71
|
+
|
62
72
|
|
63
73
|
it 'adds noon as data-in-words if time is noon' do
|
64
74
|
semantic_time_tag(time_object_noon).must_match /\A<time.+?data-in-words=\"noon\".+?<\/time>\z/
|
@@ -153,6 +163,8 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
153
163
|
let(:date_time_object_from) { DateTime.parse('31/10/2015') }
|
154
164
|
let(:date_time_object_to) { DateTime.parse('11/11/2015') }
|
155
165
|
|
166
|
+
let(:date_time_object_from_morning) { DateTime.parse('7/11/2015 8:00') }
|
167
|
+
|
156
168
|
it 'returns the from date wrapped correctly' do
|
157
169
|
semantic_date_range_tag(date_object, date_tomorrow_object).must_match /<time.+?semantic.+?date.+?from.+?>.+?<time.+?semantic.+?date.+?to.+?>/
|
158
170
|
end
|
@@ -169,6 +181,10 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
169
181
|
semantic_date_range_tag(date_time_object_from, date_time_object_from).must_match /\A<span.+?date_range.+?same_day.+?same_time.+?>/
|
170
182
|
end
|
171
183
|
|
184
|
+
it 'adds am to wrapping span if both times in morning' do
|
185
|
+
semantic_date_range_tag(date_time_object_from_morning, date_time_object_from_morning+1.hour).must_match /\A<span.+?date_range.+?same_meridian.+?>/
|
186
|
+
end
|
187
|
+
|
172
188
|
it 'accepts datetime objects' do
|
173
189
|
semantic_date_range_tag(date_time_object_from, date_time_object_to).must_match /<time.+?from.+?<\/time>/
|
174
190
|
semantic_date_range_tag(date_time_object_from, date_time_object_to).must_match /<time.+?to.+?<\/time>/
|
@@ -178,6 +194,7 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
178
194
|
semantic_date_time_range_tag(date_object, date_tomorrow_object).must_match /<time.+?semantic.+?date.+?from.+?>/
|
179
195
|
end
|
180
196
|
|
197
|
+
|
181
198
|
it 'allows to pass :format' do
|
182
199
|
semantic_date_time_range_tag(date_object, date_tomorrow_object, format: :test).must_include '~'
|
183
200
|
end
|