condensation 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d604b37c39e91d58a069c1077d28b324f2bf3a6
4
- data.tar.gz: 4a26fbcf785eef22ba017ad16f053006ac479745
3
+ metadata.gz: ed002bb3c91d4d84d1e35a5e082447da17adb038
4
+ data.tar.gz: b81c84fe94d9669af47b09804ad23e1149ae3685
5
5
  SHA512:
6
- metadata.gz: fe2d89862616b7c0e79f66a7beabbd94db59fc8f36d3ed0bc68c7d13a145bf98e5e9d3419cfea171962e06621a32c170bad6a8f2444af39a0f970adaa82be5bb
7
- data.tar.gz: 6e33fdf33b43a11b7720715140d387d6542c86ec0fa64059bfefa6ba559f544bc3192cc0c1f249652a909572d377ac109137a697c7adfef7f56c5dfd7c4b24ea
6
+ metadata.gz: 4032dabf0ab55ce4fe55b0203795c15853e82483283c70794d8e6ac9d0e262a375e164e3aa176cdc83698a62a81e3bccf932842acec42c3e51564dde7c6db1ed
7
+ data.tar.gz: b6db0f0359271367f992b86a332d1d06817de801557f0a18fa811b6c731723ebd0d1d198f6fecf4c83565c50d8242c94d6be0d8b8fc98c59106025c90d071809
data/condensation.gemspec CHANGED
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "timecop", "~> 0.7"
23
23
 
24
24
  spec.add_dependency "liquid", [">= 2.0", "<= 4.0"]
25
+ spec.add_dependency "tzinfo"
26
+ spec.add_dependency "activesupport", "~> 3.0"
25
27
  end
data/lib/condensation.rb CHANGED
@@ -12,7 +12,9 @@ module Condensation
12
12
  Filters::DaysUntil,
13
13
  Filters::UrlEncode,
14
14
  Filters::StripCommas,
15
- Filters::AdvanceDateToNext
15
+ Filters::AdvanceDateToNext,
16
+ Filters::AtMidnight,
17
+ Filters::InTimeZone
16
18
  ]
17
19
 
18
20
  def self.register_filters
@@ -6,3 +6,5 @@ require "condensation/filters/days_until"
6
6
  require "condensation/filters/url_encode"
7
7
  require "condensation/filters/strip_commas"
8
8
  require "condensation/filters/advance_date_to_next"
9
+ require "condensation/filters/at_midnight"
10
+ require "condensation/filters/in_time_zone"
@@ -1,4 +1,5 @@
1
- require 'time'
1
+ require "active_support/time_with_zone"
2
+ require "active_support/core_ext/time/calculations"
2
3
 
3
4
  module Condensation
4
5
  module Filters
@@ -26,7 +27,7 @@ module Condensation
26
27
  break if value.wday == day_number
27
28
  end
28
29
 
29
- value
30
+ value.iso8601
30
31
  end
31
32
  end
32
33
  end
@@ -0,0 +1,23 @@
1
+ require "active_support/time_with_zone"
2
+ require "active_support/core_ext/time/calculations"
3
+
4
+ module Condensation
5
+ module Filters
6
+ module AtMidnight
7
+ def at_midnight(input)
8
+ return if input.nil?
9
+
10
+ if input.is_a?(Time)
11
+ value = input
12
+ else
13
+ value = Time.parse(input) rescue nil
14
+ end
15
+
16
+ return input unless value.is_a?(Time)
17
+ value.at_midnight.iso8601
18
+ end
19
+
20
+ alias_method :beginning_of_day, :at_midnight
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ require "active_support/time_with_zone"
2
+ require "active_support/core_ext/time/calculations"
3
+
4
+ module Condensation
5
+ module Filters
6
+ module InTimeZone
7
+ def in_time_zone(input, zone_name = nil)
8
+ zone = Time.find_zone(zone_name)
9
+ return input if zone.nil?
10
+
11
+ converted_time = if input.is_a?(Time)
12
+ input.in_time_zone(zone)
13
+ else
14
+ zone.parse(input)
15
+ end
16
+
17
+ converted_time.iso8601
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Condensation
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
@@ -5,68 +5,66 @@ describe Condensation::Filters::AdvanceDateToNext do
5
5
  template.render(context, :filters => [Condensation::Filters::AdvanceDateToNext])
6
6
  end
7
7
 
8
- describe "#advance_date_to_next" do
9
- it "should handle UTC ISO 8601 dates" do
10
- created_at = "2015-06-11T10:00:00Z" # a Thursday
11
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
12
- result = render_with_filter(template, { "created_at" => created_at })
13
- result.must_equal "2015-06-13 10:00:00 UTC"
14
- end
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 | advance_date_to_next: \"Saturday\" }}")
11
+ result = render_with_filter(template, { "created_at" => created_at })
12
+ result.must_equal "2015-06-13T10:00:00Z"
13
+ end
15
14
 
