Class Babylon::Base::View
In: lib/babylon/base/view.rb
Parent: Object

Your application‘s views (stanzas) should be descendant of this class.


evaluate   new   render  


view_template  [R] 

Public Class methods

Instantiate a new view with the various varibales passed in assigns and the path of the template to render.


    # File lib/babylon/base/view.rb, line 25
25:       def initialize(path = "", assigns = {}) 
26:         @view_template = path 
28:         assigns.each do |key, value| 
29:           instance_variable_set("@#{key}""@#{key}", value) 
30:         end 
31:       end

Public Instance methods

"Loads" the view file, and uses the Nokogiri Builder to build the XML stanzas that will be sent.


    # File lib/babylon/base/view.rb, line 35
35:       def evaluate 
36:         return if @view_template == ""
37:         raise ViewFileNotFound, "No such file #{@view_template}" unless Babylon.views[@view_template] 
38:         builder = 
39: do |xml|
40:           eval(Babylon.views[@view_template], binding, @view_template, 1)
41:         end
42:         builder.doc.root.children # we output the document built 
43:       end

Used to ‘include’ another view inside an existing view. The caller needs to pass the context in which the partial will be rendered Render must be called with :partial as well (other options will be supported later). The partial vale should be a relative path to another file view, from the calling view.


    # File lib/babylon/base/view.rb, line 16
16:       def render(xml, options = {})
17:         # First, we need to identify the partial file path, based on the @view_template path.
18:         partial_path = (@view_template.split("/")[0..-2] + options[:partial].split("/")).join("/").gsub(".xml.builder", "") + ".xml.builder"
19:         raise ViewFileNotFound, "No such file #{partial_path}" unless Babylon.views[partial_path] 
20:         eval(Babylon.views[partial_path], binding, partial_path, 1)
21:       end