Class: Tilt::ERBTemplate

Inherits:
Template show all
Defined in:
lib/sinatra/tilt.rb

Overview

Direct Known Subclasses

ErubisTemplate

Instance Attribute Summary

Attributes inherited from Template

#data, #file, #line, #options

Instance Method Summary collapse

Methods inherited from Template

#basename, #compile, #eval_file, #initialize, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Instance Method Details

#compile!Object



216
217
218
# File 'lib/sinatra/tilt.rb', line 216

def compile!
  @engine = ::ERB.new(data, options[:safe], options[:trim], '@_out_buf')
end

#evaluate(scope, locals, &block) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/sinatra/tilt.rb', line 224

def evaluate(scope, locals, &block)
  source, offset = local_assignment_code(locals)
  source = [source, template_source].join("\n")

  original_out_buf =
    scope.instance_variables.any? { |var| var.to_sym == :@_out_buf } &&
    scope.instance_variable_get(:@_out_buf)

  scope.instance_eval source, eval_file, line - offset

  output = scope.instance_variable_get(:@_out_buf)
  scope.instance_variable_set(:@_out_buf, original_out_buf)

  output
end

#initialize_engineObject



212
213
214
# File 'lib/sinatra/tilt.rb', line 212

def initialize_engine
  require_template_library 'erb' unless defined? ::ERB
end

#template_sourceObject



220
221
222
# File 'lib/sinatra/tilt.rb', line 220

def template_source
  @engine.src
end