Method: Liquid::Template#render
- Defined in:
- lib/liquid/template.rb
#render(*args) ⇒ Object
Render takes a hash with local variables.
if you use the same filters over and over again consider registering them globally with Template.register_filter
if profiling was enabled in Template#parse
then the resulting profiling information will be available via Template#profiler
Following options can be passed:
* <tt>filters</tt> : array with local filters
* <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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/liquid/template.rb', line 140 def render(*args) return '' if @root.nil? context = case args.first when Liquid::Context c = args.shift if @rethrow_errors c.exception_renderer = Liquid::RAISE_EXCEPTION_LAMBDA end c when Liquid::Drop drop = args.shift drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment) when Hash Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment) when nil Context.new(assigns, instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment) else raise ArgumentError, "Expected Hash or Liquid::Context as parameter" end output = nil case args.last when Hash = args.pop output = [:output] if [:output] static_registers = context.registers.static [:registers]&.each do |key, register| static_registers[key] = register end (context, ) when Module, Array context.add_filters(args.pop) end # Retrying a render resets resource usage context.resource_limits.reset if @profiling && context.profiler.nil? @profiler = context.profiler = Liquid::Profiler.new end context.template_name ||= name begin # render the nodelist. @root.render_to_output_buffer(context, output || +'') rescue Liquid::MemoryError => e context.handle_error(e) ensure @errors = context.errors end end |