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 +4 -4
- data/condensation.gemspec +2 -0
- data/lib/condensation.rb +3 -1
- data/lib/condensation/filters.rb +2 -0
- data/lib/condensation/filters/advance_date_to_next.rb +3 -2
- data/lib/condensation/filters/at_midnight.rb +23 -0
- data/lib/condensation/filters/in_time_zone.rb +21 -0
- data/lib/condensation/version.rb +1 -1
- data/spec/condensation/filters/advance_date_to_next_spec.rb +53 -55
- data/spec/condensation/filters/at_midnight_spec.rb +56 -0
- data/spec/condensation/filters/days_since_spec.rb +50 -52
- data/spec/condensation/filters/days_until_spec.rb +57 -59
- data/spec/condensation/filters/default_spec.rb +30 -32
- data/spec/condensation/filters/hyperlink_spec.rb +37 -39
- data/spec/condensation/filters/in_time_zone_spec.rb +25 -0
- data/spec/condensation/filters/replace_inner_html_spec.rb +28 -30
- data/spec/condensation/filters/strip_commas_spec.rb +12 -14
- data/spec/condensation/filters/url_encode_spec.rb +12 -14
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed002bb3c91d4d84d1e35a5e082447da17adb038
|
4
|
+
data.tar.gz: b81c84fe94d9669af47b09804ad23e1149ae3685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4032dabf0ab55ce4fe55b0203795c15853e82483283c70794d8e6ac9d0e262a375e164e3aa176cdc83698a62a81e3bccf932842acec42c3e51564dde7c6db1ed
|
7
|
+
data.tar.gz: b6db0f0359271367f992b86a332d1d06817de801557f0a18fa811b6c731723ebd0d1d198f6fecf4c83565c50d8242c94d6be0d8b8fc98c59106025c90d071809
|
data/condensation.gemspec
CHANGED
data/lib/condensation.rb
CHANGED
data/lib/condensation/filters.rb
CHANGED
@@ -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
|
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
|
data/lib/condensation/version.rb
CHANGED
@@ -5,68 +5,66 @@ describe Condensation::Filters::AdvanceDateToNext do
|
|
5
5
|
template.render(context, :filters => [Condensation::Filters::AdvanceDateToNext])
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
let(:now) do
|
9
|
+
Time.utc(2014, 5, 30, 0, 0, 0)
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
before do
|
13
|
+
Timecop.freeze(now)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
after do
|
17
|
+
Timecop.return
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
let(:now) do
|
9
|
+
Time.utc(2014, 5, 15, 0, 0, 0)
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
before do
|
13
|
+
Timecop.freeze(now)
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
after do
|
17
|
+
Timecop.return
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
it "should escape HTML in the URL" do
|
23
|
+
url = "<script>attack.me()</script>"
|
24
|
+
escaped = "<script>attack.me()</script>"
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
it "should escape HTML in the anchor text" do
|
31
|
+
url = "http://www.example.com"
|
32
|
+
text = "<script>attack.me()</script>"
|
33
|
+
escaped = "<script>attack.me()</script>"
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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.
|
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
|
+
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
|