class Sambot::Template
Public Class Methods
new(filename)
click to toggle source
# File lib/sambot/template.rb, line 6 def initialize(filename) @filename = filename end
Public Instance Methods
evaluate(context = {}, opts = {}) { |input| ... }
click to toggle source
# File lib/sambot/template.rb, line 14 def evaluate(context = {}, opts = {}) input = File.read(path) input = yield(input) if block_given? eruby = Erubis::Eruby.new(input, opts) eruby.evaluate(context) end
path()
click to toggle source
# File lib/sambot/template.rb, line 10 def path File.expand_path(File.join(File.dirname(__FILE__), 'templates', @filename)) end
process(opts)
click to toggle source
# File lib/sambot/template.rb, line 21 def process(opts) File.delete(opts[:dest]) if File.exist?(opts[:dest]) if opts[:eruby] UI.debug("Parsing #{path} using Erubis") write(opts, opts[:dest]) else FileUtils.cp(path, opts[:dest].to_s) end if File.executable?(path) UI.debug("Making #{opts[:dest]} executable") make_executable(opts[:dest]) end end
write(ctx, dest)
click to toggle source
# File lib/sambot/template.rb, line 35 def write(ctx, dest) contents = evaluate(ctx) File.write(dest, contents) end
Private Instance Methods
make_executable(working_path)
click to toggle source
# File lib/sambot/template.rb, line 42 def make_executable(working_path) current_mask = File.stat(path).mode new_mask = current_mask | '0000000000000001'.to_i(2) File.chmod(new_mask, working_path) end