Class: Babylon::Base::Controller
- Inherits:
-
Object
- Object
- Babylon::Base::Controller
- Defined in:
- lib/babylon/base/controller.rb
Overview
Your application’s controller should be descendant of this class.
Instance Attribute Summary collapse
-
#action_name ⇒ Object
Stanza received by the controller (Nokogiri::XML::Node).
-
#rendered ⇒ Object
Stanza received by the controller (Nokogiri::XML::Node).
-
#stanza ⇒ Object
Stanza received by the controller (Nokogiri::XML::Node).
Instance Method Summary collapse
-
#assigns ⇒ Object
Returns the list of variables assigned during the action.
-
#evaluate ⇒ Object
Actually evaluates the view.
-
#initialize(stanza = nil) ⇒ Controller
constructor
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.
-
#perform(action) ⇒ Object
Performs the action and calls back the optional block argument : you should not override this function.
-
#render(options = {}) ⇒ Object
Called by default after each action to “build” a XMPP stanza.
- #render_and_evaluate(options = {}) ⇒ Object
- #render_evaluate_and_send(options) ⇒ Object
Constructor Details
#initialize(stanza = nil) ⇒ Controller
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.
12 13 14 15 |
# File 'lib/babylon/base/controller.rb', line 12 def initialize(stanza = nil) @stanza = stanza @view = nil end |
Instance Attribute Details
#action_name ⇒ Object
Stanza received by the controller (Nokogiri::XML::Node)
8 9 10 |
# File 'lib/babylon/base/controller.rb', line 8 def action_name @action_name end |
#rendered ⇒ Object
Stanza received by the controller (Nokogiri::XML::Node)
8 9 10 |
# File 'lib/babylon/base/controller.rb', line 8 def rendered @rendered end |
#stanza ⇒ Object
Stanza received by the controller (Nokogiri::XML::Node)
8 9 10 |
# File 'lib/babylon/base/controller.rb', line 8 def stanza @stanza end |
Instance Method Details
#assigns ⇒ Object
Returns the list of variables assigned during the action.
33 34 35 36 37 38 39 40 41 |
# File 'lib/babylon/base/controller.rb', line 33 def assigns vars = Hash.new instance_variables.each do |var| if !["@view", "@action_name", "@block"].include? var vars[var[1..-1]] = instance_variable_get(var) end end vars end |
#evaluate ⇒ Object
Actually evaluates the view
70 71 72 |
# File 'lib/babylon/base/controller.rb', line 70 def evaluate @view.evaluate if @view end |
#perform(action) ⇒ Object
Performs the action and calls back the optional block argument : you should not override this function
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/babylon/base/controller.rb', line 19 def perform(action) @action_name = action begin self.send(@action_name) rescue Babylon.logger.error { "#{$!}:\n#{$!.backtrace.join("\n")}" } end self.render end |
#render(options = {}) ⇒ Object
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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/babylon/base/controller.rb', line 49 def render( = {}) return if @view and ![:force] # Avoid double rendering, if we have already attached a view if == {} # default rendering result = render(:file => default_template_name) elsif [:file] file = [:file] if file =~ /^\// # Render from view root result = render_for_file(File.join("app", "views", "#{file}.xml.builder")) else result = render_for_file(view_path(file)) end elsif action_name = [:action] result = render(:file => default_template_name(action_name.to_s)) elsif [:nothing] @view = Babylon::Base::View.new() end end |
#render_and_evaluate(options = {}) ⇒ Object
74 75 76 77 |
# File 'lib/babylon/base/controller.rb', line 74 def render_and_evaluate( = {}) render() evaluate end |