16
- it "should handle non-UTC ISO 8601 dates" do
17
- created_at = "2015-06-11T20:00:00-07:00" # a Thursday
18
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
19
- result = render_with_filter(template, { "created_at" => created_at })
20
- result.must_equal "2015-06-13 20:00:00 -0700"
21
- end
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 | advance_date_to_next: \"Saturday\" }}")
18
+ result = render_with_filter(template, { "created_at" => created_at })
19
+ result.must_equal "2015-06-13T20:00:00-07:00"
20
+ end
22
21
 
23
- it "should handle YMD formatted dates" do
24
- created_at = "2015-06-11" # a Thursday
25
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
26
- result = render_with_filter(template, { "created_at" => created_at })
27
- result[0..18].must_equal "2015-06-13 00:00:00"
28
- end
22
+ it "should handle YMD formatted dates" do
23
+ created_at = "2015-06-11" # a Thursday
24
+ template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
25
+ result = render_with_filter(template, { "created_at" => created_at })
26
+ result[0..18].must_equal "2015-06-13T00:00:00"
27
+ end
29
28
 
30
- it "should handle Time input" do
31
- created_at = Time.utc(2015, 6, 11, 10, 0, 0) # a Thursday
32
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
33
- result = render_with_filter(template, { "created_at" => created_at })
34
- result.must_equal "2015-06-13 10:00:00 UTC"
35
- end
29
+ it "should handle Time input" do
30
+ created_at = Time.utc(2015, 6, 11, 10, 0, 0) # a Thursday
31
+ template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
32
+ result = render_with_filter(template, { "created_at" => created_at })
33
+ result.must_equal "2015-06-13T10:00:00Z"
34
+ end
36
35
 
37
- it "never return the same day" do
38
- created_at = "2015-06-11T10:00:00Z" # a Thursday
39
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Thursday\" }}")
40
- result = render_with_filter(template, { "created_at" => created_at })
41
- result.must_equal "2015-06-18 10:00:00 UTC"
42
- end
36
+ it "never return the same day" do
37
+ created_at = "2015-06-11T10:00:00Z" # a Thursday
38
+ template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Thursday\" }}")
39
+ result = render_with_filter(template, { "created_at" => created_at })
40
+ result.must_equal "2015-06-18T10:00:00Z"
41
+ end
43
42
 
44
- it "should handle malformed dates" do
45
- created_at = "foo"
46
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
47
- result = render_with_filter(template, { "created_at" => created_at })
48
- result.must_equal "foo"
49
- end
43
+ it "should handle malformed dates" do
44
+ created_at = "foo"
45
+ template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
46
+ result = render_with_filter(template, { "created_at" => created_at })
47
+ result.must_equal "foo"
48
+ end
50
49
 
51
- it "should handle empty string input" do
52
- created_at = ""
53
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
54
- result = render_with_filter(template, { "created_at" => created_at })
55
- result.must_equal ""
56
- end
50
+ it "should handle empty string input" do
51
+ created_at = ""
52
+ template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
53
+ result = render_with_filter(template, { "created_at" => created_at })
54
+ result.must_equal ""
55
+ end
57
56
 
58
- it "should handle nil input" do
59
- created_at = nil
60
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
61
- result = render_with_filter(template, { "created_at" => created_at })
62
- result.must_equal ""
63
- end
57
+ it "should handle nil input" do
58
+ created_at = nil
59
+ template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"Saturday\" }}")
60
+ result = render_with_filter(template, { "created_at" => created_at })
61
+ result.must_equal ""
62
+ end
64
63
 
65
- it "should render an error given an invalid day" do
66
- created_at = "2015-06-11T10:00:00Z" # a Thursday
67
- template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"fooday\" }}")
68
- result = render_with_filter(template, { "created_at" => created_at })
69
- result.must_equal "Liquid error: fooday is not a valid day"
70
- end
64
+ it "should render an error given an invalid day" do
65
+ created_at = "2015-06-11T10:00:00Z" # a Thursday
66
+ template = Liquid::Template.parse("{{ created_at | advance_date_to_next: \"fooday\" }}")
67
+ result = render_with_filter(template, { "created_at" => created_at })
68
+ result.must_equal "Liquid error: fooday is not a valid day"
71
69
  end
72
70
  end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Condensation::Filters::AtMidnight do
