Parent

Files

Babylon::Base::Controller

Your application’s controller should be descendant of this class.

Attributes

stanza[RW]

(Not documented)

rendered[RW]

(Not documented)

action_name[RW]

(Not documented)

Public Class Methods

new(stanza = nil) click to toggle source

Creates a new controller (you should not override this class) and assigns the stanza as well as any other value of the hash to instances named after the keys of the hash.

    # File lib/babylon/base/controller.rb, line 12
12:       def initialize(stanza = nil)
13:         @stanza = stanza
14:         @view = nil
15:       end

Public Instance Methods

assigns() click to toggle source

Returns the list of variables assigned during the action.

    # File lib/babylon/base/controller.rb, line 33
33:       def assigns
34:         vars = Hash.new
35:         instance_variables.each do |var|
36:           if !["@view", "@action_name", "@block"].include? var
37:             vars[var[1..-1]] = instance_variable_get(var)
38:           end
39:         end
40:         vars
41:       end
evaluate() click to toggle source

Actually evaluates the view

    # File lib/babylon/base/controller.rb, line 70
70:       def evaluate
71:         @view.evaluate if @view
72:       end
perform(action) click to toggle source

Performs the action and calls back the optional block argument : you should not override this function

    # File lib/babylon/base/controller.rb, line 19
19:       def perform(action)
20:         @action_name = action
21:         begin
22:           self.send(@action_name)
23:         rescue
24:           Babylon.logger.error {
25:             "#{$!}:\n#{$!.backtrace.join("\n")}"
26:           }
27:         end
28:         self.render
29:       end
render(options = {}) click to toggle source

Called by default after each action to “build” a XMPP stanza. By default, it will use the /controller_name/action.xml.builder You can use the following options :

  - :file : render a specific file (can be in a different controller)
  - :action : render another action of the current controller
  - :nothing : doesn't render anything
    # File lib/babylon/base/controller.rb, line 49
49:       def render(options = {}) 
50:         return if @view and !options[:force] # Avoid double rendering, if we have already attached a view
51:         
52:         if options == {} # default rendering
53:           result = render(:file => default_template_name)
54:         elsif options[:file]
55:           file = options[:file]
56:           if file =~ /^\// # Render from view root
57:             result = render_for_file(File.join("app", "views", "#{file}.xml.builder"))
58:           else
59:             result = render_for_file(view_path(file)) 
60:           end
61:         elsif action_name = options[:action]
62:           result = render(:file => default_template_name(action_name.to_s))
63:         elsif options[:nothing]
64:           @view = Babylon::Base::View.new()
65:         end
66:       end

Protected Instance Methods

default_template_name(action_name = nil) click to toggle source

Default template name used to build stanzas

    # File lib/babylon/base/controller.rb, line 84
84:       def default_template_name(action_name = nil)
85:         "#{action_name || @action_name}.xml.builder"
86:       end
render_for_file(file) click to toggle source

Creates the view and “evaluates” it to build the XML for the stanza

    # File lib/babylon/base/controller.rb, line 90
90:       def render_for_file(file)
91:         Babylon.logger.info {
92:           "RENDERING : #{file}"
93:         }
94:         @view = Babylon::Base::View.new(file, assigns)
95:         Babylon.logger.info {
96:           " "
97:         }
98:       end
view_path(file_name) click to toggle source

Builds the view path.

    # File lib/babylon/base/controller.rb, line 78
78:       def view_path(file_name)
79:         File.join("app", "views", "#{self.class.name.gsub("Controller","").downcase}", file_name)
80:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.