class Epuber::RubyTemplater

Attributes

file_path[RW]

@return [String]

locals[RW]

@return [Hash]

source_text[RW]

@return [String]

Public Class Methods

from_file(file) click to toggle source

@param [String, File] file

@return [self]

# File lib/epuber/vendor/ruby_templater.rb, line 34
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) click to toggle source

@param [String] source

@return [self]

# File lib/epuber/vendor/ruby_templater.rb, line 23
def self.from_source(source, file_path = nil)
  inst = new
  inst.source_text = source
  inst.file_path = file_path
  inst
end

Public Instance Methods

render() click to toggle source

@return [String]

# File lib/epuber/vendor/ruby_templater.rb, line 60
def render
  hash_binding = HashBinding.new(locals)
  eval_string = %(%(#{source_text}))
  eval(eval_string, hash_binding.get_binding) # rubocop:disable Security/Eval
end
with_locals(locals = {}) click to toggle source

@param [Hash] locals

@return [self]

# File lib/epuber/vendor/ruby_templater.rb, line 53
def with_locals(locals = {})
  self.locals = locals
  self
end