condensation 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +35 -0
  4. data/Rakefile +6 -6
  5. data/condensation.gemspec +18 -16
  6. data/lib/condensation.rb +9 -7
  7. data/lib/condensation/extensions.rb +7 -5
  8. data/lib/condensation/filters.rb +15 -13
  9. data/lib/condensation/filters/advance_date_to_next.rb +13 -9
  10. data/lib/condensation/filters/at_midnight.rb +12 -8
  11. data/lib/condensation/filters/days_since.rb +10 -6
  12. data/lib/condensation/filters/days_until.rb +10 -6
  13. data/lib/condensation/filters/default.rb +2 -2
  14. data/lib/condensation/filters/hmac_sha256.rb +12 -0
  15. data/lib/condensation/filters/hyperlink.rb +1 -1
  16. data/lib/condensation/filters/in_time_zone.rb +6 -6
  17. data/lib/condensation/filters/md5.rb +12 -0
  18. data/lib/condensation/filters/replace_inner_html.rb +4 -4
  19. data/lib/condensation/filters/strip_commas.rb +2 -2
  20. data/lib/condensation/filters/url_encode.rb +4 -2
  21. data/lib/condensation/filters/weeks_since.rb +10 -6
  22. data/lib/condensation/filters/weeks_until.rb +10 -6
  23. data/lib/condensation/sanitizer.rb +4 -2
  24. data/lib/condensation/version.rb +1 -1
  25. data/spec/condensation/filters/advance_date_to_next_spec.rb +39 -39
  26. data/spec/condensation/filters/at_midnight_spec.rb +29 -29
  27. data/spec/condensation/filters/days_since_spec.rb +34 -34
  28. data/spec/condensation/filters/days_until_spec.rb +39 -39
  29. data/spec/condensation/filters/default_spec.rb +19 -19
  30. data/spec/condensation/filters/hmac_sha256_spec.rb +21 -0
  31. data/spec/condensation/filters/hyperlink_spec.rb +23 -23
  32. data/spec/condensation/filters/in_time_zone_spec.rb +10 -10
  33. data/spec/condensation/filters/md5_spec.rb +21 -0
  34. data/spec/condensation/filters/replace_inner_html_spec.rb +10 -10
  35. data/spec/condensation/filters/strip_commas_spec.rb +10 -10
  36. data/spec/condensation/filters/timestamp_spec.rb +34 -34
  37. data/spec/condensation/filters/url_encode_spec.rb +10 -10
  38. data/spec/condensation/filters/weeks_since_spec.rb +34 -34
  39. data/spec/condensation/filters/weeks_until_spec.rb +39 -39
  40. data/spec/condensation/sanitizer_spec.rb +4 -4
  41. data/spec/condensation_spec.rb +1 -1
  42. data/spec/spec_helper.rb +1 -2
  43. metadata +25 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76647a5c86012dfbc8e56b16b210893382871c36
4
- data.tar.gz: 64c167153dced332fa7c915d008d5f2e3f1aa98c
3
+ metadata.gz: 8f1fc238e94b6ed78688679e5258b5de1a4bdeec
4
+ data.tar.gz: faded351dffa8b78127cc7221daf69861de772c7
5
5
  SHA512:
6
- metadata.gz: c9c711c1c42cf92bb2219e185a4f3d07db9210c458200bd506d2acb8b8bd9fea924f97e607919b60b88bf899502db0dc60ebda13068f8a262a2bc1625455a917
7
- data.tar.gz: 334c47c35f48dcbafaaec1f4e392170d2818faaebd62b415eedb7541fbb68e6fb115f04b1110f4f4800b79823f4a19651fe8a438841ddb1c79ddf6add5d7cf2d
6
+ metadata.gz: 340054883d1472243c64e5c3f9d4f37561157858dd07b0a4c2df2a5607b4d51879b141f2e74dda7a9b81de74bc56052eec5d719f79b9b81e1e8b49a27d416096
7
+ data.tar.gz: 8e25341b31217b68a6a17ef28398669e6e965f292b56ecc385979c7e044ec1aafe5837616406bdbbffba69d46088905718c8bfe6e6eb92f7f7d61d858e42032a
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -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 "bundler/gem_tasks"
3
- require "rake/testtask"
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
4
 
5
5
  Rake::TestTask.new do |t|
6
- t.libs << "lib"
7
- t.pattern = "spec/**/*_spec.rb"
6
+ t.libs << 'lib'
7
+ t.pattern = 'spec/**/*_spec.rb'
8
8
  t.verbose = true
9
9
  end
