Browse Source

Add a Liquid tag: uuidv4

Akinori MUSHA 1 year ago
parent
commit
89474e6933
1 changed files with 7 additions and 0 deletions
  1. 7 0
      app/concerns/liquid_interpolatable.rb

+ 7 - 0
app/concerns/liquid_interpolatable.rb

@@ -419,9 +419,16 @@ module LiquidInterpolatable
         "\n"
         "\n"
       end
       end
     end
     end
+
+    class Uuidv4 < Liquid::Tag
+      def render(context)
+        SecureRandom.uuid
+      end
+    end
   end
   end
   Liquid::Template.register_tag('credential', LiquidInterpolatable::Tags::Credential)
   Liquid::Template.register_tag('credential', LiquidInterpolatable::Tags::Credential)
   Liquid::Template.register_tag('line_break', LiquidInterpolatable::Tags::LineBreak)
   Liquid::Template.register_tag('line_break', LiquidInterpolatable::Tags::LineBreak)
+  Liquid::Template.register_tag('uuidv4', LiquidInterpolatable::Tags::Uuidv4)
 
 
   module Blocks
   module Blocks
     # Replace every occurrence of a given regex pattern in the first
     # Replace every occurrence of a given regex pattern in the first