Class: Grape::Axlsx::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/axlsx/renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_path, template) ⇒ Renderer

Returns a new instance of Renderer.



6
7
8
# File 'lib/grape/axlsx/renderer.rb', line 6

def initialize(view_path, template)
  @view_path, @template = view_path, template
end

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



4
5
6
# File 'lib/grape/axlsx/renderer.rb', line 4

def template
  @template
end

#view_pathObject (readonly)

Returns the value of attribute view_path.



4
5
6
# File 'lib/grape/axlsx/renderer.rb', line 4

def view_path
  @view_path
end

Instance Method Details

#render(scope) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/grape/axlsx/renderer.rb', line 10

def render(scope)
  unless view_path
    raise "Use Rack::Config to set 'api.tilt.root' in config.ru"
  end

  context = scope.instance_eval { binding }
  eval "xlsx_package = ::Axlsx::Package.new; #{template_content}; xlsx_package.to_stream.string;", context
end