require File.expand_path('../../../../config/rorc', __FILE__) require "ro_helpers/out" require 'ro_default' require 'fileutils' require 'ro_file' require 'ro_helpers/bash' require 'ro_core_ext/string' require 'erb' include Bash module RoCommands module Generators module BaseGenerator class << self def included(base) base.extend(ClassMethods) end end module ClassMethods def file_write(path) dir = File.dirname(path) RoFile.write(path, ctn) end def lib_path name.split("::").map do |i| i.downcase end.join("/") end def lastest_file Find.find(Dir.pwd, dir).select do |f| test(?f, f) end.sort_by do |f| Time.at(File.ctime(f).to_f) end.last end def open bash "#{::RoDefault.editor} #{created_file}" end def created_file @created_file ||= lastest_file end def ctn @ctn ||= "" end attr_accessor :file def file @file ||= "" end def path File.join(dir, file) end def to Out.out "writing to #{path}" end def template ctn = RoFile.read File.expand_path("../templates/#{dir}.erb", __FILE__) @ctn = ERB.new(ctn).result(binding) to end def create(*args) reset template end def file_name @file_name ||= "" end def reset instance_variables.each do |iv| instance_variable_set iv, nil end end end end end end