Class: RubyInstaller::Build::ErbCompiler
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
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
Class Method Summary
-
.new(erb_file_rel, result_file_rel = nil) ⇒ ErbCompiler
constructor
Create a new ERB object to process a template.
Instance Attribute Summary
- #erb_filename readonly
- #erb_filename_abs readonly
Instance Method Summary
-
#result(task = nil)
Returns the ERB content as String with UTF-8 encoding.
- #result_filename
-
#write_result(task = nil, filename = nil)
Write the ERB result to a file in UTF-8 encoding.
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 |
#ovl_glob | Scan the current and the gem root directory for files matching |
#ovl_read_file | Read |
#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.
# 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 = (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.
#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.
# 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