condensation 1.0.5 → 1.0.6

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: a393d9eb0299b23e66c0c038680659d49c11fff8
4
- data.tar.gz: ee168fe8b748bf9b35768588f031516c0d12fad9
3
+ metadata.gz: 8d604b37c39e91d58a069c1077d28b324f2bf3a6
4
+ data.tar.gz: 4a26fbcf785eef22ba017ad16f053006ac479745
5
5
  SHA512:
6
- metadata.gz: 8477f1b77f70c36435754c7cc6afeb605fe1305f882582bbca5f1402e800a89123f980abfe87ca961233ab8c66b6abe6b2a9fdf2c1d66dc04ab5262aab8b2149
7
- data.tar.gz: d83ee28d60416959410dd61e4fc17094c465ccba94c6f324b17cf015454293e3bd12bd7859d9984afa9e3ede0b8d976696f9955384c3c7b89dee70070956a0ed
6
+ metadata.gz: fe2d89862616b7c0e79f66a7beabbd94db59fc8f36d3ed0bc68c7d13a145bf98e5e9d3419cfea171962e06621a32c170bad6a8f2444af39a0f970adaa82be5bb
7
+ data.tar.gz: 6e33fdf33b43a11b7720715140d387d6542c86ec0fa64059bfefa6ba559f544bc3192cc0c1f249652a909572d377ac109137a697c7adfef7f56c5dfd7c4b24ea
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Derrick Reimer
1
+ Copyright (c) 2013-2015 Derrick Reimer
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Condensation
2
2
 
