condensation 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 100a7ec169473d6bc18ceebf8e459dd81fa74efb
4
+ data.tar.gz: 359b33cebf4f95b71a70b3afd670cb7965881344
5
+ SHA512:
6
+ metadata.gz: f58303213c28f48e3bf7edbfac7be3c1fced506610676592e69a1884521278046e30548f5e723830e0122f3d9a560c98e7ae4f2413e638222aaf8e9cfe4433cc
7
+ data.tar.gz: 4148402c80d022dc40e28152dd38e763df026f587c77948440009a4597c4bda3f0b125daf5dce3d405a792bf7737241ecb483f8e0ac7fabe7536f3fd69617324
data/condensation.gemspec CHANGED
@@ -3,19 +3,24 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'condensation/version'
5
5
 
6
- Gem::Specification.new do |gem|
7
- gem.name = "condensation"
8
- gem.version = Condensation::VERSION
9
- gem.authors = ["Derrick Reimer"]
10
- gem.email = ["derrickreimer@gmail.com"]
11
- gem.description = %q{A collection of handy extensions to the Liquid templating language}
12
- gem.summary = %q{Condensation is a collection of handy extensions to the Liquid templating language}
13
- gem.homepage = "https://github.com/djreimer/condensation"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "condensation"
8
+ spec.version = Condensation::VERSION
9
+ spec.authors = ["Derrick Reimer"]
10
+ spec.email = ["derrickreimer@gmail.com"]
11
+ spec.description = %q{A collection of handy extensions to the Liquid templating language}
12
+ spec.summary = %q{Condensation is a collection of handy extensions to the Liquid templating language}
13
+ spec.homepage = "https://github.com/djreimer/condensation"
14
14
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency "liquid", "~> 2.0"
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "timecop", "~> 0.7"
23
+
24
+ spec.add_dependency "liquid", [">= 2.0", "<= 4.0"]
25
+ spec.add_dependency "quack", ">= 0.0.3"
21
26
  end
data/lib/condensation.rb CHANGED
@@ -7,7 +7,9 @@ module Condensation
7
7
  FILTERS = [
8
8
  Filters::Default,
9
9
  Filters::Hyperlink,
10
- Filters::ReplaceInnerHTML
10
+ Filters::ReplaceInnerHTML,
11
+ Filters::DaysSince,
12
+ Filters::DaysUntil
11
13
  ]
12
14
 
13
15
  def self.register_filters
@@ -1,3 +1,5 @@
1
1
  require "condensation/filters/default"
2
2
  require "condensation/filters/hyperlink"
3
- require "condensation/filters/replace_inner_html"
3
+ require "condensation/filters/replace_inner_html"
4
+ require "condensation/filters/days_since"
5
+ require "condensation/filters/days_until"
@@ -0,0 +1,16 @@
1
+ require 'quack'
2
+
3
+ module Condensation
4
+ module Filters
5
+ module DaysSince
6
+ def days_since(input)
7
+ return if input.nil?
8
+ value = Quack(input).to_coerced
9
+ return unless value.is_a?(Time)
10
+
11
+ diff = Time.now - value
12
+ [diff.to_i / 86400, 0].max
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'quack'
2
+
3
+ module Condensation
4
+ module Filters
5
+ module DaysUntil
6
+ def days_until(input)
7
+ return if input.nil?
8
+ value = Quack(input).to_coerced
9
+ return unless value.is_a?(Time)
10
+
11
+ diff = value - Time.now
12
+ [diff.to_i / 86400, 0].max
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Condensation
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Condensation::Filters::DaysSince do
4
+ def render_with_filter(template, context)
5
+ template.render(context, :filters => [Condensation::Filters::DaysSince])
6
+ end
7
+
8
+ describe "#days_since" do
9
+ let(:now) do
10
+ Time.utc(2014, 5, 30, 0, 0, 0)
11
+ end
12
+
13
+ before do
14
+ Timecop.freeze(now)
15
+ end
16
+
17
+ after do
18
+ Timecop.return
19
+ end
20
+
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
27
+
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
34
+
35
+ it "should handle YMD formatted dates" do
36
+ created_at = "2014-05-15"
37
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
38
+ result = render_with_filter(template, { "created_at" => created_at })
39
+ result.must_equal "15"
40
+ end
41
+
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_since }}")
45
+ result = render_with_filter(template, { "created_at" => created_at })
46
+ result.must_equal "10"
47
+ end
48
+
49
+ it "should handle malformed dates" do
50
+ created_at = "foo"
51
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
52
+ result = render_with_filter(template, { "created_at" => created_at })
53
+ result.must_equal ""
54
+ end
55
+
56
+ it "should be zero for days in the future" do
57
+ created_at = "2014-06-01T20:00:00Z"
58
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
59
+ result = render_with_filter(template, { "created_at" => created_at })
60
+ result.must_equal "0"
61
+ end
62
+
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
69
+
70
+ it "should handle nil input" do
71
+ created_at = nil
72
+ template = Liquid::Template.parse("{{ created_at | days_since }}")
73
+ result = render_with_filter(template, { "created_at" => created_at })
74
+ result.must_equal ""
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Condensation::Filters::DaysUntil do
4
+ def render_with_filter(template, context)
5
+ template.render(context, :filters => [Condensation::Filters::DaysUntil])
6
+ end
7
+
8
+ describe "#days_until" do
9
+ let(:now) do
10
+ Time.utc(2014, 5, 15, 0, 0, 0)
11
+ end
12
+
13
+ before do
14
+ Timecop.freeze(now)
15
+ end
16
+
17
+ after do
18
+ Timecop.return
19
+ end
20
+
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
27
+
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
34
+
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
41
+
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
48
+
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
55
+
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
62
+
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
69
+
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
76
+ end
77
+ end
@@ -4,7 +4,7 @@ describe Condensation::Sanitizer do
4
4
  describe "#escape_html" do
