Module: Baptize::Plugins::Helpers

Defined in:
lib/baptize/plugins/helpers.rb

Instance Method Summary collapse

Instance Method Details

#asset_path(asset) ⇒ Object



6
7
8
# File 'lib/baptize/plugins/helpers.rb', line 6

def asset_path(asset)
  File.expand_path(File.join("assets", asset))
end

#escape_sed_arg(s) ⇒ Object



14
15
16
# File 'lib/baptize/plugins/helpers.rb', line 14

def escape_sed_arg(s)
  s.gsub("'", "'\\\\''").gsub("\n", '\n').gsub("/", "\\\\/").gsub('&', '\\\&')
end

#md5_of_file(path, md5) ⇒ Object



10
11
12
# File 'lib/baptize/plugins/helpers.rb', line 10

def md5_of_file(path, md5)
  remote_assert "test $(md5sum #{path.shellescape} | cut -f1 -d' ') = #{md5.shellescape}"
end

#render(path, locals = {}) ⇒ Object



22
23
24
25
26
# File 'lib/baptize/plugins/helpers.rb', line 22

def render(path, locals = {})
  require 'erb'
  require 'ostruct'
  ERB.new(File.read(path)).result(locals.kind_of?(Binding) ? locals : OpenStruct.new(locals).instance_eval { binding })
end

#replace_text(pattern, replacement, path) ⇒ Object



18
19
20
# File 'lib/baptize/plugins/helpers.rb', line 18

def replace_text(pattern, replacement, path)
  remote_execute "sed -i 's/#{escape_sed_arg(pattern)}/#{escape_sed_arg(replacement)}/g' #{path.shellescape}"
end