10
10
 
11
- desc "Run tests"
12
- task :default => :test
11
+ desc 'Run tests'
12
+ task default: :test
@@ -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 = "condensation"
8
+ spec.name = 'condensation'
8
9
  spec.version = Condensation::VERSION
9
- spec.authors = ["Derrick Reimer"]
10
- spec.licenses = ["MIT"]
11
- spec.email = ["derrickreimer@gmail.com"]
12
- spec.description = %q{A collection of handy extensions to the Liquid templating language}
13
- spec.summary = %q{Condensation is a collection of handy extensions to the Liquid templating language}
14
- spec.homepage = "https://github.com/djreimer/condensation"
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 = ["lib"]
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_development_dependency "bundler"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "timecop"
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 "liquid", [">= 2.0", "<= 4.0"]
26
- spec.add_dependency "tzinfo", "~> 1"
27
- spec.add_dependency "activesupport", ">= 3.0"
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
@@ -1,8 +1,8 @@
1
- require "liquid"
2
- require "condensation/extensions"
3
- require "condensation/sanitizer"
4
- require "condensation/filters"
5
- require "condensation/version"
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 "active_support/time_with_zone"
2
- require "active_support/core_ext/time/calculations"
1
+ require 'active_support/time_with_zone'
2
+ require 'active_support/core_ext/time/calculations'
3
3
 
4
- class ActiveSupport::TimeWithZone
5
- def to_liquid
6
- self
4
+ module ActiveSupport
5
+ class TimeWithZone
6
+ def to_liquid
7
+ self
8
+ end
7
9
  end
8
10
  end
@@ -1,13 +1,15 @@
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"
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 "active_support/time_with_zone"
2
- require "active_support/core_ext/time/calculations"
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
- value = input
12
- else
13
- value = Time.parse(input) rescue nil
14
- end
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{sunday monday tuesday wednesday thursday friday saturday}
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 = value + 86400 # advance a day
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 "active_support/time_with_zone"
2
- require "active_support/core_ext/time/calculations"
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
- value = input
12
- else
13
- value = Time.parse(input) rescue nil
14
- end
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
- alias_method :beginning_of_day, :at_midnight
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 = 86400
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
- value = input
13
- else
14
- value = Time.parse(input) rescue nil
15
- end
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 = 86400
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
- value = input
13
- else
14
- value = Time.parse(input) rescue nil
15
- end
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
@@ -0,0 +1,12 @@
1
+ require 'openssl'
2
+
3
+ module Condensation
4
+ module Filters
5
+ module HmacSha256
6
+ def hmac_sha256(input, secret_key)
7
+ return if input.nil?
8
+ OpenSSL::HMAC.hexdigest('SHA256', secret_key, input)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -9,4 +9,4 @@ module Condensation
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -1,5 +1,5 @@
1
- require "active_support/time_with_zone"
2
- require "active_support/core_ext/time/calculations"
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
- input.in_time_zone(zone)
13
- else
14
- zone.parse(input)
15
- end
12
+ input.in_time_zone(zone)
13
+ else
14
+ zone.parse(input)
15
+ end
16
16
 
17
17
  converted_time
18
18
  end
@@ -0,0 +1,12 @@
1
+ require 'digest'
2
+
3
+ module Condensation
4
+ module Filters
5
+ module MD5
6
+ def md5(input)
7
+ return if input.nil?
8
+ Digest::MD5.hexdigest(input)
9
+ end
10
+ end
11
+ end
12
+ 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(/\A(<\S.*>)(.*)(<\/\S*>)\z/) do
7
- "#{$1}#{inner_html}#{$3}"
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,8 +3,8 @@ module Condensation
3
3
  module StripCommas
4
4
  def strip_commas(input)
5
5
  return if input.nil?
6
- input.gsub(",", "")
6
+ input.delete(',')
7
7
  end
8
8
  end
9
9
  end
10
- end
10
+ end
@@ -2,8 +2,10 @@ module Condensation
2
2
  module Filters
3
3
  module UrlEncode
4
4
  def url_encode(input)
5
- CGI.escape(input) rescue input
5
+ CGI.escape(input)
6
+ rescue
7
+ input
6
8
  end
7
9
  end
8
10
  end
9
- end
11
+ end
@@ -3,16 +3,20 @@ require 'time'
3
3
  module Condensation
4
4
  module Filters
5
5
  module WeeksSince
6
- SECONDS_PER_WEEK = 86400 * 7
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
- value = input
13
- else
14
- value = Time.parse(input) rescue nil
15
- end
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