Module: QEDProject::Helpers
- Included in:
- Libraries::Base, Project
- Defined in:
- lib/qedproject/helpers.rb
Instance Method Summary collapse
-
#cp(source, destination, options = {}) ⇒ Object
Copies a file - wraps FileUtils to print a nice message if verbose is on.
- #cp_r(source, destination, options = {}) ⇒ Object
- #create_file(destination, options = {}) ⇒ Object
- #mkdir_p(destination, options = {}) ⇒ Object
-
#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.
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, = {}) FileUtils.cp source, destination puts "Created #{File.join destination, File.basename(source)}" if [:verbose] end |
#cp_r(source, destination, options = {}) ⇒ Object
11 12 13 14 |
# File 'lib/qedproject/helpers.rb', line 11 def cp_r(source, destination, = {}) FileUtils.cp_r source, destination puts "Created #{File.join destination, File.basename(source)}" if [: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, = {}) if [:no_overwrite] && File.exist?(destination) puts "Skipping #{destination}" if [:verbose] else FileUtils.touch destination puts "Created file #{destination}" if [:verbose] end end |
#mkdir_p(destination, options = {}) ⇒ Object
16 17 18 19 |
# File 'lib/qedproject/helpers.rb', line 16 def mkdir_p(destination, = {}) FileUtils.mkdir_p destination puts "Created folder #{destination}" if [: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 |