4
+ def render_with_filter(template, context)
5
+ template.render(context, :filters => [Condensation::Filters::AtMidnight])
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 | at_midnight }}")
11
+ result = render_with_filter(template, { "created_at" => created_at })
12
+ result.must_equal "2015-06-11T00:00:00Z"
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 | at_midnight }}")
18
+ result = render_with_filter(template, { "created_at" => created_at })
19
+ result.must_equal "2015-06-11T00:00:00-07:00"
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 | at_midnight }}")
25
+ result = render_with_filter(template, { "created_at" => created_at })
26
+ result[0..18].must_equal "2015-06-11T00:00:00"
27
+ end
28
+
29
+ it "should handle Time input" do
30
+ created_at = Time.utc(2015, 6, 11, 10, 0, 0) # a Thursday
31
+ template = Liquid::Template.parse("{{ created_at | at_midnight }}")
32
+ result = render_with_filter(template, { "created_at" => created_at })
33
+ result.must_equal "2015-06-11T00:00:00Z"
34
+ end
35
+
36
+ it "should handle malformed dates" do
37
+ created_at = "foo"
38
+ template = Liquid::Template.parse("{{ created_at | at_midnight }}")
39
+ result = render_with_filter(template, { "created_at" => created_at })
40
+ result.must_equal "foo"
41
+ end
42
+
43
+ it "should handle empty string input" do
44
+ created_at = ""
45
+ template = Liquid::Template.parse("{{ created_at | at_midnight }}")
46
+ result = render_with_filter(template, { "created_at" => created_at })
47
+ result.must_equal ""
48
+ end
49
+
50
+ it "should handle nil input" do
51
+ created_at = nil
52
+ template = Liquid::Template.parse("{{ created_at | at_midnight }}")
53
+ result = render_with_filter(template, { "created_at" => created_at })
54
+ result.must_equal ""
55
+ end
56
+ end
@@ -5,66 +5,64 @@ describe Condensation::Filters::DaysSince do
5
5
  template.render(context, :filters => [Condensation::Filters::DaysSince])
6
6
  end
7
7
 
8
- describe "#days_since" do
9
- let(:now) do
10
- Time.utc(2014, 5, 30, 0, 0, 0)
11
- end
8
+ let(:now) do
9
+ Time.utc(2014, 5, 30, 0, 0, 0)
10
+ end
12
11
 
13
- before do
14
- Timecop.freeze(now)
15
- end
12
+ before do
13
+ Timecop.freeze(now)
14
+ end
16
15
 
17
- after do
18
- Timecop.return
19
- end
16
+ after do
17
+ Timecop.return
18
+ end
20
19
 
21
- it "should handle UTC ISO 8601 dates" do
22
- created_at = "2014-05-15T10:00:00Z"
23
- template = Liquid::Template.parse("{{ created_at | days_since }}")
24
- result = render_with_filter(template, { "created_at" => created_at })
25
- result.must_equal "14"
26
- end
20
+ it "should handle UTC ISO 8601 dates" do
21
+ created_at = "2014-05-15T10:00:00Z"
22
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
23
+ result = render_with_filter(template, { "created_at" => created_at })
24
+ result.must_equal "14"
25
+ end
27
26
 
28
- it "should handle non-UTC ISO 8601 dates" do
29
- created_at = "2014-05-15T20:00:00-07:00"
30
- template = Liquid::Template.parse("{{ created_at | days_since }}")
31
- result = render_with_filter(template, { "created_at" => created_at })
32
- result.must_equal "13"
33
- end
27
+ it "should handle non-UTC ISO 8601 dates" do
28
+ created_at = "2014-05-15T20:00:00-07:00"
29
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
30
+ result = render_with_filter(template, { "created_at" => created_at })
31
+ result.must_equal "13"
32
+ end
34
33
 
35
- it "should handle Time input" do
36
- created_at = Time.utc(2014, 5, 20, 0, 0, 0)
37
- template = Liquid::Template.parse("{{ created_at | days_since }}")
38
- result = render_with_filter(template, { "created_at" => created_at })
39
- result.must_equal "10"
40
- end
34
+ it "should handle Time input" do
35
+ created_at = Time.utc(2014, 5, 20, 0, 0, 0)
36
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
37
+ result = render_with_filter(template, { "created_at" => created_at })
38
+ result.must_equal "10"
39
+ end
41
40
 
42
- it "should handle malformed dates" do
43
- created_at = "foo"
44
- template = Liquid::Template.parse("{{ created_at | days_since }}")
45
- result = render_with_filter(template, { "created_at" => created_at })
46
- result.must_equal ""
47
- end
41
+ it "should handle malformed dates" do
42
+ created_at = "foo"
43
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
44
+ result = render_with_filter(template, { "created_at" => created_at })
45
+ result.must_equal ""
46
+ end
48
47
 
