lib/liquid/template.rb in liquid-2.5.5 vs lib/liquid/template.rb in liquid-2.6.0.rc1

- old
+ new

@@ -12,11 +12,11 @@ # # template = Liquid::Template.parse(source) # template.render('user_name' => 'bob') # class Template - attr_accessor :root + attr_accessor :root, :resource_limits @@file_system = BlankFileSystem.new class << self def file_system @@file_system @@ -48,10 +48,11 @@ end end # creates a new <tt>Template</tt> from an array of tokens. Use <tt>Template.parse</tt> instead def initialize + @resource_limits = {} end # Parse source code. # Returns self for easy chaining def parse(source) @@ -86,18 +87,21 @@ # * <tt>registers</tt> : hash with register variables. Those can be accessed from # filters and tags and might be useful to integrate liquid more with its host application # def render(*args) return '' if @root.nil? - + context = case args.first when Liquid::Context args.shift + when Liquid::Drop + drop = args.shift + drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits) when Hash - Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors) + Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits) when nil - Context.new(assigns, instance_assigns, registers, @rethrow_errors) + Context.new(assigns, instance_assigns, registers, @rethrow_errors, @resource_limits) else raise ArgumentError, "Expect Hash or Liquid::Context as parameter" end case args.last @@ -118,12 +122,14 @@ context.add_filters(args.pop) end begin # render the nodelist. - # for performance reasons we get a array back here. join will make a string out of it + # for performance reasons we get an array back here. join will make a string out of it. result = @root.render(context) result.respond_to?(:join) ? result.join : result + rescue Liquid::MemoryError => e + context.handle_error(e) ensure @errors = context.errors end end