Class: Marko::Loader

Inherits:
Service show all
Defined in:
lib/marko/loader.rb

Overview

The strategy class for loading sources from repository

Constant Summary

Constants inherited from Service

Service::Failure

Instance Method Summary collapse

Methods inherited from Service

call, inherited, #initialize

Constructor Details

This class inherits a constructor from Marko::Service

Instance Method Details

#callArray<TreeNode>, Array<String>

load markup sources, parse and return TreeNode buffer

Examples:

fn = proc{|event, paylod| ... }
buffer, errors = loader.(&fn)
fail "Failed" if errors.any?
# procced ...

Parameters:

  • block (&block)

    aka proc {|event, payload| ..}

Returns:

  • (Array<TreeNode>, Array<String>)

    where the first item is buffer and the second is array<error>



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/marko/loader.rb', line 21

def call
  buffer = []
  errors = []
  parser = ParserPlug.plugged
  storage = StoragePlug.plugged
  storage.sources.each do |source|
    @block.(:source, source) if @block
    content = storage.content(source)
    buff, errs = parser.(content, source, &@block)
    buffer.concat(buff)
    errors.concat(errs)
    @block.(:errors, errs) if @block
  end
  [buffer.flatten, errors]
end