Class: Yj::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/yj/handler.rb

Class Method Summary collapse

Class Method Details

.call(template) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/yj/handler.rb', line 10

def self.call(template)
  <<~SRC
  _partial ||= false
  r ||= Yj::Render.new(self)
  yaml = ERB.new(%{#{template.source}}, nil, '-').result(binding)
  return MultiJson.dump(YAML.load(yaml)) unless _partial
  yaml.each_line.with_index.map do |line, idx|
    idx == 0 ? "- \#{line}" : "  \#{line}"
  end.join
  SRC
end