condensation 1.0.9 → 1.1.0
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/lib/condensation.rb +2 -1
- data/lib/condensation/filters.rb +1 -0
- data/lib/condensation/filters/timestamp.rb +20 -0
- data/lib/condensation/version.rb +1 -1
- data/spec/condensation/filters/timestamp_spec.rb +64 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b66db88b5f49b3e358743d670d56c7e3b6fd376b
|
4
|
+
data.tar.gz: f2128eaa66b68099f7ed2e19157893171b6c1a2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea238b8045b5d5473e7ea7b6ce6c09929e26b05644c1a89d7369ded18548de5d5dcfd7bea5dc0c53faa77da62f8a46142a0391f697dc839f226306f034241a7
|
7
|
+
data.tar.gz: 5d1906ca536af99666fe8df162afa60fda75ec7a026a1af5abe646dd3a0608c5f754ac2d622ebdc87c85ed05b796746afabafc2e26fce14a57433b30d0623728
|
data/lib/condensation.rb
CHANGED
data/lib/condensation/filters.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Condensation
|
2
|
+
module Filters
|
3
|
+
module Timestamp
|
4
|
+
def timestamp(input)
|
5
|
+
return if input.respond_to?(:empty?) ? input.empty? : !input
|
6
|
+
value = input
|
7
|
+
|
8
|
+
unless value.is_a?(Time)
|
9
|
+
begin
|
10
|
+
value = Time.parse(input)
|
11
|
+
rescue
|
12
|
+
raise Liquid::ArgumentError, "cannot convert #{input} to timestamp"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
value.to_i
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/condensation/version.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Condensation::Filters::Timestamp do
|
4
|
+
def render_with_filter(template, context)
|
5
|
+
template.render(context, :filters => [Condensation::Filters::Timestamp])
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should handle UTC ISO 8601 dates" do
|
9
|
+
created_at = "2015-06-11T10:00:00Z" # a Thursday
|
10
|
+
template = Liquid::Template.parse("{{ created_at | timestamp }}")
|
11
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
12
|
+
result.must_equal Time.parse(created_at).to_i.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should handle non-UTC ISO 8601 dates" do
|
16
|
+
created_at = "2015-06-11T20:00:00-07:00" # a Thursday
|
17
|
+
template = Liquid::Template.parse("{{ created_at | timestamp }}")
|
18
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
19
|
+
result.must_equal Time.parse(created_at).to_i.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should handle YMD formatted dates" do
|
23
|
+
created_at = "2015-06-11" # a Thursday
|
24
|
+
template = Liquid::Template.parse("{{ created_at | timestamp }}")
|
25
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
26
|
+
result.must_equal Time.parse(created_at).to_i.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should handle UTC Time input" do
|
30
|
+
created_at = Time.utc(2015, 6, 11, 10, 0, 0) # a Thursday
|
31
|
+
template = Liquid::Template.parse("{{ created_at | timestamp }}")
|
32
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
33
|
+
result.must_equal created_at.to_i.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should handle non-UTC ActiveSupport::TimeWithZone input" do
|
37
|
+
zone = ActiveSupport::TimeZone["Indian/Maldives"] # UTC+05:00
|
38
|
+
created_at = Time.utc(2015, 6, 11, 10, 0, 0).in_time_zone(zone) # Thu, 11 Jun 2015 15:00:00 MVT +05:00
|
39
|
+
template = Liquid::Template.parse("{{ created_at | timestamp }}")
|
40
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
41
|
+
result.must_equal created_at.to_i.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should render an error given an invalid date" do
|
45
|
+
created_at = "foo"
|
46
|
+
template = Liquid::Template.parse("{{ created_at | timestamp }}")
|
47
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
48
|
+
result.must_equal "Liquid error: cannot convert foo to timestamp"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should handle empty string input" do
|
52
|
+
created_at = ""
|
53
|
+
template = Liquid::Template.parse("{{ created_at | timestamp }}")
|
54
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
55
|
+
result.must_equal ""
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should handle nil input" do
|
59
|
+
created_at = nil
|
60
|
+
template = Liquid::Template.parse("{{ created_at | timestamp }}")
|
61
|
+
result = render_with_filter(template, { "created_at" => created_at })
|
62
|
+
result.must_equal ""
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: condensation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Reimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/condensation/filters/in_time_zone.rb
|
126
126
|
- lib/condensation/filters/replace_inner_html.rb
|
127
127
|
- lib/condensation/filters/strip_commas.rb
|
128
|
+
- lib/condensation/filters/timestamp.rb
|
128
129
|
- lib/condensation/filters/url_encode.rb
|
129
130
|
- lib/condensation/sanitizer.rb
|
130
131
|
- lib/condensation/version.rb
|
@@ -137,6 +138,7 @@ files:
|
|
137
138
|
- spec/condensation/filters/in_time_zone_spec.rb
|
138
139
|
- spec/condensation/filters/replace_inner_html_spec.rb
|
139
140
|
- spec/condensation/filters/strip_commas_spec.rb
|
141
|
+
- spec/condensation/filters/timestamp_spec.rb
|
140
142
|
- spec/condensation/filters/url_encode_spec.rb
|
141
143
|
- spec/condensation/sanitizer_spec.rb
|
142
144
|
- spec/condensation_spec.rb
|
@@ -176,6 +178,7 @@ test_files:
|
|
176
178
|
- spec/condensation/filters/in_time_zone_spec.rb
|
177
179
|
- spec/condensation/filters/replace_inner_html_spec.rb
|
178
180
|
- spec/condensation/filters/strip_commas_spec.rb
|
181
|
+
- spec/condensation/filters/timestamp_spec.rb
|
179
182
|
- spec/condensation/filters/url_encode_spec.rb
|
180
183
|
- spec/condensation/sanitizer_spec.rb
|
181
184
|
- spec/condensation_spec.rb
|