class Tynn::Generator
Attributes
app_name[R]
base_dir[R]
Public Class Methods
new(base_dir, args)
click to toggle source
# File bin/tynn, line 57 def initialize(base_dir, args) @base_dir = base_dir @app_name = args.first end
Public Instance Methods
generate(path, vars = {})
click to toggle source
# File bin/tynn, line 66 def generate(path, vars = {}) output_path = File.join(app_name, path) mkdir(File.dirname(output_path)) write(output_path, render(path, vars)) end
log(str)
click to toggle source
# File bin/tynn, line 95 def log(str) puts(" \033[36mcreate\033[0m : #{ str }") end
mkdir(path)
click to toggle source
# File bin/tynn, line 74 def mkdir(path) unless Dir.exist?(path) Dir.mkdir(path) log(path) end end
render(path, vars = {})
click to toggle source
# File bin/tynn, line 88 def render(path, vars = {}) source = File.read(File.join(base_dir, "templates", path)) params = OpenStruct.new(vars).instance_eval { binding } return ERB.new(source).result(params) end
setup()
click to toggle source
# File bin/tynn, line 62 def setup raise("#{ self.class }#setup not implemented") end
write(path, content)
click to toggle source
# File bin/tynn, line 82 def write(path, content) File.write(path, content) log(path) end