class Templet::Renderers::ERb
For rendering a supplied block within an ERb
template
Attributes
context[RW]
proto_template[RW]
Public Class Methods
call(template=nil, **locals, &block)
click to toggle source
Shortcut to instance method
# File lib/templet/renderers/erb.rb, line 28 def self.call(template=nil, **locals, &block) new(template, **locals).(&block) end
new(proto_template=nil, **locals)
click to toggle source
Public Instance Methods
call(&block)
click to toggle source
The return value from the block in substituted in <%= yield %>
# File lib/templet/renderers/erb.rb, line 21 def call(&block) context_binding = context.instance_eval { ::Kernel.binding } erb.result context_binding, &block end
Private Instance Methods
erb()
click to toggle source
# File lib/templet/renderers/erb.rb, line 34 def erb @erb ||= ERB.new get_template end
erb_path(call_stack)
click to toggle source
# File lib/templet/renderers/erb.rb, line 64 def erb_path(call_stack) source_path(call_stack, 0).sub(/\.rb$/, '.erb') end
get_template()
click to toggle source
# File lib/templet/renderers/erb.rb, line 38 def get_template if proto_template if proto_template =~ /(<%)|(\s\s)|(\n)/m proto_template else IO.read proto_template end else template or '' end end
read_end(call_stack)
click to toggle source
# File lib/templet/renderers/erb.rb, line 68 def read_end(call_stack) if defined? DATA DATA.read else path = source_path(call_stack, 0) IO.read(path).split(/\s__END__\s/, 2)&.last end end
read_erb(call_stack)
click to toggle source
# File lib/templet/renderers/erb.rb, line 58 def read_erb(call_stack) path = erb_path(call_stack) IO.read(path) if File.file?(path) end
source_path(call_stack, index)
click to toggle source
# File lib/templet/renderers/erb.rb, line 78 def source_path(call_stack, index) call_stack[index].split(":").first end
template(read_from=false)
click to toggle source
# File lib/templet/renderers/erb.rb, line 50 def template(read_from=false) if read_from call_stack = caller read_erb(call_stack) or read_end(call_stack) end end