Module: Capper::Utils::Templates

Defined in:
lib/capper/utils/templates.rb

Instance Method Summary collapse

Instance Method Details

#upload_template(path, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/capper/utils/templates.rb', line 27

def upload_template(path, options={})
  bnd = options.delete(:binding) || binding

  if task = current_task
    servers = find_servers_for_task(task, options)
  else
    servers = find_servers(options)
  end

  if servers.empty?
    raise Capistrano::NoMatchingServersError, "no servers matching #{task.options.inspect}"
  end

  servers.each do |server|
    erb = Erubis::Eruby.new(yield server)
    result = erb.result(bnd)
    put(result, path, options.merge!(:hosts => server))
  end
end

#upload_template_file(name, path, options = {}) ⇒ Object

render an erb template from config/deploy/templates to the current server list. this will render and upload templates serially using a server-specific @variables binding. see get_binding for details.



10
11
12
13
14
15
16
17
18
19
# File 'lib/capper/utils/templates.rb', line 10

def upload_template_file(name, path, options={})
  template = "config/deploy/templates/#{name}.erb"

  unless File.exist?(template)
    template = File.expand_path("../../templates/#{name}.erb", __FILE__)
  end

  str = File.open(template).read
  upload_template_string(str, path, options)
end

#upload_template_string(str, path, options = {}) ⇒ Object



21
22
23
24
25
# File 'lib/capper/utils/templates.rb', line 21

def upload_template_string(str, path, options={})
  upload_template(path, options) do |server|
    str
  end
end