Class: Travis::Renderer
- Inherits:
-
Object
- Object
- Travis::Renderer
- Defined in:
- lib/travis/renderer.rb
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#template_name ⇒ Object
readonly
Returns the value of attribute template_name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .hash(object, options = {}) ⇒ Object
- .json(object, options = {}) ⇒ Object
- .xml(object, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(format, object, options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
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, = {}) @format, @object, @options = format, object, @base_dir = .fetch(:base_dir, 'app/views') @version = .fetch(:version, :v1) @type = .fetch(:type, :default) @template_name = .fetch(:template, model_name) end |
Instance Attribute Details
#base_dir ⇒ Object (readonly)
Returns the value of attribute base_dir.
25 26 27 |
# File 'lib/travis/renderer.rb', line 25 def base_dir @base_dir end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
25 26 27 |
# File 'lib/travis/renderer.rb', line 25 def format @format end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
25 26 27 |
# File 'lib/travis/renderer.rb', line 25 def object @object end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
25 26 27 |
# File 'lib/travis/renderer.rb', line 25 def @options end |
#template_name ⇒ Object (readonly)
Returns the value of attribute template_name.
25 26 27 |
# File 'lib/travis/renderer.rb', line 25 def template_name @template_name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
25 26 27 |
# File 'lib/travis/renderer.rb', line 25 def type @type end |
#version ⇒ Object (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, = {}) new(:hash, object, ).render end |
.json(object, options = {}) ⇒ Object
16 17 18 |
# File 'lib/travis/renderer.rb', line 16 def json(object, = {}) new(:json, object, ).render end |
.xml(object, options = {}) ⇒ Object
20 21 22 |
# File 'lib/travis/renderer.rb', line 20 def xml(object, = {}) new(:xml, object, ).render end |
Instance Method Details
#render ⇒ Object
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 = [:params] || {} view.render(self, {}) end |