Class: Grape::Rabl::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/grape-rabl/formatter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, env) ⇒ Formatter

Returns a new instance of Formatter.



14
15
16
17
18
# File 'lib/grape-rabl/formatter.rb', line 14

def initialize(object, env)
  @env      = env
  @endpoint = env['api.endpoint']
  @object   = object
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



12
13
14
# File 'lib/grape-rabl/formatter.rb', line 12

def endpoint
  @endpoint
end

#envObject (readonly)

Returns the value of attribute env.



12
13
14
# File 'lib/grape-rabl/formatter.rb', line 12

def env
  @env
end

#objectObject (readonly)

Returns the value of attribute object.



12
13
14
# File 'lib/grape-rabl/formatter.rb', line 12

def object
  @object
end

Class Method Details

.tilt_cacheObject



7
8
9
# File 'lib/grape-rabl/formatter.rb', line 7

def tilt_cache
  @tilt_cache ||= ::Tilt::Cache.new
end

Instance Method Details

#renderObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/grape-rabl/formatter.rb', line 20

def render
  if rablable?
    rabl do |template|
      engine = tilt_template(template)
      output = engine.render endpoint, locals
      if layout_template
        layout_template.render(endpoint) { output }
      else
        output
      end
    end
  else
    fallback_formatter.call object, env
  end
end