class TinyTemplate

Constants

VERSION

Public Class Methods

new(str) click to toggle source

You can construct by your sulf this class, but you wont benefict from the magic of the context being automaticaly calculated with debug_inspector

# File lib/tiny_template.rb, line 8
def initialize(str)
  self.str = str
end
parse(str, context) click to toggle source

This is a facility class method aimed to simplify the construction

# File lib/tiny_template.rb, line 21
def self.parse(str, context)
  new(str).parse(context)
end
secure(allowed_keys) { || ... } click to toggle source
# File lib/tiny_template.rb, line 25
def self.secure(allowed_keys, &block)
  previous_keys = @allowed_keys
  @allowed_keys = allowed_keys
  yield.tap do
    @allowed_keys = previous_keys
  end

Public Instance Methods

parse(context) click to toggle source

Context can be any object that you expect it will respond to methods on the template passed to the constructor

# File lib/tiny_template.rb, line 14
def parse(context)
  str.gsub(/\{\{\w+(\.\w+)*\}\}/) do |match|
    interpolate(match, context)
  end
end