Sha256: e1614bc6d5cb0d9e2a813d1c4591b34b519cee3e54c36f201989368524585efb
Contents?: true
Size: 1.25 KB
Versions: 22
Compression:
Stored size: 1.25 KB
Contents
# encoding: utf-8 # rubocop:disable Lint/Eval require_relative 'hash_binding' module Epuber class RubyTemplater # @return [String] # attr_accessor :source_text # @return [String] # attr_accessor :file_path # @return [Hash] # attr_accessor :locals # @param source [String] # # @return [self] # def self.from_source(source, file_path = nil) inst = new inst.source_text = source inst.file_path = file_path inst end # @param file [String, File] # # @return [self] # 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 # ----------------------------------------------------------------------------- # # DSL methods # @param locals [Hash] # # @return [self] # def with_locals(locals = {}) self.locals = locals self end # @return [String] # def render hash_binding = HashBinding.new(locals) eval_string = %(%(#{source_text})) eval(eval_string, hash_binding.get_binding) end end end # rubocop:enable Lint/Eval
Version data entries
22 entries across 22 versions & 1 rubygems