class Capistrano::Template::Helpers::Renderer
Attributes
from[RW]
locals[RW]
reader[RW]
Public Class Methods
new(from, context, reader: File, locals: {})
click to toggle source
Calls superclass method
# File lib/capistrano/template/helpers/renderer.rb, line 7 def initialize(from, context, reader: File, locals: {}) super context self.from = from self.reader = reader self.locals = locals end
Public Instance Methods
as_io()
click to toggle source
# File lib/capistrano/template/helpers/renderer.rb, line 25 def as_io StringIO.new(as_str) end
as_str()
click to toggle source
# File lib/capistrano/template/helpers/renderer.rb, line 21 def as_str @rendered_template ||= ERB.new(template_content, nil, '-').result(binding) end
indented_content(content, indent)
click to toggle source
# File lib/capistrano/template/helpers/renderer.rb, line 44 def indented_content(content, indent) content.split("\n").map { |line| "#{' ' * indent}#{line}" }.join("\n") end
locals=(new_locals)
click to toggle source
# File lib/capistrano/template/helpers/renderer.rb, line 15 def locals=(new_locals) new_locals ||= {} new_locals = new_locals.each_with_object({}) { |(key, value), result| result[key.to_sym] = value } @locals = new_locals end
method_missing(m, *args, &block)
click to toggle source
Calls superclass method
# File lib/capistrano/template/helpers/renderer.rb, line 29 def method_missing(m, *args, &block) if locals.key?(m) locals[m] else super end end
render(from, indent: 0, locals: {})
click to toggle source
# File lib/capistrano/template/helpers/renderer.rb, line 37 def render(from, indent: 0, locals: {}) template = template_file(from) content = Renderer.new(template, self, reader: reader, locals: self.locals.merge(locals)).as_str indented_content(content, indent) end
respond_to_missing?(m, include_private)
click to toggle source
Calls superclass method
# File lib/capistrano/template/helpers/renderer.rb, line 48 def respond_to_missing?(m, include_private) if locals.key?(m) true else super end end
Protected Instance Methods
template_content()
click to toggle source
# File lib/capistrano/template/helpers/renderer.rb, line 58 def template_content reader.read(from) end