Class: Marko::Services::Compile

Inherits:
Marko::Service show all
Defined in:
lib/marko/services/compile.rb

Overview

Compitation service

Constant Summary

Constants inherited from Marko::Service

Marko::Service::Failure

Instance Method Summary collapse

Methods inherited from Marko::Service

call, inherited

Constructor Details

#initialize(tree: nil, template: '', filename: '', &block) ⇒ Compile

Returns a new instance of Compile.



9
10
11
12
13
14
15
16
17
18
# File 'lib/marko/services/compile.rb', line 9

def initialize(tree: nil, template: '', filename: '', &block)
  @tree = MustbeTreeNode.(tree) if tree
  @template = MustbeString.(template)
  @filename = MustbeString.(filename)
  @block = block

  art = Marko.artifact
  @template = art.template if @template.empty?
  @filename = art.filename if @filename.empty?
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
# File 'lib/marko/services/compile.rb', line 20

def call
  storage = StoragePlug.plugged
  compiler = CompilerPlug.plugged
  erb = storage.content(@template)
  @tree = Assembler.(&@block) unless @tree
  compiler.(@tree, erb, @filename, &@block) # => filename
end