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.



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

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



21
22
23
24
# File 'lib/web_console/testing/erb_precompiler.rb', line 21

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

Instance Method Details

#buildObject



17
18
19
# File 'lib/web_console/testing/erb_precompiler.rb', line 17

def build
  @erb.result(binding)
end