49
- it "should be zero for days in the future" do
50
- created_at = "2014-06-01T20:00:00Z"
51
- template = Liquid::Template.parse("{{ created_at | days_since }}")
52
- result = render_with_filter(template, { "created_at" => created_at })
53
- result.must_equal "0"
54
- end
48
+ it "should be zero for days in the future" do
49
+ created_at = "2014-06-01T20:00:00Z"
50
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
51
+ result = render_with_filter(template, { "created_at" => created_at })
52
+ result.must_equal "0"
53
+ end
55
54
 
56
- it "should handle empty string input" do
57
- created_at = ""
58
- template = Liquid::Template.parse("{{ created_at | days_since }}")
59
- result = render_with_filter(template, { "created_at" => created_at })
60
- result.must_equal ""
61
- end
55
+ it "should handle empty string input" do
56
+ created_at = ""
57
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
58
+ result = render_with_filter(template, { "created_at" => created_at })
59
+ result.must_equal ""
60
+ end
62
61
 
63
- it "should handle nil input" do
64
- created_at = nil
65
- template = Liquid::Template.parse("{{ created_at | days_since }}")
66
- result = render_with_filter(template, { "created_at" => created_at })
67
- result.must_equal ""
68
- end
62
+ it "should handle nil input" do
63
+ created_at = nil
64
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
65
+ result = render_with_filter(template, { "created_at" => created_at })
66
+ result.must_equal ""
69
67
  end
70
68
  end
@@ -5,73 +5,71 @@ describe Condensation::Filters::DaysUntil do
5
5
  template.render(context, :filters => [Condensation::Filters::DaysUntil])
6
6
  end
7
7
 
8
- describe "#days_until" do
9
- let(:now) do
10
- Time.utc(2014, 5, 15, 0, 0, 0)
11
- end
8
+ let(:now) do
9
+ Time.utc(2014, 5, 15, 0, 0, 0)
10
+ end
12
11
 
13
- before do
14
- Timecop.freeze(now)
15
- end
12
+ before do
13
+ Timecop.freeze(now)
14
+ end
16
15
 
17
- after do
18
- Timecop.return
19
- end
16
+ after do
17
+ Timecop.return
18
+ end
20
19
 
21
- it "should handle UTC ISO 8601 dates" do
22
- created_at = "2014-05-30T10:00:00Z"
23
- template = Liquid::Template.parse("{{ created_at | days_until }}")
24
- result = render_with_filter(template, { "created_at" => created_at })
25
- result.must_equal "15"
26
- end
20
+ it "should handle UTC ISO 8601 dates" do
21
+ created_at = "2014-05-30T10:00:00Z"
22
+ template = Liquid::Template.parse("{{ created_at | days_until }}")
23
+ result = render_with_filter(template, { "created_at" => created_at })
24
+ result.must_equal "15"
25
+ end
27
26
 
28
- it "should handle non-UTC ISO 8601 dates" do
29
- created_at = "2014-05-30T20:00:00-07:00"
30
- template = Liquid::Template.parse("{{ created_at | days_until }}")
31
- result = render_with_filter(template, { "created_at" => created_at })
32
- result.must_equal "16"
33
- end
27
+ it "should handle non-UTC ISO 8601 dates" do
28
+ created_at = "2014-05-30T20:00:00-07:00"
29
+ template = Liquid::Template.parse("{{ created_at | days_until }}")
30
+ result = render_with_filter(template, { "created_at" => created_at })
31
+ result.must_equal "16"
32
+ end
34
33
 
35
- it "should handle YMD formatted dates" do
36
- created_at = "2014-05-30"
37
- template = Liquid::Template.parse("{{ created_at | days_until }}")
38
- result = render_with_filter(template, { "created_at" => created_at })
39
- result.must_equal "15"
40
- end
34
+ it "should handle YMD formatted dates" do
35
+ created_at = "2014-05-30"
36
+ template = Liquid::Template.parse("{{ created_at | days_until }}")
37
+ result = render_with_filter(template, { "created_at" => created_at })
38
+ result.must_equal "15"
39
+ end
41
40
 
42
- it "should handle Time input" do
43
- created_at = Time.utc(2014, 5, 20, 0, 0, 0)
44
- template = Liquid::Template.parse("{{ created_at | days_until }}")
45
- result = render_with_filter(template, { "created_at" => created_at })
46
- result.must_equal "5"
47
- end
41
+ it "should handle Time input" do
42
+ created_at = Time.utc(2014, 5, 20, 0, 0, 0)
43
+ template = Liquid::Template.parse("{{ created_at | days_until }}")
44
+ result = render_with_filter(template, { "created_at" => created_at })
45
+ result.must_equal "5"
46
+ end
48
47
 
