Sha256: 3b744d768ab6c94210a84514b5d537de43b13fea46f79bbab0dc253c4df7d7dd
Contents?: true
Size: 927 Bytes
Versions: 14
Compression:
Stored size: 927 Bytes
Contents
require 'erb' module Buildable::FileMaker class << self # create plain_text file with content # # plain_text('test.txt') { |content| content << "hi" } # # => create test.txt file with "hi" inside def plain_text(filename, options = {}) # check if exist and be overwrite content = yield('') File.open(filename, 'w') { |file| file.write content } end def template(name, location = './', options = {}) destination = File.join(location, name) # check if exist and can overwrite template = load_template(name) raise "Template #{name} not found" unless template builder = ERB.new(template) File.open(destination, 'w') { |f| f.write builder.result } end private def load_template(name) filename = File.expand_path("../../../templates/#{name}.erb", __FILE__) File.read(filename) if File.exist? filename end end end
Version data entries
14 entries across 14 versions & 1 rubygems