Module: QEDProject::Helpers

Included in:
Libraries::Base, Project
Defined in:
lib/qedproject/helpers.rb

Instance Method Summary collapse

Instance Method Details

#cp(source, destination, options = {}) ⇒ Object

Copies a file - wraps FileUtils to print a nice message if verbose is on.



6
7
8
9
# File 'lib/qedproject/helpers.rb', line 6

def cp(source, destination, options = {})
  FileUtils.cp source, destination
  puts "Created #{File.join destination, File.basename(source)}" if options[:verbose]
end

#cp_r(source, destination, options = {}) ⇒ Object



11
12
13
14
# File 'lib/qedproject/helpers.rb', line 11

def cp_r(source, destination, options = {})
  FileUtils.cp_r source, destination
  puts "Created #{File.join destination, File.basename(source)}" if options[:verbose]
end

#create_file(destination, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/qedproject/helpers.rb', line 21

def create_file(destination, options = {})
  if options[:no_overwrite] && File.exist?(destination)
    puts "Skipping #{destination}" if options[:verbose]
  else
    FileUtils.touch destination
    puts "Created file #{destination}" if options[:verbose]
  end
end

#mkdir_p(destination, options = {}) ⇒ Object



16
17
18
19
# File 'lib/qedproject/helpers.rb', line 16

def mkdir_p(destination, options = {})
  FileUtils.mkdir_p destination
  puts "Created folder #{destination}" if options[:verbose]
end

#render_template_to_file(template, file, context) ⇒ Object

Reads a template from the file system, evaluates it with ERB places it in the output folder specified. Takes the binding context as the last parameter so that ERb has access to instance variables, etc. This works similar to how Rails and Sinatra templates work.



37
38
39
40
41
42
# File 'lib/qedproject/helpers.rb', line 37

def render_template_to_file(template, file, context)
  t = File.read(File.join(self.template_root, template))
  File.open(file, "w") do |f|
    f << ERB.new(t, nil, "-").result(context)
  end
end