49
- it "should handle malformed dates" do
50
- created_at = "foo"
51
- template = Liquid::Template.parse("{{ created_at | days_until }}")
52
- result = render_with_filter(template, { "created_at" => created_at })
53
- result.must_equal ""
54
- end
48
+ it "should handle malformed dates" do
49
+ created_at = "foo"
50
+ template = Liquid::Template.parse("{{ created_at | days_until }}")
51
+ result = render_with_filter(template, { "created_at" => created_at })
52
+ result.must_equal ""
53
+ end
55
54
 
56
- it "should be zero for days in the past" do
57
- created_at = "2014-05-01T20:00:00Z"
58
- template = Liquid::Template.parse("{{ created_at | days_until }}")
59
- result = render_with_filter(template, { "created_at" => created_at })
60
- result.must_equal "0"
61
- end
55
+ it "should be zero for days in the past" do
56
+ created_at = "2014-05-01T20:00:00Z"
57
+ template = Liquid::Template.parse("{{ created_at | days_until }}")
58
+ result = render_with_filter(template, { "created_at" => created_at })
59
+ result.must_equal "0"
60
+ end
62
61
 
63
- it "should handle empty string input" do
64
- created_at = ""
65
- template = Liquid::Template.parse("{{ created_at | days_since }}")
66
- result = render_with_filter(template, { "created_at" => created_at })
67
- result.must_equal ""
68
- end
62
+ it "should handle empty string input" do
63
+ created_at = ""
64
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
65
+ result = render_with_filter(template, { "created_at" => created_at })
66
+ result.must_equal ""
67
+ end
69
68
 
70
- it "should handle nil input" do
71
- created_at = nil
72
- template = Liquid::Template.parse("{{ created_at | days_until }}")
73
- result = render_with_filter(template, { "created_at" => created_at })
74
- result.must_equal ""
75
- end
69
+ it "should handle nil input" do
70
+ created_at = nil
71
+ template = Liquid::Template.parse("{{ created_at | days_until }}")
72
+ result = render_with_filter(template, { "created_at" => created_at })
73
+ result.must_equal ""
76
74
  end
77
- end
75
+ end
@@ -5,41 +5,39 @@ describe Condensation::Filters::Default do
5
5
  template.render(context, :filters => [Condensation::Filters::Default])
6
6
  end
7
7
 
8
- describe "#default" do
9
- it "should return input if it is not blank" do
10
- template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
11
- result = render_with_filter(template, { "name" => "Foo" })
12
- result.must_equal "Foo"
13
- end
8
+ it "should return input if it is not blank" do
9
+ template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
10
+ result = render_with_filter(template, { "name" => "Foo" })
11
+ result.must_equal "Foo"
12
+ end
14
13
 
15
- it "should return default value if input is nil" do
16
- template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
17
- result = render_with_filter(template, { "name" => nil })
18
- result.must_equal "Bar"
19
- end
14
+ it "should return default value if input is nil" do
15
+ template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
16
+ result = render_with_filter(template, { "name" => nil })
17
+ result.must_equal "Bar"
18
+ end
20
19
 
21
- it "should return default value if input is an empty string" do
22
- template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
23
- result = render_with_filter(template, { "name" => "" })
24
- result.must_equal "Bar"
25
- end
20
+ it "should return default value if input is an empty string" do
21
+ template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
22
+ result = render_with_filter(template, { "name" => "" })
23
+ result.must_equal "Bar"
24
+ end
26
25
 
27
- it "should return default value if input is an empty hash" do
28
- template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
29
- result = render_with_filter(template, { "name" => {} })
30
- result.must_equal "Bar"
31
- end
26
+ it "should return default value if input is an empty hash" do
27
+ template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
28
+ result = render_with_filter(template, { "name" => {} })
29
+ result.must_equal "Bar"
30
+ end
32
31
 
33
- it "should return default value if input is an empty array" do
34
- template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
35
- result = render_with_filter(template, { "name" => [] })
36
- result.must_equal "Bar"
37
- end
32
+ it "should return default value if input is an empty array" do
33
+ template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
34
+ result = render_with_filter(template, { "name" => [] })
35
+ result.must_equal "Bar"
36
+ end
38
37
 
39
- it "should return default value if input is false" do
40
- template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
41
- result = render_with_filter(template, { "name" => false })
42
- result.must_equal "Bar"
43
- end
38
+ it "should return default value if input is false" do
39
+ template = Liquid::Template.parse("{{ name | default: 'Bar' }}")
40
+ result = render_with_filter(template, { "name" => false })
41
+ result.must_equal "Bar"
44
42
  end
45
- end
43
+ end
@@ -5,48 +5,46 @@ describe Condensation::Filters::Hyperlink do
5
5
  template.render(context, :filters => [Condensation::Filters::Hyperlink])
