class TouchErb::TemplateDir

Public Class Methods

new( root_dir = ENV['TOUCH_ERB_ROOT'] || File.join(Dir.home, '.touch_erb'), create_dir = true ) click to toggle source
# File lib/touch_erb/template_dir.rb, line 5
def initialize(
  root_dir = ENV['TOUCH_ERB_ROOT'] || File.join(Dir.home, '.touch_erb'),
  create_dir = true
)
  FileUtils.mkdir_p(root_dir) if create_dir &&  !Dir.exist?(root_dir)
  @root =  root_dir
end

Public Instance Methods

add(template_name) click to toggle source
# File lib/touch_erb/template_dir.rb, line 22
def add(template_name)
  absolute_path = File.join(@root, "#{template_name}.erb")
  FileUtils.touch(absolute_path)
  absolute_path
end
find(template_name) click to toggle source
# File lib/touch_erb/template_dir.rb, line 13
def find(template_name)
  absolute_path = "#{File.join(@root, template_name)}.erb"
  if File.exist?(absolute_path)
    File.read(absolute_path)
  else
    nil
  end
end
list() click to toggle source
# File lib/touch_erb/template_dir.rb, line 28
def list()
  Dir.glob("*.erb", base: @root).map { |filename| File.basename(filename, '.erb') }
end