Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Crystal 0.25.0 JSON::Any API #32

Merged
merged 1 commit into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/liquid/filters/compact.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Liquid::Filters

def self.filter(data : Any, args : Array(Any)? = nil) : Any
if (d = data.as_a?)
result = d.compact_map{ |d| d }
result = d.reject &.raw.nil?
JSON.parse(result.to_json)
else
data
Expand All @@ -16,4 +16,4 @@ module Liquid::Filters
end

FilterRegister.register "compact", Compact
end
end
4 changes: 2 additions & 2 deletions src/liquid/filters/first.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module Liquid::Filters

def self.filter(data : Any, args : Array(Any)? = nil) : Any
if (d = data.as_a?) && !d.empty?
Any.new d.first
d.first
else
data
end
end
end

FilterRegister.register "first", First
end
end
4 changes: 2 additions & 2 deletions src/liquid/filters/last.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module Liquid::Filters

def self.filter(data : Any, args : Array(Any)? = nil) : Any
if (d = data.as_a?) && !d.empty?
Any.new d.last
d.last
else
data
end
end
end

FilterRegister.register "last", Last
end
end
8 changes: 4 additions & 4 deletions src/liquid/filters/map.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Liquid::Filters

# raise error if user doesn't provide a string argument
raise FilterArgumentException.new "map filter expects argument to be a string" unless args.first.raw.is_a?(String)

if (raw = data.raw) && raw.is_a?(Array) && (first = args.first?)
result = raw.compact_map { |r| self.responds_to(r, first.as_s) }
if result.empty?
Expand All @@ -22,14 +22,14 @@ module Liquid::Filters
JSON.parse(result.to_json)
end
elsif (raw = data.raw) && raw.is_a?(Hash) && (first = args.first?)
Any.new raw[first.as_s]?
raw[first.as_s]
else
data
end
end

def self.responds_to(data, key)
if data.is_a?(Hash)
if data = data.as_h?
data[key]?
else
nil
Expand All @@ -38,4 +38,4 @@ module Liquid::Filters
end

FilterRegister.register "map", Map
end
end