lib/blower/context.rb
# Renders and installs files from ERB templates. Files are under +from+ in ERB format. +from/foo/bar.conf.erb+ is
# rendered and written to +to/foo/bar.conf+. Non-ERB files are ignored.
# @param [String] from The directory to search for .erb files.
# @param [String] to The remote directory to put files in.
# @macro onable
# @macro asable
# @macro quietable
# @macro onceable
Renders and installs files from ERB templates. Files are under +from+ in ERB format.
Renders and installs files from ERB templates . Files are under + from + in ERB format .
def render (from, to, as: user, on: hosts, quiet: false, once: nil)
      self.once once, quiet: quiet do
        Dir.chdir File.dirname(file) do
          Find.find(from).each do |path|
            if File.directory?(path)
              to_path = to + path[from.length..-1]
              sh "mkdir -p #{to_path.shellescape}"
            elsif path =~ /\.erb$/
              template = ERB.new(File.read(path))
              to_path = to + path[from.length..-5]
              log.info "render: #{path} -> #{to_path}", quiet: quiet do
                hash_map(hosts) do |host|
                  host.cp StringIO.new(template.result(binding)), to_path, as: as, quiet: quiet
                end
              end
            else
              to_path = to + path[from.length..-1]
              log.info "copy: #{path} -> #{to_path}", quiet: quiet do
                hash_map(hosts) do |host|
                  host.cp File.open(path), to_path, as: as, quiet: quiet
                end
              end
            end
          end
        end
      end
    end
def render ( from , to , as : user , on : hosts , quiet : false , once : nil ) self . once once , quiet : quiet do Dir . chdir File . dirname ( file ) do Find . find ( from ) . each do | path | if File . directory? ( path ) to_path = to + path [ from . length .. - 1 ] sh "mkdir -p #{to_path.shellescape}" elsif path =~ / \. erb$ / template = ERB . new ( File . read ( path ) ) to_path = to + path [ from . length .. - 5 ] log . info "render: #{path} -> #{to_path}" , quiet : quiet do hash_map ( hosts ) do | host | host . cp StringIO . new ( template . result ( binding ) ) , to_path , as : as , quiet : quiet end end else to_path = to + path [ from . length .. - 1 ] log . info "copy: #{path} -> #{to_path}" , quiet : quiet do hash_map ( hosts ) do | host | host . cp File . open ( path ) , to_path , as : as , quiet : quiet end end end end end end end
Renders and installs files from ERB templates.
Renders and installs files from ERB templates .
from
<not_specific>
to
<not_specific>
as
<not_specific>
user
<not_specific>
on
<not_specific>
hosts
<not_specific>
quiet
<not_specific>
once
<not_specific>
<not_specific>
to The remote directory to put files in.
to The remote directory to put files in .
macro
None
macro
None
macro
None
macro
None