Class: ReVIEW::Template
- Includes:
- ERB::Util
- Defined in:
- lib/review/template.rb
Constant Summary collapse
- TEMPLATE_DIR =
File.join(File.dirname(__FILE__), '../../templates')
Class Method Summary collapse
- .generate(path:, binding:, mode: 1, template_dir: ReVIEW::Template::TEMPLATE_DIR) ⇒ Object
- .load(filename, mode = 1) ⇒ Object
Instance Method Summary collapse
-
#initialize(filename = nil, mode = nil) ⇒ Template
constructor
A new instance of Template.
- #result(bind_data = nil) ⇒ Object
Constructor Details
#initialize(filename = nil, mode = nil) ⇒ Template
Returns a new instance of Template.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/review/template.rb', line 18 def initialize(filename = nil, mode = nil) return unless filename content = File.read(filename) @erb = if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6') ERB.new(content, trim_mode: mode) else ERB.new(content, nil, mode) end end |
Class Method Details
.generate(path:, binding:, mode: 1, template_dir: ReVIEW::Template::TEMPLATE_DIR) ⇒ Object
13 14 15 16 |
# File 'lib/review/template.rb', line 13 def self.generate(path:, binding:, mode: 1, template_dir: ReVIEW::Template::TEMPLATE_DIR) template_file = File.(path, template_dir) self.new(template_file, mode).result(binding) end |
.load(filename, mode = 1) ⇒ Object
9 10 11 |
# File 'lib/review/template.rb', line 9 def self.load(filename, mode = 1) self.new(filename, mode) end |
Instance Method Details
#result(bind_data = nil) ⇒ Object
29 30 31 |
# File 'lib/review/template.rb', line 29 def result(bind_data = nil) @erb.result(bind_data) end |