Sha256: fa5e5fdd1a1f73b1b3c083e1b1e0a19566ea44981bfc9cedaf3688d7e90a7b6a

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

# will first try and copy the file:
# config/deploy/#{full_app_name}/#{from}.erb
# to:
# shared/config/to
# if the original source path doesn exist then it will
# search in:
# config/deploy/shared/#{from}.erb
# this allows files which are common to all enviros to
# come from a single source while allowing specific
# ones to be over-ridden
# if the target file name is the same as the source then
# the second parameter can be left out
def smart_template(from, to=nil)
  to ||= from
  full_to_path = "#{shared_path}/config/#{to.sub(/\.sample$/, '')}"
  if from_erb_path = template_file(from)
    from_erb = StringIO.new(ERB.new(File.read(from_erb_path)).result(binding))
    upload! from_erb, full_to_path
    info "copying: #{from_erb_path} to: #{full_to_path}"
  else
    error "error #{from} not found"
  end
end

#find a template file in order.
def template_file(name)
  app_root = Dir.pwd #may use Rake.application.original_dir
  unless File.exist?(File.join(app_root, 'Capfile'))
    raise "Assume run in app root(there exists a Capfile), but now in #{app_root}!" 
  end
  items = []
  items << "#{app_root}/config/#{name}"
  items << "#{app_root}/config/deploy/#{fetch(:stage)}/#{name}.erb"
  items << "#{app_root}/config/deploy/shared/#{name}.erb"
  tmpl_path = File.join(File.dirname(__FILE__), "templates")
  items << "#{tmpl_path}/#{name}.erb"
  items.each do |f|
    return f if File.exist?(f)
  end
  nil
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
capup-0.0.4 lib/capup/template.rb
capup-0.0.2 lib/capup/template.rb