123456789_123456789_123456789_123456789_123456789_

Class: RubyInstaller::Build::ErbCompiler

Relationships & Source Files
Namespace Children
Classes:
Box
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Utils
Inherits: Object
Defined in: lib/ruby_installer/build/erb_compiler.rb

Overview

This class processes a template file with ERB. The ERB template is either taken from the current directory or, if it doesn’t exist, from the gem root directory.

Constant Summary

Utils - Included

GEM_ROOT, WINDOWS_CMD_SHEBANG

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Utils - Included

#eval_file,
#file

Extend rake’s file task to be defined only once and to check the expected file is indeed generated.

#msys_sh,
#ovl_expand_file

Returns the absolute path of rel_file within the current directory or, if it doesn’t exist, from the gem root directory.

#ovl_glob

Scan the current and the gem root directory for files matching rel_pattern.

#ovl_read_file

Read rel_file from the current directory or, if it doesn’t exist, from the gem root directory.

#q_inno

Quote a string according to the rules of Inno-Setup.

#rubyinstaller_build_gem_files

Return the gem files of “rubyinstaller-build”.

#task

Extend rake’s task definition to be defined only once, even if called several times.

#with_env, #with_sandbox_ruby, #task_once

Constructor Details

.new(erb_file_rel, result_file_rel = nil) ⇒ ErbCompiler

Create a new ERB object to process a template.

The ERB template erb_file_rel should be a relative path. It is either taken from the current directory or, if it doesn’t exist, from the gem root directory.

[ GitHub ]

  
# File 'lib/ruby_installer/build/erb_compiler.rb', line 43

def initialize(erb_file_rel, result_file_rel=nil)
  @erb_filename = erb_file_rel
  @erb_filename_abs = ovl_expand_file(erb_file_rel)
  @erb = ERB.new(File.read(@erb_filename_abs, encoding: "UTF-8"))
  @result_file_rel = result_file_rel || erb_file_rel.sub(/\.erb$/, "")
  @erb.filename = @result_file_rel
end

Instance Attribute Details

#erb_filename (readonly)

[ GitHub ]

  
# File 'lib/ruby_installer/build/erb_compiler.rb', line 36

attr_reader :erb_filename

#erb_filename_abs (readonly)

[ GitHub ]

  
# File 'lib/ruby_installer/build/erb_compiler.rb', line 37

attr_reader :erb_filename_abs

Instance Method Details

#result(task = nil)

Returns the ERB content as String with UTF-8 encoding.

A Box instance is used as binding to process the ERB template. All method calls are redirected to the task object.

[ GitHub ]

  
# File 'lib/ruby_installer/build/erb_compiler.rb', line 59

def result(task=nil)
  box = Box.new(self, task)
  @erb.result(box.binding)
end

#result_filename

[ GitHub ]

  
# File 'lib/ruby_installer/build/erb_compiler.rb', line 51

def result_filename
  @result_file_rel
end

#write_result(task = nil, filename = nil)

Write the ERB result to a file in UTF-8 encoding.

See #result

If no file name is given, it is derived from the template file name by cutting the .erb extension. If the file path contains non-exising directories, they are created.

[ GitHub ]

  
# File 'lib/ruby_installer/build/erb_compiler.rb', line 70

def write_result(task=nil, filename=nil)
  filename ||= result_filename
  FileUtils.mkdir_p File.dirname(filename)
  File.binwrite(filename, result(task))
  filename
end