class Lono::Template::Template
Attributes
name[R]
Main template Erb methods are: source and variables
template "example-2" do source "example" variables(test: 1) end
Public Class Methods
new(blueprint, name, block=nil, options={})
click to toggle source
# File lib/lono/template/template.rb, line 16 def initialize(blueprint, name, block=nil, options={}) @blueprint, @name, @block, @options = blueprint, name, block, options @source_path = default_source_path(name) end
Public Instance Methods
build()
click to toggle source
# File lib/lono/template/template.rb, line 38 def build instance_eval(&@block) if @block if File.exist?(@source_path) RenderMePretty.result(@source_path, context: context) else puts "ERROR: #{@source_path} does not exist, but it was used as a template source.".color(:red) exit 1 end end
context()
click to toggle source
Context for ERB rendering. This is where we control what references get passed to the ERB rendering.
# File lib/lono/template/template.rb, line 51 def context @context ||= Lono::Template::Context.new(@options) end
default_source_path(name)
click to toggle source
internal methods
# File lib/lono/template/template.rb, line 34 def default_source_path(name) "#{Lono.config.templates_path}/#{name}.yml" # defaults to name, source method overrides end
source(path)
click to toggle source
Returns path, example: ./app/templates/example.yml
# File lib/lono/template/template.rb, line 22 def source(path) @source_path = path[0..0] == '/' ? path : "#{Lono.config.templates_path}/#{path}" @source_path += ".yml" end
variables(vars={})
click to toggle source
# File lib/lono/template/template.rb, line 27 def variables(vars={}) vars.each do |var,value| context.instance_variable_set("@#{var}", value) end end