module Inline::Erb
Constants
- VERSION
Public Class Methods
render(name, **context)
click to toggle source
Reads from a embedded template
@param src String - The data found after __END__ @param context Hash - variables to pass into template @return Rendered Template
@example
inline_template('vhost.conf', server_name: "example.com") __END__
# File lib/inline/erb.rb, line 31 def render(name, **context) templates = {} begin app, data = File.read(caller.first.split(":").first).split("__END__", 2) rescue Errno::ENOENT app, data = nil end data.strip! if data template = nil data.each_line do |line| if line =~ /^@@\s*(.*\S)\s*$/ template = String.new templates[$1.to_s] = template elsif template << line end end TemplateRenderer.render(templates[name], context) end end
Private Instance Methods
render(name, **context)
click to toggle source
Reads from a embedded template
@param src String - The data found after __END__ @param context Hash - variables to pass into template @return Rendered Template
@example
inline_template('vhost.conf', server_name: "example.com") __END__
# File lib/inline/erb.rb, line 31 def render(name, **context) templates = {} begin app, data = File.read(caller.first.split(":").first).split("__END__", 2) rescue Errno::ENOENT app, data = nil end data.strip! if data template = nil data.each_line do |line| if line =~ /^@@\s*(.*\S)\s*$/ template = String.new templates[$1.to_s] = template elsif template << line end end TemplateRenderer.render(templates[name], context) end end