semantic_date_time_tags 0.1.7 → 0.1.8
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/.travis.yml +2 -1
- data/Gemfile.lock +42 -40
- data/README.md +9 -1
- data/lib/assets/stylesheets/semantic_date_time_tags/default.scss +7 -0
- data/lib/assets/stylesheets/semantic_date_time_tags/partials/_mixins.scss +1 -0
- data/lib/assets/stylesheets/semantic_date_time_tags/partials/mixins/_date_range.scss +49 -0
- data/lib/assets/stylesheets/semantic_date_time_tags/partials/mixins/_date_time.scss +20 -0
- data/lib/assets/stylesheets/semantic_date_time_tags.css +4 -0
- data/lib/semantic_date_time_tags/format_parser.rb +4 -6
- data/lib/semantic_date_time_tags/tag/date.rb +1 -3
- data/lib/semantic_date_time_tags/tag/date_range.rb +7 -9
- data/lib/semantic_date_time_tags/tag/date_time.rb +2 -4
- data/lib/semantic_date_time_tags/tag/time.rb +1 -3
- data/lib/semantic_date_time_tags/tag.rb +13 -15
- data/lib/semantic_date_time_tags/version.rb +1 -1
- data/lib/semantic_date_time_tags/view_helpers.rb +6 -8
- data/lib/semantic_date_time_tags.rb +1 -1
- data/test/semantic_date_time_tags/view_helpers_test.rb +20 -34
- data/test/test_helper.rb +3 -3
- metadata +7 -3
- data/lib/assets/stylesheets/semantic_date_time_tags.css.scss +0 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 770b668d9784919dbff28f3cebadf264fdd83ef9
|
|
4
|
+
data.tar.gz: d2c46bb284fbf9977312c5724e366249d7939f62
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6287afc303c9d24a4b84e1c1525ce503025c1f88482fe3ae50ab7b798e61537b15a6580737d926e079ca3be9873906c0bfdb0765806cc13dc2de5c68e429017f
|
|
7
|
+
data.tar.gz: 3c3bf57fe98ac100da20c24c5e5dfe297932658f9d7e4c101293f87adfa06c21ed239e37d32dd3a77d7b2a257c86d42b3418e83b170452badc45e841abfc8344
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
semantic_date_time_tags (0.1.
|
|
4
|
+
semantic_date_time_tags (0.1.8)
|
|
5
5
|
rails (>= 3.0.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionmailer (4.2.
|
|
11
|
-
actionpack (= 4.2.
|
|
12
|
-
actionview (= 4.2.
|
|
13
|
-
activejob (= 4.2.
|
|
10
|
+
actionmailer (4.2.6)
|
|
11
|
+
actionpack (= 4.2.6)
|
|
12
|
+
actionview (= 4.2.6)
|
|
13
|
+
activejob (= 4.2.6)
|
|
14
14
|
mail (~> 2.5, >= 2.5.4)
|
|
15
15
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
16
|
-
actionpack (4.2.
|
|
17
|
-
actionview (= 4.2.
|
|
18
|
-
activesupport (= 4.2.
|
|
16
|
+
actionpack (4.2.6)
|
|
17
|
+
actionview (= 4.2.6)
|
|
18
|
+
activesupport (= 4.2.6)
|
|
19
19
|
rack (~> 1.6)
|
|
20
20
|
rack-test (~> 0.6.2)
|
|
21
21
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
22
22
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
23
|
-
actionview (4.2.
|
|
24
|
-
activesupport (= 4.2.
|
|
23
|
+
actionview (4.2.6)
|
|
24
|
+
activesupport (= 4.2.6)
|
|
25
25
|
builder (~> 3.1)
|
|
26
26
|
erubis (~> 2.7.0)
|
|
27
27
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
28
28
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
29
|
-
activejob (4.2.
|
|
30
|
-
activesupport (= 4.2.
|
|
29
|
+
activejob (4.2.6)
|
|
30
|
+
activesupport (= 4.2.6)
|
|
31
31
|
globalid (>= 0.3.0)
|
|
32
|
-
activemodel (4.2.
|
|
33
|
-
activesupport (= 4.2.
|
|
32
|
+
activemodel (4.2.6)
|
|
33
|
+
activesupport (= 4.2.6)
|
|
34
34
|
builder (~> 3.1)
|
|
35
|
-
activerecord (4.2.
|
|
36
|
-
activemodel (= 4.2.
|
|
37
|
-
activesupport (= 4.2.
|
|
35
|
+
activerecord (4.2.6)
|
|
36
|
+
activemodel (= 4.2.6)
|
|
37
|
+
activesupport (= 4.2.6)
|
|
38
38
|
arel (~> 6.0)
|
|
39
|
-
activesupport (4.2.
|
|
39
|
+
activesupport (4.2.6)
|
|
40
40
|
i18n (~> 0.7)
|
|
41
41
|
json (~> 1.7, >= 1.7.7)
|
|
42
42
|
minitest (~> 5.1)
|
|
@@ -45,6 +45,7 @@ GEM
|
|
|
45
45
|
arel (6.0.3)
|
|
46
46
|
builder (3.2.2)
|
|
47
47
|
coderay (1.1.0)
|
|
48
|
+
concurrent-ruby (1.0.1)
|
|
48
49
|
coveralls (0.8.3)
|
|
49
50
|
json (~> 1.8)
|
|
50
51
|
rest-client (>= 1.6.8, < 2)
|
|
@@ -86,12 +87,12 @@ GEM
|
|
|
86
87
|
mime-types (>= 1.16, < 3)
|
|
87
88
|
method_source (0.8.2)
|
|
88
89
|
mime-types (2.6.2)
|
|
89
|
-
|
|
90
|
+
mini_portile2 (2.0.0)
|
|
90
91
|
minitest (5.8.2)
|
|
91
92
|
nenv (0.2.0)
|
|
92
93
|
netrc (0.11.0)
|
|
93
|
-
nokogiri (1.6.
|
|
94
|
-
|
|
94
|
+
nokogiri (1.6.7.2)
|
|
95
|
+
mini_portile2 (~> 2.0.0.rc2)
|
|
95
96
|
notiffany (0.0.8)
|
|
96
97
|
nenv (~> 0.1)
|
|
97
98
|
shellany (~> 0.0)
|
|
@@ -102,16 +103,16 @@ GEM
|
|
|
102
103
|
rack (1.6.4)
|
|
103
104
|
rack-test (0.6.3)
|
|
104
105
|
rack (>= 1.0)
|
|
105
|
-
rails (4.2.
|
|
106
|
-
actionmailer (= 4.2.
|
|
107
|
-
actionpack (= 4.2.
|
|
108
|
-
actionview (= 4.2.
|
|
109
|
-
activejob (= 4.2.
|
|
110
|
-
activemodel (= 4.2.
|
|
111
|
-
activerecord (= 4.2.
|
|
112
|
-
activesupport (= 4.2.
|
|
106
|
+
rails (4.2.6)
|
|
107
|
+
actionmailer (= 4.2.6)
|
|
108
|
+
actionpack (= 4.2.6)
|
|
109
|
+
actionview (= 4.2.6)
|
|
110
|
+
activejob (= 4.2.6)
|
|
111
|
+
activemodel (= 4.2.6)
|
|
112
|
+
activerecord (= 4.2.6)
|
|
113
|
+
activesupport (= 4.2.6)
|
|
113
114
|
bundler (>= 1.3.0, < 2.0)
|
|
114
|
-
railties (= 4.2.
|
|
115
|
+
railties (= 4.2.6)
|
|
115
116
|
sprockets-rails
|
|
116
117
|
rails-deprecated_sanitizer (1.0.3)
|
|
117
118
|
activesupport (>= 4.2.0.alpha)
|
|
@@ -119,11 +120,11 @@ GEM
|
|
|
119
120
|
activesupport (>= 4.2.0.beta, < 5.0)
|
|
120
121
|
nokogiri (~> 1.6.0)
|
|
121
122
|
rails-deprecated_sanitizer (>= 1.0.1)
|
|
122
|
-
rails-html-sanitizer (1.0.
|
|
123
|
+
rails-html-sanitizer (1.0.3)
|
|
123
124
|
loofah (~> 2.0)
|
|
124
|
-
railties (4.2.
|
|
125
|
-
actionpack (= 4.2.
|
|
126
|
-
activesupport (= 4.2.
|
|
125
|
+
railties (4.2.6)
|
|
126
|
+
actionpack (= 4.2.6)
|
|
127
|
+
activesupport (= 4.2.6)
|
|
127
128
|
rake (>= 0.8.7)
|
|
128
129
|
thor (>= 0.18.1, < 2.0)
|
|
129
130
|
rake (10.4.2)
|
|
@@ -141,12 +142,13 @@ GEM
|
|
|
141
142
|
simplecov-html (~> 0.10.0)
|
|
142
143
|
simplecov-html (0.10.0)
|
|
143
144
|
slop (3.6.0)
|
|
144
|
-
sprockets (3.
|
|
145
|
+
sprockets (3.5.2)
|
|
146
|
+
concurrent-ruby (~> 1.0)
|
|
145
147
|
rack (> 1, < 3)
|
|
146
|
-
sprockets-rails (
|
|
147
|
-
actionpack (>=
|
|
148
|
-
activesupport (>=
|
|
149
|
-
sprockets (>=
|
|
148
|
+
sprockets-rails (3.0.4)
|
|
149
|
+
actionpack (>= 4.0)
|
|
150
|
+
activesupport (>= 4.0)
|
|
151
|
+
sprockets (>= 3.0.0)
|
|
150
152
|
term-ansicolor (1.3.2)
|
|
151
153
|
tins (~> 1.0)
|
|
152
154
|
thor (0.19.1)
|
|
@@ -171,4 +173,4 @@ DEPENDENCIES
|
|
|
171
173
|
semantic_date_time_tags!
|
|
172
174
|
|
|
173
175
|
BUNDLED WITH
|
|
174
|
-
1.
|
|
176
|
+
1.11.2
|
data/README.md
CHANGED
|
@@ -59,8 +59,16 @@ $ gem install semantic_date_time_tags
|
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
If you want to use the default css you can include it like this:
|
|
62
|
+
```css
|
|
63
|
+
/*
|
|
64
|
+
*= require 'semantic_date_time_tags/default'
|
|
65
|
+
*/
|
|
62
66
|
```
|
|
63
|
-
|
|
67
|
+
|
|
68
|
+
Or if you like to use some of the mixins, import them like this:
|
|
69
|
+
|
|
70
|
+
```scss
|
|
71
|
+
@import "semantic_date_time_tags/partials/mixins";
|
|
64
72
|
```
|
|
65
73
|
|
|
66
74
|
## Usage
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import 'mixins/*';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* hides first year of date range if same year */
|
|
2
|
+
@mixin date-range-same-year {
|
|
3
|
+
&.same_year {
|
|
4
|
+
time.date.from {
|
|
5
|
+
span.year {
|
|
6
|
+
display: none;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/* hides first month of date range if same month */
|
|
14
|
+
@mixin date-range-same-year-same-month {
|
|
15
|
+
&.same_year.same_month {
|
|
16
|
+
time.date.from {
|
|
17
|
+
span.month {
|
|
18
|
+
display: none;
|
|
19
|
+
}
|
|
20
|
+
span.month + span.sep {
|
|
21
|
+
display: none;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
/* hides time from and date range seperator if same day */
|
|
29
|
+
@mixin date-range-same-day {
|
|
30
|
+
&.same_day {
|
|
31
|
+
time.date.from,
|
|
32
|
+
span.date_range_separator {
|
|
33
|
+
display: none;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/* hides first am/pm if same meridian */
|
|
40
|
+
@mixin date-range-same-meridian {
|
|
41
|
+
&.same_meridian {
|
|
42
|
+
time.from {
|
|
43
|
+
span.minutes + span.sep,
|
|
44
|
+
span.minutes + span.sep + span.ampm {
|
|
45
|
+
display: none;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* hides minutes if whole hour */
|
|
2
|
+
@mixin date-time-whole-hour {
|
|
3
|
+
&.whole_hour {
|
|
4
|
+
span.minutes,
|
|
5
|
+
span.minutes + span.sep {
|
|
6
|
+
display: none;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/* hides seconds if whole minutes */
|
|
13
|
+
@mixin date-time-whole-minute {
|
|
14
|
+
&.whole_minute {
|
|
15
|
+
span.seconds,
|
|
16
|
+
span.seconds + span.sep {
|
|
17
|
+
display: none;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -2,7 +2,6 @@ require 'action_view'
|
|
|
2
2
|
|
|
3
3
|
module SemanticDateTimeTags
|
|
4
4
|
class FormatParser < Struct.new :format, :str
|
|
5
|
-
|
|
6
5
|
include ActionView::Helpers::TagHelper
|
|
7
6
|
|
|
8
7
|
def to_html
|
|
@@ -23,18 +22,18 @@ module SemanticDateTimeTags
|
|
|
23
22
|
format.scan /(%-?\w|.+?(?=%))/
|
|
24
23
|
end
|
|
25
24
|
|
|
26
|
-
def get_tag_for_match
|
|
25
|
+
def get_tag_for_match(match, comp)
|
|
27
26
|
content_tag :span, match, class: get_classes_for_component(comp)
|
|
28
27
|
end
|
|
29
28
|
|
|
30
|
-
def get_regexp_for_component
|
|
29
|
+
def get_regexp_for_component(comp)
|
|
31
30
|
case
|
|
32
|
-
when comp =~ /%-?\w/ then
|
|
31
|
+
when comp =~ /%-?\w/ then '(\\w+)'
|
|
33
32
|
else "(#{comp})"
|
|
34
33
|
end
|
|
35
34
|
end
|
|
36
35
|
|
|
37
|
-
def get_classes_for_component
|
|
36
|
+
def get_classes_for_component(comp)
|
|
38
37
|
case comp
|
|
39
38
|
when /%-?[YCy]/ then ['year', comp[/\w/]]
|
|
40
39
|
when /%-?[mBbh]/ then ['month', comp[/\w/]]
|
|
@@ -45,6 +44,5 @@ module SemanticDateTimeTags
|
|
|
45
44
|
when /\W+/ then ['sep']
|
|
46
45
|
end
|
|
47
46
|
end
|
|
48
|
-
|
|
49
47
|
end
|
|
50
48
|
end
|
|
@@ -3,8 +3,7 @@ require_relative '../format_parser'
|
|
|
3
3
|
module SemanticDateTimeTags
|
|
4
4
|
class Tag
|
|
5
5
|
class Date < Tag
|
|
6
|
-
|
|
7
|
-
def initialize obj, options={}
|
|
6
|
+
def initialize(obj, options = {})
|
|
8
7
|
raise 'object must be Date or DateTime' unless [::Date, ::DateTime].any? { |c| obj.instance_of? c }
|
|
9
8
|
super(obj, options)
|
|
10
9
|
end
|
|
@@ -29,7 +28,6 @@ module SemanticDateTimeTags
|
|
|
29
28
|
def scope
|
|
30
29
|
'date.formats'
|
|
31
30
|
end
|
|
32
|
-
|
|
33
31
|
end
|
|
34
32
|
end
|
|
35
33
|
end
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
module SemanticDateTimeTags
|
|
2
2
|
class Tag
|
|
3
3
|
class DateRange < Tag
|
|
4
|
-
|
|
5
4
|
attr_accessor :date_from
|
|
6
5
|
attr_accessor :date_to
|
|
7
6
|
attr_accessor :options
|
|
8
7
|
|
|
9
|
-
def initialize
|
|
8
|
+
def initialize(date_from, date_to = nil, options = {})
|
|
10
9
|
@date_from = date_from
|
|
11
10
|
@date_to = date_to
|
|
12
11
|
@options = options
|
|
@@ -43,7 +42,7 @@ module SemanticDateTimeTags
|
|
|
43
42
|
def same_meridian?
|
|
44
43
|
return false unless same_day?
|
|
45
44
|
(date_from.to_datetime.hour < 12 && date_to.to_datetime.hour < 12) ||
|
|
46
|
-
|
|
45
|
+
(date_from.to_datetime.hour >= 12 && date_to.to_datetime.hour >= 12)
|
|
47
46
|
end
|
|
48
47
|
|
|
49
48
|
# ---------------------------------------------------------------------
|
|
@@ -65,18 +64,18 @@ module SemanticDateTimeTags
|
|
|
65
64
|
|
|
66
65
|
def to_html
|
|
67
66
|
from = case date_from
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
when ::DateTime then SemanticDateTimeTags::Tag::DateTime.new(date_from, options.merge(class: 'from')).to_html
|
|
68
|
+
when ::Date then SemanticDateTimeTags::Tag::Date.new(date_from.to_date, options.merge(class: 'from')).to_html
|
|
70
69
|
end
|
|
71
70
|
|
|
72
71
|
sep = content_tag(:span, separator, class: 'date_range_separator')
|
|
73
72
|
|
|
74
73
|
to = case date_to
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
when ::DateTime then SemanticDateTimeTags::Tag::DateTime.new(date_to, options.merge(class: 'to')).to_html
|
|
75
|
+
when ::Date then SemanticDateTimeTags::Tag::Date.new(date_to.to_date, options.merge(class: 'to')).to_html
|
|
77
76
|
end
|
|
78
77
|
|
|
79
|
-
content_tag(:span, class: dom_classes) { [
|
|
78
|
+
content_tag(:span, class: dom_classes) { [from, sep, to].join.html_safe }.html_safe
|
|
80
79
|
end
|
|
81
80
|
|
|
82
81
|
private # =============================================================
|
|
@@ -84,7 +83,6 @@ module SemanticDateTimeTags
|
|
|
84
83
|
def separator
|
|
85
84
|
options.fetch(:separator, ' – ')
|
|
86
85
|
end
|
|
87
|
-
|
|
88
86
|
end
|
|
89
87
|
end
|
|
90
88
|
end
|
|
@@ -3,8 +3,7 @@ require_relative '../format_parser'
|
|
|
3
3
|
module SemanticDateTimeTags
|
|
4
4
|
class Tag
|
|
5
5
|
class DateTime < Tag
|
|
6
|
-
|
|
7
|
-
def initialize obj, options={}
|
|
6
|
+
def initialize(obj, options = {})
|
|
8
7
|
raise 'object must be DateTime' unless obj.instance_of?(::DateTime)
|
|
9
8
|
super(obj, options)
|
|
10
9
|
end
|
|
@@ -32,9 +31,8 @@ module SemanticDateTimeTags
|
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
def localized_obj
|
|
35
|
-
obj.strftime I18n.t(
|
|
34
|
+
obj.strftime I18n.t(format, scope: scope, locale: I18n.locale)
|
|
36
35
|
end
|
|
37
|
-
|
|
38
36
|
end
|
|
39
37
|
end
|
|
40
38
|
end
|
|
@@ -3,8 +3,7 @@ require_relative '../format_parser'
|
|
|
3
3
|
module SemanticDateTimeTags
|
|
4
4
|
class Tag
|
|
5
5
|
class Time < Tag
|
|
6
|
-
|
|
7
|
-
def initialize obj, options={}
|
|
6
|
+
def initialize(obj, options = {})
|
|
8
7
|
raise 'object must be Time' unless obj.instance_of?(::Time)
|
|
9
8
|
super(obj, options)
|
|
10
9
|
end
|
|
@@ -30,7 +29,6 @@ module SemanticDateTimeTags
|
|
|
30
29
|
def scope
|
|
31
30
|
'time.formats'
|
|
32
31
|
end
|
|
33
|
-
|
|
34
32
|
end
|
|
35
33
|
end
|
|
36
34
|
end
|
|
@@ -3,7 +3,6 @@ require 'i18n'
|
|
|
3
3
|
|
|
4
4
|
module SemanticDateTimeTags
|
|
5
5
|
class Tag
|
|
6
|
-
|
|
7
6
|
include ActionView::Helpers::DateHelper
|
|
8
7
|
include ActionView::Helpers::TagHelper
|
|
9
8
|
|
|
@@ -13,9 +12,9 @@ module SemanticDateTimeTags
|
|
|
13
12
|
|
|
14
13
|
# =====================================================================
|
|
15
14
|
|
|
16
|
-
def initialize
|
|
15
|
+
def initialize(obj, options = {})
|
|
17
16
|
@obj = obj
|
|
18
|
-
@options = options.tap{ |opts| opts.delete(:scope) }
|
|
17
|
+
@options = options.tap { |opts| opts.delete(:scope) }
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
# ---------------------------------------------------------------------
|
|
@@ -46,39 +45,39 @@ module SemanticDateTimeTags
|
|
|
46
45
|
end
|
|
47
46
|
|
|
48
47
|
def current_date_class
|
|
49
|
-
return unless [::Date
|
|
48
|
+
return unless [::Date, ::DateTime].any? { |c| obj.instance_of? c }
|
|
50
49
|
'current_date' if obj.today?
|
|
51
50
|
end
|
|
52
51
|
|
|
53
52
|
def current_year_class
|
|
54
|
-
return unless [::Date
|
|
53
|
+
return unless [::Date, ::DateTime].any? { |c| obj.instance_of? c }
|
|
55
54
|
'current_year' if obj.year == ::Date.today.year
|
|
56
55
|
end
|
|
57
56
|
|
|
58
57
|
def whole_hour_class
|
|
59
|
-
return unless [::Time
|
|
58
|
+
return unless [::Time, ::DateTime].any? { |c| obj.instance_of? c }
|
|
60
59
|
'whole_hour' unless obj.min > 0
|
|
61
60
|
end
|
|
62
61
|
|
|
63
62
|
def whole_minute_class
|
|
64
|
-
return unless [::Time
|
|
63
|
+
return unless [::Time, ::DateTime].any? { |c| obj.instance_of? c }
|
|
65
64
|
'whole_minute' unless obj.sec > 0
|
|
66
65
|
end
|
|
67
66
|
|
|
68
67
|
def noon_class
|
|
69
|
-
return unless [::Time
|
|
68
|
+
return unless [::Time, ::DateTime].any? { |c| obj.instance_of? c }
|
|
70
69
|
'noon' if obj == obj.noon
|
|
71
70
|
end
|
|
72
71
|
|
|
73
72
|
def midnight_class
|
|
74
|
-
return unless [::Time
|
|
73
|
+
return unless [::Time, ::DateTime].any? { |c| obj.instance_of? c }
|
|
75
74
|
'midnight' if obj == obj.midnight
|
|
76
75
|
end
|
|
77
76
|
|
|
78
77
|
def am_pm_class
|
|
79
|
-
return unless [::Time
|
|
78
|
+
return unless [::Time, ::DateTime].any? { |c| obj.instance_of? c }
|
|
80
79
|
case
|
|
81
|
-
when (0..11).
|
|
80
|
+
when (0..11).cover?(obj.hour) then 'am'
|
|
82
81
|
else 'pm'
|
|
83
82
|
end
|
|
84
83
|
end
|
|
@@ -114,20 +113,19 @@ module SemanticDateTimeTags
|
|
|
114
113
|
# ---------------------------------------------------------------------
|
|
115
114
|
|
|
116
115
|
def in_words
|
|
117
|
-
[
|
|
116
|
+
[noon_in_words, midnight_in_words].reject(&:blank?).join(' ')
|
|
118
117
|
end
|
|
119
118
|
|
|
120
119
|
def noon_in_words
|
|
121
|
-
return unless [::Time
|
|
120
|
+
return unless [::Time, ::DateTime].any? { |c| obj.instance_of? c }
|
|
122
121
|
return unless obj == obj.noon
|
|
123
122
|
I18n.t :noon, scope: %i(time in_words)
|
|
124
123
|
end
|
|
125
124
|
|
|
126
125
|
def midnight_in_words
|
|
127
|
-
return unless [::Time
|
|
126
|
+
return unless [::Time, ::DateTime].any? { |c| obj.instance_of? c }
|
|
128
127
|
return unless obj == obj.midnight
|
|
129
128
|
I18n.t :midnight, scope: %i(time in_words)
|
|
130
129
|
end
|
|
131
|
-
|
|
132
130
|
end
|
|
133
131
|
end
|
|
@@ -8,8 +8,7 @@ require_relative 'tag/time'
|
|
|
8
8
|
|
|
9
9
|
module SemanticDateTimeTags
|
|
10
10
|
module ViewHelpers
|
|
11
|
-
|
|
12
|
-
def self.included klass
|
|
11
|
+
def self.included(klass)
|
|
13
12
|
klass.class_eval do
|
|
14
13
|
include ActionView::Context
|
|
15
14
|
end
|
|
@@ -18,25 +17,24 @@ module SemanticDateTimeTags
|
|
|
18
17
|
# =====================================================================
|
|
19
18
|
|
|
20
19
|
# accepts datetime and date
|
|
21
|
-
def semantic_date_range_tag
|
|
20
|
+
def semantic_date_range_tag(date_from, date_to, options = {})
|
|
22
21
|
SemanticDateTimeTags::Tag::DateRange.new(date_from, date_to, options).to_html
|
|
23
22
|
end
|
|
24
|
-
|
|
23
|
+
alias semantic_date_time_range_tag semantic_date_range_tag
|
|
25
24
|
|
|
26
25
|
# accepts only datetime
|
|
27
|
-
def semantic_date_time_tag
|
|
26
|
+
def semantic_date_time_tag(date_time, options = {})
|
|
28
27
|
SemanticDateTimeTags::Tag::DateTime.new(date_time, options).to_html
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
# accepts datetime and date
|
|
32
|
-
def semantic_date_tag
|
|
31
|
+
def semantic_date_tag(date, options = {})
|
|
33
32
|
SemanticDateTimeTags::Tag::Date.new(date, options).to_html
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
# accepts datetime and time
|
|
37
|
-
def semantic_time_tag
|
|
36
|
+
def semantic_time_tag(time, options = {})
|
|
38
37
|
SemanticDateTimeTags::Tag::Time.new(time, options).to_html
|
|
39
38
|
end
|
|
40
|
-
|
|
41
39
|
end
|
|
42
40
|
end
|
|
@@ -3,4 +3,4 @@ require "semantic_date_time_tags/railtie" if defined?(Rails)
|
|
|
3
3
|
require "semantic_date_time_tags/engine"
|
|
4
4
|
require "semantic_date_time_tags/version"
|
|
5
5
|
|
|
6
|
-
I18n.load_path += Dir.glob(File.join( File.dirname(__FILE__), 'config', 'locales', '*.yml' ))
|
|
6
|
+
I18n.load_path += Dir.glob(File.join( File.dirname(__FILE__), 'config', 'locales', '*.yml' ))
|
|
@@ -4,28 +4,26 @@ require 'semantic_date_time_tags/view_helpers'
|
|
|
4
4
|
describe SemanticDateTimeTags::ViewHelpers do
|
|
5
5
|
include SemanticDateTimeTags::ViewHelpers
|
|
6
6
|
|
|
7
|
-
let(:date_object) { Date.parse(
|
|
8
|
-
let(:date_tomorrow_object) { Date.parse(
|
|
9
|
-
let(:time_object) { Time.parse(
|
|
7
|
+
let(:date_object) { Date.parse("31/10/#{Date.today.year}") }
|
|
8
|
+
let(:date_tomorrow_object) { Date.parse("31/10/#{Date.today.year}") + 1.day }
|
|
9
|
+
let(:time_object) { Time.parse("31/10/#{Date.today.year}") }
|
|
10
10
|
|
|
11
11
|
# ---------------------------------------------------------------------
|
|
12
12
|
|
|
13
13
|
describe '#semantic_time_tag' do
|
|
14
14
|
let(:time_object_hours) { time_object.strftime('%H') }
|
|
15
|
-
let(:time_object_midnight) { Time.new(
|
|
15
|
+
let(:time_object_midnight) { Time.new(Date.today.year, 11, 3, 24, 00) }
|
|
16
16
|
let(:time_object_minutes) { time_object.strftime('%M') }
|
|
17
|
-
let(:time_object_noon) { Time.new(
|
|
17
|
+
let(:time_object_noon) { Time.new(Date.today.year, 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
20
|
let(:time_object_before_noon) { Time.new(2014, 8, 21, 11, 00) }
|
|
21
21
|
let(:time_object_after_noon) { Time.new(2014, 8, 21, 12, 01) }
|
|
22
22
|
|
|
23
|
-
|
|
24
23
|
it 'does not work with a date object' do
|
|
25
24
|
proc { semantic_time_tag(date_object) }.must_raise RuntimeError
|
|
26
25
|
end
|
|
27
26
|
|
|
28
|
-
|
|
29
27
|
it 'returns hours wrapped in a span tag' do
|
|
30
28
|
semantic_time_tag(time_object).must_match Regexp.new("<span.+?hours.+?H.+?>#{time_object_hours}</span>")
|
|
31
29
|
end
|
|
@@ -34,16 +32,14 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
34
32
|
semantic_time_tag(time_object).must_match Regexp.new("<span.+?minutes.+?M.+?>#{time_object_minutes}</span>")
|
|
35
33
|
end
|
|
36
34
|
|
|
37
|
-
|
|
38
35
|
it 'wraps the whole thing in a time tag by default' do
|
|
39
36
|
semantic_time_tag(time_object).must_match /\A<time.+?<\/time>\z/
|
|
40
37
|
end
|
|
41
38
|
|
|
42
39
|
it 'wraps the whole thing in a span tag if passed as argument' do
|
|
43
|
-
semantic_time_tag(time_object,
|
|
40
|
+
semantic_time_tag(time_object, tag_name: :span).must_match /\A<span.+?<\/span>\z/
|
|
44
41
|
end
|
|
45
42
|
|
|
46
|
-
|
|
47
43
|
it 'adds whole_hour class if time is whole hour' do
|
|
48
44
|
semantic_time_tag(time_object_whole_hour).must_match /\A<time.+?whole_hour.+?<\/time>\z/
|
|
49
45
|
end
|
|
@@ -52,7 +48,6 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
52
48
|
semantic_time_tag(time_object_whole_minute).must_match /\A<time.+?whole_minute.+?<\/time>\z/
|
|
53
49
|
end
|
|
54
50
|
|
|
55
|
-
|
|
56
51
|
it 'adds noon class if time is noon' do
|
|
57
52
|
semantic_time_tag(time_object_noon).must_match /\A<time.+?noon.+?<\/time>\z/
|
|
58
53
|
end
|
|
@@ -69,7 +64,6 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
69
64
|
semantic_time_tag(time_object_after_noon).must_match /\A<time.+?pm.+?<\/time>\z/
|
|
70
65
|
end
|
|
71
66
|
|
|
72
|
-
|
|
73
67
|
it 'adds noon as data-in-words if time is noon' do
|
|
74
68
|
semantic_time_tag(time_object_noon).must_match /\A<time.+?data-in-words=\"noon\".+?<\/time>\z/
|
|
75
69
|
end
|
|
@@ -78,7 +72,6 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
78
72
|
semantic_time_tag(time_object_midnight).must_match /\A<time.+?data-in-words=\"midnight\".+?<\/time>\z/
|
|
79
73
|
end
|
|
80
74
|
|
|
81
|
-
|
|
82
75
|
it 'allows to pass :format' do
|
|
83
76
|
semantic_time_tag(time_object, format: :test).must_include '~'
|
|
84
77
|
end
|
|
@@ -91,39 +84,34 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
91
84
|
let(:date_object_month) { date_object.strftime('%-m') }
|
|
92
85
|
let(:date_object_year) { date_object.year }
|
|
93
86
|
|
|
94
|
-
|
|
95
87
|
it 'should only work with a date or datetime object' do
|
|
96
88
|
proc { semantic_date_tag(time_object) }.must_raise RuntimeError
|
|
97
89
|
end
|
|
98
90
|
|
|
99
|
-
|
|
100
91
|
it 'wraps everything in a time tag by default' do
|
|
101
92
|
semantic_date_tag(date_object).must_match /\A<time.+?<\/time>\z/
|
|
102
93
|
end
|
|
103
94
|
|
|
104
95
|
it 'wraps everything in a span tag if passed as argument' do
|
|
105
|
-
semantic_date_tag(date_object,
|
|
96
|
+
semantic_date_tag(date_object, tag_name: :span).must_match /\A<span.+?<\/span>\z/
|
|
106
97
|
end
|
|
107
98
|
|
|
108
|
-
|
|
109
99
|
it 'returns year, month and day wrapped in a span tags' do
|
|
110
100
|
semantic_date_tag(date_object).must_match Regexp.new("<span.+?year.+?>#{date_object_year}</span>")
|
|
111
101
|
semantic_date_tag(date_object).must_match Regexp.new("<span.+?month.+?>#{date_object_month}</span>")
|
|
112
102
|
semantic_date_tag(date_object).must_match Regexp.new("<span.+?day.+?>#{date_object_day}</span>")
|
|
113
103
|
end
|
|
114
104
|
|
|
115
|
-
|
|
116
105
|
it 'adds current_date class if date is today' do
|
|
117
|
-
semantic_date_tag(Date.today).must_include
|
|
118
|
-
semantic_date_tag(Date.today-1.day).wont_include
|
|
106
|
+
semantic_date_tag(Date.today).must_include 'current_date'
|
|
107
|
+
semantic_date_tag(Date.today - 1.day).wont_include 'current_date'
|
|
119
108
|
end
|
|
120
109
|
|
|
121
110
|
it 'adds current class to year span if date is this year' do
|
|
122
|
-
semantic_date_tag(Date.today).must_include
|
|
123
|
-
semantic_date_tag(Date.today-1.year).wont_include
|
|
111
|
+
semantic_date_tag(Date.today).must_include 'current_year'
|
|
112
|
+
semantic_date_tag(Date.today - 1.year).wont_include 'current_year'
|
|
124
113
|
end
|
|
125
114
|
|
|
126
|
-
|
|
127
115
|
it 'allows to pass :format' do
|
|
128
116
|
semantic_date_tag(Date.today, format: :test).must_include '~'
|
|
129
117
|
end
|
|
@@ -132,9 +120,9 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
132
120
|
# ---------------------------------------------------------------------
|
|
133
121
|
|
|
134
122
|
describe '#semantic_date_time_tag' do
|
|
135
|
-
let(:date_time_object) { DateTime.parse(
|
|
136
|
-
let(:date_time_object_noon) { DateTime.parse(
|
|
137
|
-
let(:date_time_object_midnight) { DateTime.parse(
|
|
123
|
+
let(:date_time_object) { DateTime.parse("31/10/#{Date.today.year}") }
|
|
124
|
+
let(:date_time_object_noon) { DateTime.parse("31/10/#{Date.today.year}").noon }
|
|
125
|
+
let(:date_time_object_midnight) { DateTime.parse("31/10/#{Date.today.year}").midnight }
|
|
138
126
|
|
|
139
127
|
it 'only works with a time or date_time object' do
|
|
140
128
|
proc { semantic_date_time_tag(time_object) }.must_raise RuntimeError
|
|
@@ -160,11 +148,11 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
160
148
|
# ---------------------------------------------------------------------
|
|
161
149
|
|
|
162
150
|
describe '#semantic_date_range_tag' do
|
|
163
|
-
let(:date_time_object_from) { DateTime.parse(
|
|
164
|
-
let(:date_time_object_to) { DateTime.parse(
|
|
151
|
+
let(:date_time_object_from) { DateTime.parse("31/10/#{Date.today.year}") }
|
|
152
|
+
let(:date_time_object_to) { DateTime.parse("11/11/#{Date.today.year}") }
|
|
165
153
|
|
|
166
|
-
let(:date_time_object_from_morning) { DateTime.parse(
|
|
167
|
-
let(:date_time_object_to_afternoon) { DateTime.parse(
|
|
154
|
+
let(:date_time_object_from_morning) { DateTime.parse("14/11/#{Date.today.year} 11:00") }
|
|
155
|
+
let(:date_time_object_to_afternoon) { DateTime.parse("14/11/#{Date.today.year} 15:00") }
|
|
168
156
|
|
|
169
157
|
it 'returns the from date wrapped correctly' do
|
|
170
158
|
semantic_date_range_tag(date_object, date_tomorrow_object).must_match /<time.+?semantic.+?date.+?from.+?>.+?<time.+?semantic.+?date.+?to.+?>/
|
|
@@ -183,9 +171,9 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
183
171
|
end
|
|
184
172
|
|
|
185
173
|
it 'adds am to wrapping span if both times in morning' do
|
|
186
|
-
semantic_date_range_tag(date_time_object_from_morning-1.hour, date_time_object_from_morning).must_match /\A<span.+?date_range.+?same_meridian.+?>/
|
|
174
|
+
semantic_date_range_tag(date_time_object_from_morning - 1.hour, date_time_object_from_morning).must_match /\A<span.+?date_range.+?same_meridian.+?>/
|
|
187
175
|
semantic_date_range_tag(date_time_object_from_morning, date_time_object_to_afternoon).wont_match /\A<span.+?date_range.+?same_meridian.+?>/
|
|
188
|
-
semantic_date_range_tag(date_time_object_to_afternoon, date_time_object_to_afternoon+1.hour).must_match /\A<span.+?date_range.+?same_meridian.+?>/
|
|
176
|
+
semantic_date_range_tag(date_time_object_to_afternoon, date_time_object_to_afternoon + 1.hour).must_match /\A<span.+?date_range.+?same_meridian.+?>/
|
|
189
177
|
end
|
|
190
178
|
|
|
191
179
|
it 'accepts datetime objects' do
|
|
@@ -197,10 +185,8 @@ describe SemanticDateTimeTags::ViewHelpers do
|
|
|
197
185
|
semantic_date_time_range_tag(date_object, date_tomorrow_object).must_match /<time.+?semantic.+?date.+?from.+?>/
|
|
198
186
|
end
|
|
199
187
|
|
|
200
|
-
|
|
201
188
|
it 'allows to pass :format' do
|
|
202
189
|
semantic_date_time_range_tag(date_object, date_tomorrow_object, format: :test).must_include '~'
|
|
203
190
|
end
|
|
204
191
|
end
|
|
205
|
-
|
|
206
192
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: semantic_date_time_tags
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomas Celizna
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-03-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -124,7 +124,11 @@ files:
|
|
|
124
124
|
- LICENSE
|
|
125
125
|
- README.md
|
|
126
126
|
- Rakefile
|
|
127
|
-
- lib/assets/stylesheets/semantic_date_time_tags.css
|
|
127
|
+
- lib/assets/stylesheets/semantic_date_time_tags.css
|
|
128
|
+
- lib/assets/stylesheets/semantic_date_time_tags/default.scss
|
|
129
|
+
- lib/assets/stylesheets/semantic_date_time_tags/partials/_mixins.scss
|
|
130
|
+
- lib/assets/stylesheets/semantic_date_time_tags/partials/mixins/_date_range.scss
|
|
131
|
+
- lib/assets/stylesheets/semantic_date_time_tags/partials/mixins/_date_time.scss
|
|
128
132
|
- lib/config/locales/semantic_date_time_tags.en.yml
|
|
129
133
|
- lib/semantic_date_time_tags.rb
|
|
130
134
|
- lib/semantic_date_time_tags/engine.rb
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
span.date_range {
|
|
2
|
-
&.same_year {
|
|
3
|
-
time.date.from {
|
|
4
|
-
span.year {
|
|
5
|
-
display: none;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
&.same_year.same_month {
|
|
11
|
-
time.date.from {
|
|
12
|
-
span.month {
|
|
13
|
-
display: none;
|
|
14
|
-
}
|
|
15
|
-
span.month + span.sep {
|
|
16
|
-
display: none;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
&.same_day {
|
|
22
|
-
time.date.from,
|
|
23
|
-
span.date_range_separator {
|
|
24
|
-
display: none;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|