Sha256: a384c007d7525dc7f220504f35df59fb7d4098ac75ef9cf4ae4b777617bef037

Contents?: true

Size: 1.31 KB

Versions: 19

Compression:

Stored size: 1.31 KB

Contents

require "erubis"

module Capper
  module Utils
    module Templates

      # 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.
      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

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

      def upload_template(path, options={})
        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(binding())
          put(result, path, options.merge!(:hosts => server))
        end
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
capper-0.9.17 lib/capper/utils/templates.rb
capper-0.9.16 lib/capper/utils/templates.rb
capper-0.9.15 lib/capper/utils/templates.rb
capper-0.9.14 lib/capper/utils/templates.rb
capper-0.9.13 lib/capper/utils/templates.rb
capper-0.9.12 lib/capper/utils/templates.rb
capper-0.9.11 lib/capper/utils/templates.rb
capper-0.9.10 lib/capper/utils/templates.rb
capper-0.9.9 lib/capper/utils/templates.rb
capper-0.9.8 lib/capper/utils/templates.rb
capper-0.9.7 lib/capper/utils/templates.rb
capper-0.9.6 lib/capper/utils/templates.rb
capper-0.9.5 lib/capper/utils/templates.rb
capper-0.9.4 lib/capper/utils/templates.rb
capper-0.9.3 lib/capper/utils/templates.rb
capper-0.9.2 lib/capper/utils/templates.rb
capper-0.9.1 lib/capper/utils/templates.rb
capper-0.9.0 lib/capper/utils/templates.rb
capper-0.8.3 lib/capper/utils/templates.rb