Module: Capper::Utils::Templates
- Defined in:
- lib/capper/utils/templates.rb
Instance Method Summary collapse
- #upload_template(path, options = {}) ⇒ Object
-
#upload_template_file(name, path, options = {}) ⇒ Object
render an erb template from config/deploy/templates to the current server list.
- #upload_template_string(str, path, options = {}) ⇒ Object
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, ={}) bnd = .delete(:binding) || binding if task = current_task servers = find_servers_for_task(task, ) else servers = find_servers() end if servers.empty? raise Capistrano::NoMatchingServersError, "no servers matching #{task..inspect}" end servers.each do |server| erb = Erubis::Eruby.new(yield server) result = erb.result(bnd) put(result, path, .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, ={}) template = "config/deploy/templates/#{name}.erb" unless File.exist?(template) template = File.("../../templates/#{name}.erb", __FILE__) end str = File.open(template).read upload_template_string(str, path, ) 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, ={}) upload_template(path, ) do |server| str end end |