Skip to content

Commit

Permalink
Merge pull request #3285 from huginn/liquid_features
Browse files Browse the repository at this point in the history
New Liquid features: hex filters and the uuidv4 tag
  • Loading branch information
knu committed Jun 27, 2023
2 parents ba93bdf + 89474e6 commit 8439a77
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/concerns/liquid_interpolatable.rb
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

0 comments on commit 8439a77

Please sign in to comment.