Module: CommandKit::FileUtils

Includes:
FileUtils
Included in:
Command
Defined in:
lib/command_kit/file_utils.rb

Overview

File manipulation related methods.

Since:

  • 0.3.0

Instance Method Summary collapse

Instance Method Details

#erb(source, dest = nil) ⇒ String?

Renders an erb file and optionally writes it out to a destination file.

Examples:

Rendering a ERB template and saving it's output:

erb File.join(template_dir,'README.md.erb'), 'README.md'

Rendering a ERB template and capturing it's output:

output = erb(File.join(template_dir,'_partial.erb'))

Parameters:

  • source (String)

    The path to the erb template file.

  • dest (String, nil) (defaults to: nil)

    The path to the destination file.

Returns:

  • (String, nil)

    If no destination path argument is given, the rendered erb template String will be returned.

Since:

  • 0.3.0



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/command_kit/file_utils.rb', line 36

def erb(source,dest=nil)
  erb    = ERB.new(File.read(source), trim_mode: '-')
  result = erb.result(binding)

  if dest
    File.write(dest,result)
    return
  else
    return result
  end
end