lib/retrospec/plugins/v1/plugin/foreman_plugin.rb
def safe_create_module_files(template_dir, module_path, spec_object)
          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)
            if dest =~ /foreman_plugin_template/i
              dest = dest.gsub('foreman_plugin_template', spec_object.plugin_name)
            end
            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)
              elsif template =~ /\.erb/
                original_text = File.read(template)
                text = original_text.gsub('foreman_plugin_template', spec_object.plugin_name)
                text = text.gsub('ForemanPluginTemplate', spec_object.plugin_name.camel_case)
                safe_create_file(dest, text)
              else
                safe_copy_file(template, dest)
              end
            end
          end
        end
# creates any file that is contained in the templates/modules_files directory structure
# 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
creates any file that is contained in the templates/modules_files directory structure
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
creates any file that is contained in the templates / modules_files directory structure 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')).sort
          templates.each do |template|
            dest = template.gsub(File.join(template_dir,'module_files'), module_path)
            if dest =~ /foreman_plugin_template/i
              dest = dest.gsub('foreman_plugin_template', spec_object.plugin_name)
            end
            if File.symlink?(template)
              safe_create_symlink(template, dest)
            elsif File.directory?(template)
              safe_mkdir(dest)
            else
              if template =~ /\.retrospec\.erb/
                dest = dest.gsub(/\.retrospec\.erb/, '')
                safe_create_template_file(dest, template, spec_object)
              elsif template =~ /\.erb/
                original_text = File.read(template)
                text = original_text.gsub('foreman_plugin_template', spec_object.plugin_name)
                text = text.gsub('ForemanPluginTemplate', spec_object.plugin_name.camel_case)
                safe_create_file(dest, text)
              else
                safe_copy_file(template, dest)
              end
            end
          end
        end
def safe_create_module_files ( template_dir , module_path , spec_object ) 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 ) if dest =~ / foreman_plugin_template /i dest = dest . gsub ( 'foreman_plugin_template' , spec_object . plugin_name ) end if File . symlink? ( template ) safe_create_symlink ( template , dest ) elsif File . directory? ( template ) safe_mkdir ( dest ) else if template =~ / \. retrospec \. erb / dest = dest . gsub ( / \. retrospec \. erb / , '' ) safe_create_template_file ( dest , template , spec_object ) elsif template =~ / \. erb / original_text = File . read ( template ) text = original_text . gsub ( 'foreman_plugin_template' , spec_object . plugin_name ) text = text . gsub ( 'ForemanPluginTemplate' , spec_object . plugin_name . camel_case ) safe_create_file ( dest , text ) else safe_copy_file ( template , dest ) end end end end
creates any file that is contained in the templates/modules_files directory structure
loops through the directory looking for erb files or other files.
creates any file that is contained in the templates / modules_files directory structure loops through the directory looking for erb files or other files .
# 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 # render any file ending in .retrospec_erb as a template
template_dir
module_path
spec_object