6
6
  end
7
7
 
8
- describe "#hyperlink" do
9
- it "should use the URL as the anchor text if none provided" do
10
- url = "http://www.example.com"
11
- template = Liquid::Template.parse("{{ url | hyperlink }}")
12
- result = render_with_filter(template, { "url" => url })
13
- result.must_equal "<a href='#{url}'>#{url}</a>"
14
- end
8
+ it "should use the URL as the anchor text if none provided" do
9
+ url = "http://www.example.com"
10
+ template = Liquid::Template.parse("{{ url | hyperlink }}")
11
+ result = render_with_filter(template, { "url" => url })
12
+ result.must_equal "<a href='#{url}'>#{url}</a>"
13
+ end
15
14
 
16
- it "should use the provided anchor text" do
17
- url = "http://www.example.com"
18
- template = Liquid::Template.parse("{{ url | hyperlink: 'Click here!' }}")
19
- result = render_with_filter(template, { "url" => url })
20
- result.must_equal "<a href='#{url}'>Click here!</a>"
21
- end
15
+ it "should use the provided anchor text" do
16
+ url = "http://www.example.com"
17
+ template = Liquid::Template.parse("{{ url | hyperlink: 'Click here!' }}")
18
+ result = render_with_filter(template, { "url" => url })
19
+ result.must_equal "<a href='#{url}'>Click here!</a>"
20
+ end
22
21
 
23
- it "should escape HTML in the URL" do
24
- url = "<script>attack.me()</script>"
25
- escaped = "&lt;script&gt;attack.me()&lt;/script&gt;"
26
- template = Liquid::Template.parse("{{ url | hyperlink }}")
27
- result = render_with_filter(template, { "url" => url })
28
- result.must_equal "<a href='#{escaped}'>#{escaped}</a>"
29
- end
22
+ it "should escape HTML in the URL" do
23
+ url = "<script>attack.me()</script>"
24
+ escaped = "&lt;script&gt;attack.me()&lt;/script&gt;"
25
+ template = Liquid::Template.parse("{{ url | hyperlink }}")
26
+ result = render_with_filter(template, { "url" => url })
27
+ result.must_equal "<a href='#{escaped}'>#{escaped}</a>"
28
+ end
30
29
 
31
- it "should escape HTML in the anchor text" do
32
- url = "http://www.example.com"
33
- text = "<script>attack.me()</script>"
34
- escaped = "&lt;script&gt;attack.me()&lt;/script&gt;"
35
- template = Liquid::Template.parse("{{ url | hyperlink: '#{text}' }}")
36
- result = render_with_filter(template, { "url" => url })
37
- result.must_equal "<a href='#{url}'>#{escaped}</a>"
38
- end
30
+ it "should escape HTML in the anchor text" do
31
+ url = "http://www.example.com"
32
+ text = "<script>attack.me()</script>"
33
+ escaped = "&lt;script&gt;attack.me()&lt;/script&gt;"
34
+ template = Liquid::Template.parse("{{ url | hyperlink: '#{text}' }}")
35
+ result = render_with_filter(template, { "url" => url })
36
+ result.must_equal "<a href='#{url}'>#{escaped}</a>"
37
+ end
39
38
 
40
- it "should return empty string if input is nil" do
41
- template = Liquid::Template.parse("{{ url | hyperlink }}")
42
- result = render_with_filter(template, {})
43
- result.must_equal ""
44
- end
39
+ it "should return empty string if input is nil" do
40
+ template = Liquid::Template.parse("{{ url | hyperlink }}")
41
+ result = render_with_filter(template, {})
42
+ result.must_equal ""
43
+ end
45
44
 
46
- it "should handle numeric input" do
47
- template = Liquid::Template.parse("{{ url | hyperlink: 'Bar' }}")
48
- result = render_with_filter(template, { "url" => 1 })
49
- result.must_equal "<a href='1'>Bar</a>"
50
- end
45
+ it "should handle numeric input" do
46
+ template = Liquid::Template.parse("{{ url | hyperlink: 'Bar' }}")
47
+ result = render_with_filter(template, { "url" => 1 })
48
+ result.must_equal "<a href='1'>Bar</a>"
51
49
  end
