Class: Jv::Render

Inherits:
Object
  • Object
show all
Defined in:
lib/jv/render.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Render

Returns a new instance of Render.



3
4
5
# File 'lib/jv/render.rb', line 3

def initialize(context)
  @context = context
end

Instance Method Details

#call(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jv/render.rb', line 7

def call(options)
  render_collection = options[:collection].present?
  options[:locals] ||= {}
  options[:locals].merge!(r: self, _partial: true) if render_collection
  json = @context.render options
  if render_collection
    json.prepend('[')
    json[-1] = ']'
  end
  JSON.load(json)
end