Class Skates::Base::Controller
In: lib/skates/base/controller.rb
Parent: Object

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

Methods

Attributes

action_name  [RW] 
rendered  [RW] 
stanza  [RW] 

Public Class methods

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.

[Source]

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

Public Instance methods

Returns the list of variables assigned during the action.

[Source]

    # File lib/skates/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

Actually evaluates the view

[Source]

    # File lib/skates/base/controller.rb, line 70
70:       def evaluate
71:         @view.evaluate if @view
72:       end

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

[Source]

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

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

[Source]

    # File lib/skates/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 = Skates::Base::View.new()
65:         end
66:       end

Render and evaluate a given view

[Source]

    # File lib/skates/base/controller.rb, line 76
76:       def render_and_evaluate(options = {})
77:         render(options)
78:         evaluate
79:       end

Renders, evaluate and sends

[Source]

    # File lib/skates/base/controller.rb, line 83
83:       def render_evaluate_and_send(options)
84:         response = render_and_evaluate(options)
85:         Skates.router.connection.send_xml response 
86:       end

Protected Instance methods

Default template name used to build stanzas

[Source]

     # File lib/skates/base/controller.rb, line 98
 98:       def default_template_name(action_name = nil)
 99:         "#{action_name || @action_name}.xml.builder"
100:       end

Creates the view and "evaluates" it to build the XML for the stanza

[Source]

     # File lib/skates/base/controller.rb, line 104
104:       def render_for_file(file)
105:         Skates.logger.info {
106:           "RENDERING : #{file}"
107:         }
108:         @view = Skates::Base::View.new(file, assigns)
109:         Skates.logger.info {
110:           " "
111:         }
112:       end

Builds the view path.

[Source]

    # File lib/skates/base/controller.rb, line 92
92:       def view_path(file_name)
93:         File.join("app", "views", "#{self.class.name.gsub("Controller","").downcase}", file_name)
94:       end

[Validate]