Class: Ytrbium::Engine

Inherits:
Erubi::CaptureEndEngine
  • Object
show all
Defined in:
lib/ytrbium/engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, options = {}) ⇒ Engine

Returns a new instance of Engine.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ytrbium/engine.rb', line 2

def initialize(input, options = {})
  @template_module = options[:module] || Ytrbium.dsl
  stack_var = @defstack = "@_ybuf_stack"
  engine = self
  @template_module.module_eval do
    instance_variable_set(:@engine, engine)
    instance_variable_set(stack_var.to_sym, [])
  end
  bufvar = "@_ybuf"
  bufval = "Ytrbium::String.new"
  super(input, options.merge(bufval: bufval,
                             bufvar: bufvar,
                             preamble: "options ||= {}; #{stack_var} = []; #{bufvar} = #{bufval};",
                             escape: true,
                             escapefunc: "@_ybuf.indent_expr",
                             regexp: /<%(\|?={1,2}|!|-|\#|%|\|)?(.*?)([-=])?%>([ \t]*\r?\n)?/m))
end

Instance Method Details

#expand(b = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ytrbium/engine.rb', line 20

def expand(b = nil)
  mod_src = src
  args = []
  args.unshift @filename, 1 if @filename
  args.unshift b if b
  @template_module.module_eval do
    # rubocop:disable Security/Eval
    eval(mod_src, *args)
    # rubocop:enable Security/Eval
  end
end