5
5
  it "should escape HTML entities" do
6
6
  html = "<div><a href='http://foo.bar/?x=r%20b&y=z'>Baz</a></div>"
7
- escaped = "&lt;div&gt;&lt;a href='http://foo.bar/?x=r%20b&amp;y=z'&gt;Baz&lt;/a&gt;&lt;/div&gt;"
7
+ escaped = "&lt;div&gt;&lt;a href=&#39;http://foo.bar/?x=r%20b&amp;y=z&#39;&gt;Baz&lt;/a&gt;&lt;/div&gt;"
8
8
  Condensation::Sanitizer.new(html).escape_html.must_equal(escaped)
9
9
  end
10
10
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $:.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
3
  require 'condensation'
4
+ require 'timecop'
4
5
  require 'minitest/spec'
5
6
  require 'minitest/autorun'
6
7
  require 'minitest/pride'
metadata CHANGED
@@ -1,32 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: condensation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Derrick Reimer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-09 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: liquid
14
+ name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: timecop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: liquid
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
20
60
  - !ruby/object:Gem::Version
21
61
  version: '2.0'
62
+ - - <=
63
+ - !ruby/object:Gem::Version
64
+ version: '4.0'
22
65
  type: :runtime
23
66
  prerelease: false
24
67
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
68
  requirements:
27
- - - ~>
69
+ - - '>='
28
70
  - !ruby/object:Gem::Version
29
71
  version: '2.0'
72
+ - - <=
73
+ - !ruby/object:Gem::Version
74
+ version: '4.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: quack
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: 0.0.3
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: 0.0.3
30
89
  description: A collection of handy extensions to the Liquid templating language
31
90
  email:
32
91
  - derrickreimer@gmail.com
@@ -42,11 +101,15 @@ files:
42
101
  - condensation.gemspec
43
102
  - lib/condensation.rb
44
103
  - lib/condensation/filters.rb
104
+ - lib/condensation/filters/days_since.rb
105
+ - lib/condensation/filters/days_until.rb
45
106
  - lib/condensation/filters/default.rb
46
107
  - lib/condensation/filters/hyperlink.rb
47
108
  - lib/condensation/filters/replace_inner_html.rb
48
109
  - lib/condensation/sanitizer.rb
49
110
  - lib/condensation/version.rb
111
+ - spec/condensation/filters/days_since_spec.rb
112
+ - spec/condensation/filters/days_until_spec.rb
50
113
  - spec/condensation/filters/default_spec.rb
51
114
  - spec/condensation/filters/hyperlink_spec.rb
52
115
  - spec/condensation/filters/replace_inner_html_spec.rb
@@ -55,30 +118,31 @@ files:
55
118
  - spec/spec_helper.rb
56
119
  homepage: https://github.com/djreimer/condensation
57
120
  licenses: []
121
+ metadata: {}
58
122
  post_install_message:
59
123
  rdoc_options: []
60
124
  require_paths:
61
125
  - lib
62
126
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
127
  requirements:
65
- - - ! '>='
128
+ - - '>='
66
129
  - !ruby/object:Gem::Version
67
130
  version: '0'
68
131
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
132
  requirements:
71
- - - ! '>='
133
+ - - '>='
72
134
  - !ruby/object:Gem::Version
73
135
  version: '0'
74
136
  requirements: []
75
137
  rubyforge_project:
76
- rubygems_version: 1.8.23
138
+ rubygems_version: 2.0.3
77
139
  signing_key:
78
- specification_version: 3
140
+ specification_version: 4
79
141
  summary: Condensation is a collection of handy extensions to the Liquid templating
80
142
  language
81
143
  test_files:
144
+ - spec/condensation/filters/days_since_spec.rb
145
+ - spec/condensation/filters/days_until_spec.rb
82
146
  - spec/condensation/filters/default_spec.rb
83
147
  - spec/condensation/filters/hyperlink_spec.rb
84
148
  - spec/condensation/filters/replace_inner_html_spec.rb