52
- end
50
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Condensation::Filters::InTimeZone do
4
+ def render_with_filter(template, context)
5
+ template.render(context, :filters => [Condensation::Filters::InTimeZone])
6
+ end
7
+
8
+ it "should handle UTC ISO 8601 dates" do
9
+ created_at = "2015-01-01T10:00:00Z"
10
+ template = Liquid::Template.parse("{{ created_at | in_time_zone: 'America/Los_Angeles' }}")
11
+ result = render_with_filter(template, { "created_at" => created_at })
12
+ result.must_equal "2015-01-01T02:00:00-08:00"
13
+
14
+ template = Liquid::Template.parse("{{ created_at | in_time_zone: 'Indian/Maldives' }}")
15
+ result = render_with_filter(template, { "created_at" => created_at })
16
+ result.must_equal "2015-01-01T15:00:00+05:00"
17
+ end
18
+
19
+ it "should handle Time input" do
20
+ created_at = Time.utc(2015, 1, 1, 10, 0, 0)
21
+ template = Liquid::Template.parse("{{ created_at | in_time_zone: 'America/Los_Angeles' }}")
22
+ result = render_with_filter(template, { "created_at" => created_at })
23
+ result.must_equal "2015-01-01T02:00:00-08:00"
24
+ end
25
+ end
@@ -5,39 +5,37 @@ describe Condensation::Filters::ReplaceInnerHTML do
5
5
  template.render(context, :filters => [Condensation::Filters::ReplaceInnerHTML])
6
6
  end
7
7
 
8
- describe "#replace_inner_html" do
9
- it "should replace the inner content of a given HTML tag" do
10
- tag = "<a href='http://www.example.com'>Foo</a>"
11
- template = Liquid::Template.parse("{{ example_link | replace_inner_html: 'Bar' }}")
12
- result = render_with_filter(template, { "example_link" => tag })
13
- result.must_equal "<a href='http://www.example.com'>Bar</a>"
14
- end
15
-
16
- it "should not alter malformed input" do
17
- tags = [
18
- "< a href='http://www.example.com'>Foo</a>",
19
- "<a href='http://www.example.com'>Foo< /a>",
20
- "<a href='http://www.example.com'>Foo",
21
- " <a href='http://www.example.com'>Foo</a> "
22
- ]
8
+ it "should replace the inner content of a given HTML tag" do
9
+ tag = "<a href='http://www.example.com'>Foo</a>"
10
+ template = Liquid::Template.parse("{{ example_link | replace_inner_html: 'Bar' }}")
11
+ result = render_with_filter(template, { "example_link" => tag })
12
+ result.must_equal "<a href='http://www.example.com'>Bar</a>"
13
+ end
23
14
 
24
- tags.each do |tag|
25
- template = Liquid::Template.parse("{{ example_link | replace_inner_html: 'Bar' }}")
26
- result = render_with_filter(template, { "example_link" => tag })
27
- result.must_equal tag
28
- end
29
- end
15
+ it "should not alter malformed input" do
16
+ tags = [
17
+ "< a href='http://www.example.com'>Foo</a>",
18
+ "<a href='http://www.example.com'>Foo< /a>",
19
+ "<a href='http://www.example.com'>Foo",
20
+ " <a href='http://www.example.com'>Foo</a> "
21
+ ]
30
22
 
31
- it "should return empty string if input is nil" do
23
+ tags.each do |tag|
32
24
  template = Liquid::Template.parse("{{ example_link | replace_inner_html: 'Bar' }}")
33
- result = render_with_filter(template, {})
34
- result.must_equal ""
25
+ result = render_with_filter(template, { "example_link" => tag })
26
+ result.must_equal tag
35
27
  end
28
+ end
36
29
 
37
- it "should handle numeric input" do
38
- template = Liquid::Template.parse("{{ example_link | replace_inner_html: 'Bar' }}")
39
- result = render_with_filter(template, { "example_link" => 1 })
40
- result.must_equal "1"
41
- end
30
+ it "should return empty string if input is nil" do
31
+ template = Liquid::Template.parse("{{ example_link | replace_inner_html: 'Bar' }}")
32
+ result = render_with_filter(template, {})
33
+ result.must_equal ""
34
+ end
35
+
36
+ it "should handle numeric input" do
37
+ template = Liquid::Template.parse("{{ example_link | replace_inner_html: 'Bar' }}")
38
+ result = render_with_filter(template, { "example_link" => 1 })
39
+ result.must_equal "1"
42
40
  end
43
- end
41
+ end
@@ -5,19 +5,17 @@ describe Condensation::Filters::StripCommas do
5
5
  template.render(context, :filters => [Condensation::Filters::StripCommas])
6
6
  end
7
7
 
8
- describe "#strip_commas" do
9
- it "remove commas" do
10
- tag = "foo, bar, bop"
11
- template = Liquid::Template.parse("{{ tag | strip_commas }}")
12
- result = render_with_filter(template, { "tag" => tag })
13
- result.must_equal "foo bar bop"
14
- end
8
+ it "remove commas" do
9
+ tag = "foo, bar, bop"
10
+ template = Liquid::Template.parse("{{ tag | strip_commas }}")
11
+ result = render_with_filter(template, { "tag" => tag })
12
+ result.must_equal "foo bar bop"
13
+ end
15
14
 
