lib/retrospec/plugins/v1/module_helpers.rb in retrospec-0.3.0 vs lib/retrospec/plugins/v1/module_helpers.rb in retrospec-0.3.1

- old
+ new

@@ -5,10 +5,11 @@ module Plugins module V1 module ModuleHelpers # only creates a directory if the directory doesn't already exist def safe_mkdir(dir) + dir = File.expand_path(dir) if File.exists? dir unless File.directory? dir $stderr.puts "!! #{dir} already exists and is not a directory".fatal end else @@ -101,19 +102,27 @@ # loops through the directory looking for erb files or other files. # strips the erb extension and renders the template to the current module path # filenames must named how they would appear in the normal module path. The directory # structure where the file is contained def safe_create_module_files(template_dir, module_path, spec_object) - templates = Find.find(File.join(template_dir,'module_files')).find_all.sort + templates = Find.find(File.join(template_dir,'module_files')).sort templates.each do |template| - dest = template.gsub(File.join(template_dir,'module_files'), module_path).gsub('.erb', '') - if File.symlink?(template) - safe_create_symlink(template, dest) - elsif File.directory?(template) - safe_mkdir(dest) - else + dest = template.gsub(File.join(template_dir,'module_files'), module_path) + if File.symlink?(template) + safe_create_symlink(template, dest) + elsif File.directory?(template) + safe_mkdir(dest) + else + # because some plugins contain erb files themselves any erb file will be copied only + # so we need to designate which files should be rendered with .retrospec.erb + if template =~ /\.retrospec\.erb/ + # render any file ending in .retrospec_erb as a template + dest = dest.gsub(/\.retrospec\.erb/, '') safe_create_template_file(dest, template, spec_object) + else + safe_copy_file(template, dest) end + end end end end end end