Class: JsendWrapper::Rails::TemplateHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/jsend_wrapper/rails/template_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ TemplateHandler

Returns a new instance of TemplateHandler.

Parameters:

  • view (ActiveView::Base)


31
32
33
# File 'lib/jsend_wrapper/rails/template_handler.rb', line 31

def initialize(view)
  @view = view
end

Class Method Details

.call(template) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/jsend_wrapper/rails/template_handler.rb', line 19

def self.call(template)
  json_handler = ActionView::Template.registered_template_handler :jbuilder
  json = json_handler.call template

  <<-RUBY
    content = instance_eval #{json.inspect}
    JsendWrapper::Rails::TemplateHandler.new(self).render content
  RUBY
end

Instance Method Details

#render(json) ⇒ Object

Parameters:

  • json (String)


37
38
39
40
# File 'lib/jsend_wrapper/rails/template_handler.rb', line 37

def render(json, *)
  json = 'null' if !json || json.empty?
  %[{"status":"success","data":#{json}}]
end