Sha256: aa4ff432579aab924a113d1be9367825a2b5e59b397b3e02197932f4e211788a

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'colorize'
require 'date'
require 'erb'
require 'fileutils'

TEMPLATES_DIRECTORY = File.expand_path('../../templates', __FILE__)

module Spout
  module Helpers
    # Helpers to generate and update Spout dictionary framework.
    module Framework
      def copy_file(template_file, file_name = '')
        file_name = template_file if file_name == ''
        file_path = File.join(@full_path, file_name)
        template_file_path = File.join(TEMPLATES_DIRECTORY, template_file)
        puts '      create'.colorize(:green) + "  #{file_name}"
        FileUtils.copy(template_file_path, file_path)
      end

      def evaluate_file(template_file, file_name)
        template_file_path = File.join(TEMPLATES_DIRECTORY, template_file)
        template = ERB.new(File.read(template_file_path))
        file_path = File.join(@full_path, file_name)
        file_out = File.new(file_path, 'w')
        file_out.syswrite(template.result(binding))
        puts '      create'.colorize(:green) + "  #{file_name}"
      ensure
        file_out.close if file_out
      end

      def directory(directory_name)
        directory_path = File.join(@full_path, directory_name)
        puts '      create'.colorize(:green) + "  #{directory_name}"
        FileUtils.mkpath(directory_path)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spout-0.12.1 lib/spout/helpers/framework.rb
spout-0.12.0 lib/spout/helpers/framework.rb
spout-0.12.0.rc2 lib/spout/helpers/framework.rb