class GemHadar::TemplateCompiler
compiler.compile(‘template.erb’, ‘output.txt’)
end
t.version = ‘1.0.0’
t.name = ‘my_template’
compiler = GemHadar::TemplateCompiler.new do |t|
@example Compiling a template file
context, and writing the resulting content to specified destination files.
handles the reading of template files, rendering them with the provided
substituting placeholders with actual values from a configuration block. It
The TemplateCompiler class provides functionality to process ERB templates,
representations.
A class for compiling ERB template files into their final output
def compile(src, dst)
-
dst(String) -- the path to the destination file where the rendered content will be written -
src(String) -- the path to the source ERB template file
def compile(src, dst) template = File.read(src) File.open(dst, 'w') do |output| erb = ERB.new(template, trim_mode: ?-) erb.filename = src.to_s output.write erb.result binding end end
def initialize(&block)
-
block(Proc) -- the block to be evaluated for configuring the template compiler
def initialize(&block) super block_self(&block) @values = {} instance_eval(&block) end
def method_missing(id, *a, &b)
-
(Object)- the value associated with the method name if retrieving,
Parameters:
-
b(Proc) -- the block passed to the method -
a(Array) -- the arguments passed to the method -
id(Symbol) -- the name of the method being called
def method_missing(id, *a, &b) if a.empty? && id && @values.key?(id) @values[id] elsif a.size == 1 @values[id] = a.first else super end end