Class: Travis::Renderer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, object, options = {}) ⇒ Renderer

Returns a new instance of Renderer.



27
28
29
30
31
32
33
34
# File 'lib/travis/renderer.rb', line 27

def initialize(format, object, options = {})
  @format, @object, @options = format, object, options

  @base_dir = options.fetch(:base_dir, 'app/views')
  @version  = options.fetch(:version, :v1)
  @type     = options.fetch(:type, :default)
  @template_name = options.fetch(:template, model_name)
end

Instance Attribute Details

#base_dirObject (readonly)

Returns the value of attribute base_dir.



25
26
27
# File 'lib/travis/renderer.rb', line 25

def base_dir
  @base_dir
end

#formatObject (readonly)

Returns the value of attribute format.



25
26
27
# File 'lib/travis/renderer.rb', line 25

def format
  @format
end

#objectObject (readonly)

Returns the value of attribute object.



25
26
27
# File 'lib/travis/renderer.rb', line 25

def object
  @object
end

#optionsObject (readonly)

Returns the value of attribute options.



25
26
27
# File 'lib/travis/renderer.rb', line 25

def options
  @options
end

#template_nameObject (readonly)

Returns the value of attribute template_name.



25
26
27
# File 'lib/travis/renderer.rb', line 25

def template_name
  @template_name
end

#typeObject (readonly)

Returns the value of attribute type.



25
26
27
# File 'lib/travis/renderer.rb', line 25

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



25
26
27
# File 'lib/travis/renderer.rb', line 25

def version
  @version
end

Class Method Details

.hash(object, options = {}) ⇒ Object



12
13
14
# File 'lib/travis/renderer.rb', line 12

def hash(object, options = {})
  new(:hash, object, options).render
end

.json(object, options = {}) ⇒ Object



16
17
18
# File 'lib/travis/renderer.rb', line 16

def json(object, options = {})
  new(:json, object, options).render
end

.xml(object, options = {}) ⇒ Object



20
21
22
# File 'lib/travis/renderer.rb', line 20

def xml(object, options = {})
  new(:xml, object, options).render
end

Instance Method Details

#renderObject



36
37
38
39
40
41
42
# File 'lib/travis/renderer.rb', line 36

def render
  set_instance_variable
  view = Rabl::Engine.new(template, :format => format) # :view_path => view_path(options) TODO view_path doesn't seem get passed through to :extends
  view.singleton_class.send(:attr_accessor, :params) # omg. essentially need this for a test helper? is there no way to pass locals in?
  view.params = options[:params] || {}
  view.render(self, {})
end