class Railroader::TemplateProcessor
Base Processor for templates/views
Public Class Methods
new(tracker, template_name, called_from = nil, file_name = nil)
click to toggle source
Initializes template information.
Calls superclass method
Railroader::BaseProcessor::new
# File lib/railroader/processors/template_processor.rb, line 8 def initialize tracker, template_name, called_from = nil, file_name = nil super(tracker) @current_template = Railroader::Template.new template_name, called_from, file_name, tracker @file_name = file_name if called_from template_name = (template_name.to_s + "." + called_from.to_s).to_sym end tracker.templates[template_name] = @current_template @inside_concat = false end
Public Instance Methods
add_escaped_output(output)
click to toggle source
# File lib/railroader/processors/template_processor.rb, line 75 def add_escaped_output output add_output output, :escaped_output end
add_output(output, type = :output)
click to toggle source
# File lib/railroader/processors/template_processor.rb, line 79 def add_output output, type = :output s = Sexp.new(type, output) s.line(output.line) @current_template.add_output s s end
normalize_output(arg)
click to toggle source
Pull out actual output value from template
# File lib/railroader/processors/template_processor.rb, line 57 def normalize_output arg if call? arg and [:to_s, :html_safe!, :freeze].include? arg.method arg.target elsif node_type? arg, :if branches = [arg.then_clause, arg.else_clause].compact if branches.empty? s(:nil) elsif branches.length == 2 Sexp.new(:or, *branches) else branches.first end else arg end end
process(exp)
click to toggle source
Process the template Sexp
.
Calls superclass method
Railroader::SexpProcessor#process
# File lib/railroader/processors/template_processor.rb, line 23 def process exp begin super rescue => e except = e.exception("Error when processing #{@current_template.name}: #{e.message}") except.set_backtrace(e.backtrace) raise except end end
process_escaped_output(exp)
click to toggle source
# File lib/railroader/processors/template_processor.rb, line 52 def process_escaped_output exp process_output exp end
process_lasgn(exp)
click to toggle source
Ignore initial variable assignment
# File lib/railroader/processors/template_processor.rb, line 34 def process_lasgn exp if exp.lhs == :_erbout and exp.rhs.node_type == :str # ignore ignore elsif exp.lhs == :_buf and exp.rhs.node_type == :str ignore else exp.rhs = process exp.rhs exp end end
process_output(exp)
click to toggle source
Adds output to the list of outputs.
# File lib/railroader/processors/template_processor.rb, line 46 def process_output exp exp.value = process exp.value @current_template.add_output exp unless exp.original_line exp end