16
- it "should handle nil values" do
17
- tag = nil
18
- template = Liquid::Template.parse("{{ tags | strip_commas }}")
19
- result = render_with_filter(template, { "tag" => tag })
20
- result.must_equal ""
21
- end
15
+ it "should handle nil values" do
16
+ tag = nil
17
+ template = Liquid::Template.parse("{{ tags | strip_commas }}")
18
+ result = render_with_filter(template, { "tag" => tag })
19
+ result.must_equal ""
22
20
  end
23
- end
21
+ end
@@ -5,19 +5,17 @@ describe Condensation::Filters::UrlEncode do
5
5
  template.render(context, :filters => [Condensation::Filters::UrlEncode])
6
6
  end
7
7
 
8
- describe "#url_encode" do
9
- it "encode the input" do
10
- email = "derrick+1@example.com"
11
- template = Liquid::Template.parse("{{ email | url_encode }}")
12
- result = render_with_filter(template, { "email" => email })
13
- result.must_equal "derrick%2B1%40example.com"
14
- end
8
+ it "encode the input" do
9
+ email = "derrick+1@example.com"
10
+ template = Liquid::Template.parse("{{ email | url_encode }}")
11
+ result = render_with_filter(template, { "email" => email })
12
+ result.must_equal "derrick%2B1%40example.com"
13
+ end
15
14
 
16
- it "should handle nil values" do
17
- email = nil
18
- template = Liquid::Template.parse("{{ email | url_encode }}")
19
- result = render_with_filter(template, { "email" => email })
20
- result.must_equal ""
21
- end
15
+ it "should handle nil values" do
16
+ email = nil
17
+ template = Liquid::Template.parse("{{ email | url_encode }}")
18
+ result = render_with_filter(template, { "email" => email })
19
+ result.must_equal ""
22
20
  end
23
- end
21
+ 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.6
4
+ version: 1.0.7
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-06-11 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,34 @@ dependencies:
72
72
  - - <=
73
73
  - !ruby/object:Gem::Version
74
74
  version: '4.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: tzinfo
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: activesupport
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
75
103
  description: A collection of handy extensions to the Liquid templating language
76
104
  email:
77
105
  - derrickreimer@gmail.com
@@ -88,20 +116,24 @@ files:
88
116
  - lib/condensation.rb
89
117
  - lib/condensation/filters.rb
90
118
  - lib/condensation/filters/advance_date_to_next.rb
119
+ - lib/condensation/filters/at_midnight.rb
91
120
  - lib/condensation/filters/days_since.rb
92
121
  - lib/condensation/filters/days_until.rb
93
122
  - lib/condensation/filters/default.rb
94
123
  - lib/condensation/filters/hyperlink.rb
124
+ - lib/condensation/filters/in_time_zone.rb
95
125
  - lib/condensation/filters/replace_inner_html.rb
96
126
  - lib/condensation/filters/strip_commas.rb
97
127
  - lib/condensation/filters/url_encode.rb
98
128
  - lib/condensation/sanitizer.rb
99
129
  - lib/condensation/version.rb
100
130
  - spec/condensation/filters/advance_date_to_next_spec.rb
131
+ - spec/condensation/filters/at_midnight_spec.rb
101
132
  - spec/condensation/filters/days_since_spec.rb
102
133
  - spec/condensation/filters/days_until_spec.rb
103
134
  - spec/condensation/filters/default_spec.rb
104
135
  - spec/condensation/filters/hyperlink_spec.rb
136
+ - spec/condensation/filters/in_time_zone_spec.rb
105
137
  - spec/condensation/filters/replace_inner_html_spec.rb
106
138
  - spec/condensation/filters/strip_commas_spec.rb
107
139
  - spec/condensation/filters/url_encode_spec.rb
@@ -134,10 +166,12 @@ summary: Condensation is a collection of handy extensions to the Liquid templati
134
166
  language
135
167
  test_files:
136
168
  - spec/condensation/filters/advance_date_to_next_spec.rb
169
+ - spec/condensation/filters/at_midnight_spec.rb
137
170
  - spec/condensation/filters/days_since_spec.rb
138
171
  - spec/condensation/filters/days_until_spec.rb
139
172
  - spec/condensation/filters/default_spec.rb
140
173
  - spec/condensation/filters/hyperlink_spec.rb
174
+ - spec/condensation/filters/in_time_zone_spec.rb
141
175
  - spec/condensation/filters/replace_inner_html_spec.rb
142
176
  - spec/condensation/filters/strip_commas_spec.rb
143
177
  - spec/condensation/filters/url_encode_spec.rb