module ExtJS module MVC module Generator class Base TEMPLATE_PATH = "#{File.dirname(__FILE__)}/templates" def initialize *args @gsubs ||= {} @gsubs['namespace'] = ExtJS::MVC.environment['namespace'] end protected def ensure_directories_present! *args args.each do |a| Dir.mkdir(a) unless File.exists?(a) end end def ensure_no_overwrite! *args args.each do |a| if File.exists?(a) && !ARGV.include?("--force") raise ExtJS::MVC::FileExists.new("File already exists: #{a}") end end end def template(template_filename, destination_filename) #write the file File.open(destination_filename, 'w') {|f| f.puts(render_template(template_filename))} ExtJS::MVC.ui.confirm(" Created #{destination_filename}") end def render_template(template_filename, gsubs = @gsubs) #grab the template file text template_text = IO.read("#{TEMPLATE_PATH}/#{template_filename}") #translate the template file text gsubs.each_pair do |key, value| template_text.gsub!(Regexp.new("<%= @#{key} %>"), value) end template_text end def include_script html_filename, script_filename, dom_id end end end end end