condensation 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +35 -0
- data/Rakefile +6 -6
- data/condensation.gemspec +18 -16
- data/lib/condensation.rb +9 -7
- data/lib/condensation/extensions.rb +7 -5
- data/lib/condensation/filters.rb +15 -13
- data/lib/condensation/filters/advance_date_to_next.rb +13 -9
- data/lib/condensation/filters/at_midnight.rb +12 -8
- data/lib/condensation/filters/days_since.rb +10 -6
- data/lib/condensation/filters/days_until.rb +10 -6
- data/lib/condensation/filters/default.rb +2 -2
- data/lib/condensation/filters/hmac_sha256.rb +12 -0
- data/lib/condensation/filters/hyperlink.rb +1 -1
- data/lib/condensation/filters/in_time_zone.rb +6 -6
- data/lib/condensation/filters/md5.rb +12 -0
- data/lib/condensation/filters/replace_inner_html.rb +4 -4
- data/lib/condensation/filters/strip_commas.rb +2 -2
- data/lib/condensation/filters/url_encode.rb +4 -2
- data/lib/condensation/filters/weeks_since.rb +10 -6
- data/lib/condensation/filters/weeks_until.rb +10 -6
- data/lib/condensation/sanitizer.rb +4 -2
- data/lib/condensation/version.rb +1 -1
- data/spec/condensation/filters/advance_date_to_next_spec.rb +39 -39
- data/spec/condensation/filters/at_midnight_spec.rb +29 -29
- data/spec/condensation/filters/days_since_spec.rb +34 -34
- data/spec/condensation/filters/days_until_spec.rb +39 -39
- data/spec/condensation/filters/default_spec.rb +19 -19
- data/spec/condensation/filters/hmac_sha256_spec.rb +21 -0
- data/spec/condensation/filters/hyperlink_spec.rb +23 -23
- data/spec/condensation/filters/in_time_zone_spec.rb +10 -10
- data/spec/condensation/filters/md5_spec.rb +21 -0
- data/spec/condensation/filters/replace_inner_html_spec.rb +10 -10
- data/spec/condensation/filters/strip_commas_spec.rb +10 -10
- data/spec/condensation/filters/timestamp_spec.rb +34 -34
- data/spec/condensation/filters/url_encode_spec.rb +10 -10
- data/spec/condensation/filters/weeks_since_spec.rb +34 -34
- data/spec/condensation/filters/weeks_until_spec.rb +39 -39
- data/spec/condensation/sanitizer_spec.rb +4 -4
- data/spec/condensation_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -2
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f1fc238e94b6ed78688679e5258b5de1a4bdeec
|
4
|
+
data.tar.gz: faded351dffa8b78127cc7221daf69861de772c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 340054883d1472243c64e5c3f9d4f37561157858dd07b0a4c2df2a5607b4d51879b141f2e74dda7a9b81de74bc56052eec5d719f79b9b81e1e8b49a27d416096
|
7
|
+
data.tar.gz: 8e25341b31217b68a6a17ef28398669e6e965f292b56ecc385979c7e044ec1aafe5837616406bdbbffba69d46088905718c8bfe6e6eb92f7f7d61d858e42032a
|
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-10-19 14:17:34 -0500 using RuboCop version 0.48.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 10
|
10
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Max: 60
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
Metrics/CyclomaticComplexity:
|
16
|
+
Max: 7
|
17
|
+
|
18
|
+
# Offense count: 24
|
19
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
20
|
+
# URISchemes: http, https
|
21
|
+
Metrics/LineLength:
|
22
|
+
Max: 107
|
23
|
+
|
24
|
+
# Offense count: 6
|
25
|
+
# Configuration parameters: CountComments.
|
26
|
+
Metrics/MethodLength:
|
27
|
+
Max: 21
|
28
|
+
|
29
|
+
# Offense count: 1
|
30
|
+
Metrics/PerceivedComplexity:
|
31
|
+
Max: 8
|
32
|
+
|
33
|
+
# Offense count: 18
|
34
|
+
Style/Documentation:
|
35
|
+
Enabled: false
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake/testtask'
|
4
4
|
|
5
5
|
Rake::TestTask.new do |t|
|
6
|
-
t.libs <<
|
7
|
-
t.pattern =
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.pattern = 'spec/**/*_spec.rb'
|
8
8
|
t.verbose = true
|
9
9
|
end
|
10
10
|
|
11
|
-
desc
|
12
|
-
task :
|
11
|
+
desc 'Run tests'
|
12
|
+
task default: :test
|
data/condensation.gemspec
CHANGED
@@ -1,28 +1,30 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'condensation/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'condensation'
|
8
9
|
spec.version = Condensation::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.licenses = [
|
11
|
-
spec.email = [
|
12
|
-
spec.description =
|
13
|
-
spec.summary =
|
14
|
-
spec.homepage =
|
10
|
+
spec.authors = ['Derrick Reimer']
|
11
|
+
spec.licenses = ['MIT']
|
12
|
+
spec.email = ['derrickreimer@gmail.com']
|
13
|
+
spec.description = 'A collection of handy extensions to the Liquid templating language'
|
14
|
+
spec.summary = 'Condensation is a collection of handy extensions to the Liquid templating language'
|
15
|
+
spec.homepage = 'https://github.com/djreimer/condensation'
|
15
16
|
|
16
|
-
spec.files = `git ls-files`.split(
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
20
21
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'timecop'
|
25
|
+
spec.add_development_dependency 'rubocop'
|
24
26
|
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
27
|
-
spec.add_dependency
|
27
|
+
spec.add_dependency 'liquid', ['>= 2.0', '<= 4.0']
|
28
|
+
spec.add_dependency 'tzinfo', '~> 1'
|
29
|
+
spec.add_dependency 'activesupport', '>= 3.0'
|
28
30
|
end
|
data/lib/condensation.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'liquid'
|
2
|
+
require 'condensation/extensions'
|
3
|
+
require 'condensation/sanitizer'
|
4
|
+
require 'condensation/filters'
|
5
|
+
require 'condensation/version'
|
6
6
|
|
7
7
|
module Condensation
|
8
8
|
FILTERS = [
|
@@ -18,8 +18,10 @@ module Condensation
|
|
18
18
|
Filters::InTimeZone,
|
19
19
|
Filters::Timestamp,
|
20
20
|
Filters::WeeksSince,
|
21
|
-
Filters::WeeksUntil
|
22
|
-
|
21
|
+
Filters::WeeksUntil,
|
22
|
+
Filters::MD5,
|
23
|
+
Filters::HmacSha256
|
24
|
+
].freeze
|
23
25
|
|
24
26
|
def self.register_filters
|
25
27
|
FILTERS.each do |filter|
|
@@ -1,8 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'active_support/time_with_zone'
|
2
|
+
require 'active_support/core_ext/time/calculations'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module ActiveSupport
|
5
|
+
class TimeWithZone
|
6
|
+
def to_liquid
|
7
|
+
self
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
data/lib/condensation/filters.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
1
|
+
require 'condensation/filters/default'
|
2
|
+
require 'condensation/filters/hyperlink'
|
3
|
+
require 'condensation/filters/replace_inner_html'
|
4
|
+
require 'condensation/filters/days_since'
|
5
|
+
require 'condensation/filters/days_until'
|
6
|
+
require 'condensation/filters/url_encode'
|
7
|
+
require 'condensation/filters/strip_commas'
|
8
|
+
require 'condensation/filters/advance_date_to_next'
|
9
|
+
require 'condensation/filters/at_midnight'
|
10
|
+
require 'condensation/filters/in_time_zone'
|
11
|
+
require 'condensation/filters/timestamp'
|
12
|
+
require 'condensation/filters/weeks_since'
|
13
|
+
require 'condensation/filters/weeks_until'
|
14
|
+
require 'condensation/filters/md5'
|
15
|
+
require 'condensation/filters/hmac_sha256'
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'active_support/time_with_zone'
|
2
|
+
require 'active_support/core_ext/time/calculations'
|
3
3
|
|
4
4
|
module Condensation
|
5
5
|
module Filters
|
@@ -7,15 +7,19 @@ module Condensation
|
|
7
7
|
def advance_date_to_next(input, day)
|
8
8
|
return if input.nil?
|
9
9
|
|
10
|
-
if input.is_a?(Time)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
value = if input.is_a?(Time)
|
11
|
+
input
|
12
|
+
else
|
13
|
+
begin
|
14
|
+
Time.parse(input)
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
15
19
|
|
16
20
|
return input unless value.is_a?(Time)
|
17
21
|
|
18
|
-
days = %w
|
22
|
+
days = %w[sunday monday tuesday wednesday thursday friday saturday]
|
19
23
|
day_number = days.index(day.downcase)
|
20
24
|
|
21
25
|
unless day_number
|
@@ -23,7 +27,7 @@ module Condensation
|
|
23
27
|
end
|
24
28
|
|
25
29
|
loop do
|
26
|
-
value
|
30
|
+
value += 86_400 # advance a day
|
27
31
|
break if value.wday == day_number
|
28
32
|
end
|
29
33
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'active_support/time_with_zone'
|
2
|
+
require 'active_support/core_ext/time/calculations'
|
3
3
|
|
4
4
|
module Condensation
|
5
5
|
module Filters
|
@@ -7,17 +7,21 @@ module Condensation
|
|
7
7
|
def at_midnight(input)
|
8
8
|
return if input.nil?
|
9
9
|
|
10
|
-
if input.is_a?(Time)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
value = if input.is_a?(Time)
|
11
|
+
input
|
12
|
+
else
|
13
|
+
begin
|
14
|
+
Time.parse(input)
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
15
19
|
|
16
20
|
return input unless value.is_a?(Time)
|
17
21
|
value.at_midnight
|
18
22
|
end
|
19
23
|
|
20
|
-
|
24
|
+
alias beginning_of_day at_midnight
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
@@ -3,16 +3,20 @@ require 'time'
|
|
3
3
|
module Condensation
|
4
4
|
module Filters
|
5
5
|
module DaysSince
|
6
|
-
SECONDS_PER_DAY =
|
6
|
+
SECONDS_PER_DAY = 86_400
|
7
7
|
|
8
8
|
def days_since(input)
|
9
9
|
return if input.nil?
|
10
10
|
|
11
|
-
if input.is_a?(Time)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
value = if input.is_a?(Time)
|
12
|
+
input
|
13
|
+
else
|
14
|
+
begin
|
15
|
+
Time.parse(input)
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
16
20
|
|
17
21
|
return unless value.is_a?(Time)
|
18
22
|
|
@@ -3,16 +3,20 @@ require 'time'
|
|
3
3
|
module Condensation
|
4
4
|
module Filters
|
5
5
|
module DaysUntil
|
6
|
-
SECONDS_PER_DAY =
|
6
|
+
SECONDS_PER_DAY = 86_400
|
7
7
|
|
8
8
|
def days_until(input)
|
9
9
|
return if input.nil?
|
10
10
|
|
11
|
-
if input.is_a?(Time)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
value = if input.is_a?(Time)
|
12
|
+
input
|
13
|
+
else
|
14
|
+
begin
|
15
|
+
Time.parse(input)
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
16
20
|
|
17
21
|
return unless value.is_a?(Time)
|
18
22
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Condensation
|
2
2
|
module Filters
|
3
3
|
module Default
|
4
|
-
def default(input, default_value =
|
4
|
+
def default(input, default_value = '')
|
5
5
|
is_blank = input.respond_to?(:empty?) ? input.empty? : !input
|
6
6
|
is_blank ? default_value : input
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
10
|
-
end
|
10
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'active_support/time_with_zone'
|
2
|
+
require 'active_support/core_ext/time/calculations'
|
3
3
|
|
4
4
|
module Condensation
|
5
5
|
module Filters
|
@@ -9,10 +9,10 @@ module Condensation
|
|
9
9
|
return input if zone.nil?
|
10
10
|
|
11
11
|
converted_time = if input.is_a?(Time)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
input.in_time_zone(zone)
|
13
|
+
else
|
14
|
+
zone.parse(input)
|
15
|
+
end
|
16
16
|
|
17
17
|
converted_time
|
18
18
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Condensation
|
2
2
|
module Filters
|
3
3
|
module ReplaceInnerHTML
|
4
|
-
def replace_inner_html(input, inner_html =
|
4
|
+
def replace_inner_html(input, inner_html = '')
|
5
5
|
return if input.nil?
|
6
|
-
input.to_s.gsub(
|
7
|
-
"#{
|
6
|
+
input.to_s.gsub(%r{\A(<\S.*>)(.*)(<\/\S*>)\z}) do
|
7
|
+
"#{Regexp.last_match(1)}#{inner_html}#{Regexp.last_match(3)}"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
|
-
end
|
12
|
+
end
|
@@ -3,16 +3,20 @@ require 'time'
|
|
3
3
|
module Condensation
|
4
4
|
module Filters
|
5
5
|
module WeeksSince
|
6
|
-
SECONDS_PER_WEEK =
|
6
|
+
SECONDS_PER_WEEK = 86_400 * 7
|
7
7
|
|
8
8
|
def weeks_since(input)
|
9
9
|
return if input.nil?
|
10
10
|
|
11
|
-
if input.is_a?(Time)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
value = if input.is_a?(Time)
|
12
|
+
input
|
13
|
+
else
|
14
|
+
begin
|
15
|
+
Time.parse(input)
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
16
20
|
|
17
21
|
return unless value.is_a?(Time)
|
18
22
|
|