Sha256: e9ab28f2d8b26d1ff42c6659efc01e4306f7c4a62d4f702957f85efd96d2a5e6

Contents?: true

Size: 680 Bytes

Versions: 1

Compression:

Stored size: 680 Bytes

Contents

require 'fileutils'

module TouchErb
  class TemplateDir
    def initialize(root_dir = ENV['TOUCH_ERB_ROOT'] || File.join(Dir.home, '.touch_erb'))
      FileUtils.mkdir_p(root_dir) unless Dir.exist?(root_dir)
      @root =  root_dir
    end

    def find(template_name)
      absolute_path = "#{File.join(@root, template_name)}.erb"
      File.read(absolute_path) if File.exist?(absolute_path)
    end

    def add(template_name)
      absolute_path = File.join(@root, "#{template_name}.erb")
      FileUtils.touch(absolute_path)
      absolute_path
    end

    def list()
      Dir.glob("*.erb", base: @root).map { |filename| File.basename(filename, '.erb') }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
touch_erb-0.2.0 lib/touch_erb/template_dir.rb