Class: WebConsole::Testing::ERBPrecompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/web_console/testing/erb_precompiler.rb

Overview

This class is to pre-compile ‘templates/*.erb’.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ERBPrecompiler

Returns a new instance of ERBPrecompiler.



8
9
10
11
12
13
# File 'lib/web_console/testing/erb_precompiler.rb', line 8

def initialize(path)
  @erb  = ERB.new(File.read(path))
  @view = FakeMiddleware.new(
    view_path: Helper.gem_root.join('lib/web_console/templates'),
  ).view
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



19
20
21
22
# File 'lib/web_console/testing/erb_precompiler.rb', line 19

def method_missing(name, *args, &block)
  return super unless @view.respond_to?(name)
  @view.send(name, *args, &block)
end

Instance Method Details

#buildObject



15
16
17
# File 'lib/web_console/testing/erb_precompiler.rb', line 15

def build
  @erb.result(binding)
end