def _expand(template, args, params)
raise StandardError.new("expand :for argument evaluates to nil") if params.has_key?(:for) && params[:for].nil?
context = params[:for]
old_indent = @indent
@indent = params[:indent] || @indent
noIndentNextLine = params[:_noIndentNextLine] ||
(@output.is_a?(OutputHandler) && @output.noIndentNextLine) ||
(@output.to_s.size > 0 && @output.to_s[-1] != "\n"[0])
caller = params[:_caller] || self
old_context, @context = @context, context if context
local_output = nil
if template =~ LOCAL_TEMPLATE_REGEX
tplname = $1
raise StandardError.new("Template not found: #{$1}") unless @templates[tplname]
old_output, @output = @output, OutputHandler.new(@indent, @parent.indentString)
@output.noIndentNextLine = noIndentNextLine
_call_template(tplname, @context, args, caller == self)
old_output.noIndentNextLine = false if old_output.is_a?(OutputHandler) && !old_output.noIndentNextLine
local_output, @output = @output, old_output
else
local_output = @parent.expand(template, *(args.dup << {:for => @context, :indent => @indent, :_noIndentNextLine => noIndentNextLine, :_evalOnly => true, :_caller => caller}))
end
_direct_concat(local_output) unless params[:_evalOnly]
@context = old_context if old_context
@indent = old_indent
local_output.to_s
end