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

New Liquid features: hex filters and the uuidv4 tag #3285

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/concerns/liquid_interpolatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def initialize(agent)
outer_scope[kvs.options[:variable]] = kvs.memory
end

super({}, outer_scope, { agent: agent }, true)
super({}, outer_scope, { agent: }, true)
end

def hash
Expand Down Expand Up @@ -263,6 +263,14 @@ def json(input)
JSON.dump(input)
end

def hex_encode(input)
input.to_s.unpack1('H*')
end

def hex_decode(input)
[input.to_s].pack('H*')
end

def md5(input)
Digest::MD5.hexdigest(input.to_s)
end
Expand Down Expand Up @@ -411,9 +419,16 @@ def render(context)
"\n"
end
end

class Uuidv4 < Liquid::Tag
def render(context)
SecureRandom.uuid
end
end
end
Liquid::Template.register_tag('credential', LiquidInterpolatable::Tags::Credential)
Liquid::Template.register_tag('line_break', LiquidInterpolatable::Tags::LineBreak)
Liquid::Template.register_tag('uuidv4', LiquidInterpolatable::Tags::Uuidv4)

module Blocks
# Replace every occurrence of a given regex pattern in the first
Expand Down