Class: Epuber::RubyTemplater
- Inherits:
-
Object
- Object
- Epuber::RubyTemplater
- Defined in:
- lib/epuber/vendor/ruby_templater.rb
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#file_path ⇒ String
15 16 17 |
# File 'lib/epuber/vendor/ruby_templater.rb', line 15 def file_path @file_path end |
#locals ⇒ Hash
19 20 21 |
# File 'lib/epuber/vendor/ruby_templater.rb', line 19 def locals @locals end |
#source_text ⇒ String
11 12 13 |
# File 'lib/epuber/vendor/ruby_templater.rb', line 11 def source_text @source_text end |
Class Method Details
.from_file(file) ⇒ self
36 37 38 39 40 41 42 43 44 |
# File 'lib/epuber/vendor/ruby_templater.rb', line 36 def self.from_file(file) file_obj = if file.is_a?(String) File.new(file, 'r') else file end from_source(file_obj.read, file_obj.path) end |
.from_source(source, file_path = nil) ⇒ self
25 26 27 28 29 30 |
# File 'lib/epuber/vendor/ruby_templater.rb', line 25 def self.from_source(source, file_path = nil) inst = new inst.source_text = source inst.file_path = file_path inst end |
Instance Method Details
#render ⇒ String
62 63 64 65 66 |
# File 'lib/epuber/vendor/ruby_templater.rb', line 62 def render hash_binding = HashBinding.new(locals) eval_string = %(%(#{source_text})) eval(eval_string, hash_binding.get_binding) end |
#with_locals(locals = {}) ⇒ self
55 56 57 58 |
# File 'lib/epuber/vendor/ruby_templater.rb', line 55 def with_locals(locals = {}) self.locals = locals self end |