3
- TODO: Write a gem description
3
+ A collection of handy Liquid filters. Developed for [Drip](https://www.getdrip.com).
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,21 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ To make all the filters available in your Liquid templates, place this call
22
+ in your app initialization code:
23
+
24
+ ```ruby
25
+ Condensation.register_filters
26
+ ```
27
+
28
+ For example, in a Rails app, you'll likely place this in an initializer.
29
+ To pick and choose which filters you like, just register them manually:
30
+
31
+ ```ruby
32
+ Liquid::Template.register_filter(Condensation::Filters::DaysUntil)
33
+ ```
34
+
35
+ Explore all the available filters [here](https://github.com/djreimer/condensation/tree/master/lib/condensation/filters).
22
36
 
23
37
  ## Contributing
24
38
 
data/condensation.gemspec CHANGED
@@ -22,5 +22,4 @@ 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 "quack", ">= 0.0.3"
26
25
  end
@@ -0,0 +1,33 @@
1
+ require 'time'
2
+
3
+ module Condensation
4
+ module Filters
5
+ module AdvanceDateToNext
6
+ def advance_date_to_next(input, day)
7
+ return if input.nil?
8
+
9
+ if input.is_a?(Time)
10
+ value = input
11
+ else
12
+ value = Time.parse(input) rescue nil
13
+ end
14
+
15
+ return input unless value.is_a?(Time)
16
+
17
+ days = %w{sunday monday tuesday wednesday thursday friday saturday}
18
+ day_number = days.index(day.downcase)
19
+
20
+ unless day_number
21
+ raise Liquid::ArgumentError, "#{day} is not a valid day"
22
+ end
23
+
24
+ loop do
25
+ value = value + 86400 # advance a day
26
+ break if value.wday == day_number
27
+ end
28
+
29
+ value
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,11 +1,17 @@
1
- require 'quack'
1
+ require 'time'
2
2
 
3
3
  module Condensation
4
4
  module Filters
5
5
  module DaysSince
6
6
  def days_since(input)
7
7
  return if input.nil?
8
- value = Quack(input).to_coerced
8
+
9
+ if input.is_a?(Time)
10
+ value = input
11
+ else
12
+ value = Time.parse(input) rescue nil
13
+ end
14
+
9
15
  return unless value.is_a?(Time)
10
16
 
11
17
  diff = Time.now - value
@@ -13,4 +19,4 @@ module Condensation
13
19
  end
14
20
  end
15
21
  end
16
- end
22
+ end
@@ -1,11 +1,17 @@
1
- require 'quack'
1
+ require 'time'
2
2
 
3
3
  module Condensation
4
4
  module Filters
5
5
  module DaysUntil
6
6
  def days_until(input)
7
7
  return if input.nil?
8
- value = Quack(input).to_coerced
8
+
9
+ if input.is_a?(Time)
10
+ value = input
11
+ else
12
+ value = Time.parse(input) rescue nil
13
+ end
14
+
9
15
  return unless value.is_a?(Time)
10
16
 
11
17
  diff = value - Time.now
@@ -13,4 +19,4 @@ module Condensation
13
19
  end
14
20
  end
15
21
  end
16
- end
22
+ end
@@ -4,4 +4,5 @@ require "condensation/filters/replace_inner_html"
4
4
  require "condensation/filters/days_since"
5
5
  require "condensation/filters/days_until"
6
6
  require "condensation/filters/url_encode"
7
- require "condensation/filters/strip_commas"
7
+ require "condensation/filters/strip_commas"
8
+ require "condensation/filters/advance_date_to_next"
@@ -1,3 +1,3 @@
1
1
  module Condensation
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
data/lib/condensation.rb CHANGED
@@ -11,7 +11,8 @@ module Condensation
11
11
  Filters::DaysSince,
12
12
  Filters::DaysUntil,
13
13
  Filters::UrlEncode,
14
- Filters::StripCommas
14
+ Filters::StripCommas,
15
+ Filters::AdvanceDateToNext
15
16
  ]
16
17
 
17
18
  def self.register_filters
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Condensation::Filters::AdvanceDateToNext do
4
+ def render_with_filter(template, context)
5
+ template.render(context, :filters => [Condensation::Filters::AdvanceDateToNext])
6
+ end
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
15
+
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
22
+
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
29
+
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
36
+
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
43
+
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
50
+
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
57
+
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
64
+
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
71
+ end
72
+ end
@@ -32,13 +32,6 @@ describe Condensation::Filters::DaysSince do
32
32
  result.must_equal "13"
33
33
  end
34
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
35
  it "should handle Time input" do
43
36
  created_at = Time.utc(2014, 5, 20, 0, 0, 0)
44
37
  template = Liquid::Template.parse("{{ created_at | days_since }}")
@@ -74,4 +67,4 @@ describe Condensation::Filters::DaysSince do
74
67
  result.must_equal ""
75
68
  end
76
69
  end
77
- end
70
+ end
@@ -4,4 +4,4 @@ describe Condensation do
4
4
  describe "#register_filters" do
5
5
  # TODO
6
6
  end
7
- end
7
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,4 +4,3 @@ require 'condensation'
4
4
  require 'timecop'
5
5
  require 'minitest/spec'
6
6
  require 'minitest/autorun'
7
- require 'minitest/pride'
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.5
4
+ version: 1.0.6
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-02-12 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,20 +72,6 @@ dependencies:
72
72
  - - <=
73
73
  - !ruby/object:Gem::Version
74
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
89
75
  description: A collection of handy extensions to the Liquid templating language
90
76
  email:
91
77
  - derrickreimer@gmail.com
@@ -101,6 +87,7 @@ files:
101
87
  - condensation.gemspec
102
88
  - lib/condensation.rb
103
89
  - lib/condensation/filters.rb
90
+ - lib/condensation/filters/advance_date_to_next.rb
104
91
  - lib/condensation/filters/days_since.rb
105
92
  - lib/condensation/filters/days_until.rb
106
93
  - lib/condensation/filters/default.rb
@@ -110,6 +97,7 @@ files:
110
97
  - lib/condensation/filters/url_encode.rb
111
98
  - lib/condensation/sanitizer.rb
112
99
  - lib/condensation/version.rb
100
+ - spec/condensation/filters/advance_date_to_next_spec.rb
113
101
  - spec/condensation/filters/days_since_spec.rb
114
102
  - spec/condensation/filters/days_until_spec.rb
115
103
  - spec/condensation/filters/default_spec.rb
@@ -145,6 +133,7 @@ specification_version: 4
145
133
  summary: Condensation is a collection of handy extensions to the Liquid templating
146
134
  language
147
135
  test_files:
136
+ - spec/condensation/filters/advance_date_to_next_spec.rb
148
137
  - spec/condensation/filters/days_since_spec.rb
149
138
  - spec/condensation/filters/days_until_spec.rb
150
139
  - spec/condensation/filters/default_spec.rb