Include this Mixin to a class to make objects of this class publishable, ie accessible through a standard web (REST) interface.
- action?
- action_methods
- action_or_template?
- alias_action
- included
- method_missing
- mount_at
- setup_template_dir_stack
- template?
[ show source ]
# File lib/raw/controller/publishable.rb, line 25
25: def self.included(base)
26: super
27: base.send(:include, Flashing)
28: base.send(:include, Caching)
29: end
Check if the controller responds to this action.
[ show source ]
# File lib/raw/controller/publishable.rb, line 62
62: def action?(action)
63: action_methods.include?(action.to_s)
64: end
Return the ‘action’ methods for this Object. Some dangerous methods from ancestors are removed. All private methods are ignored.
[ show source ]
# File lib/raw/controller/publishable.rb, line 55
55: def action_methods
56: public_instance_methods - Controller.public_instance_methods
57: end
Check if this action or template exists.
[ show source ]
# File lib/raw/controller/publishable.rb, line 106
106: def action_or_template?(action, format)
107: action?(action) or template?(action, format)
108: end
Aliases an action
[ show source ]
# File lib/raw/controller/publishable.rb, line 117
117: def alias_action(new, old)
118: alias_method new, old
119: ann new, :template => old
120: end
Use the method_missing hook to compile the actions for this controller.
[ show source ]
# File lib/raw/controller/publishable.rb, line 34
34: def method_missing(action, *args)
35: if Context.current.application.compiler.compile(self.class, action)
36: send(action, *args)
37: else
38: super
39: end
40: end
This callback is called when this controller is mounted.
[ show source ]
# File lib/raw/controller/publishable.rb, line 143
143: def mount_at(path)
144: @mount_path = path
145:
146: # Setup the template_dir_stack.
147:
148: stack = []
149: stack << File.join(Template.root_dir, path).gsub(/\/$/, "")
150: self.setup_template_dir_stack(stack)
151: stack << File.join(Nitro.proto_path, "template", path).gsub(/\/$/, "")
152: ann(:self, :template_dir_stack => stack)
153: end
Override this method to customize the template_dir_stack. Typically used in controllers defined in reusable Parts. Call super to include the parent class’s customizations. Implements some form of template root inheritance, thus allowing for more reusable controllers. Ie you can ‘extend’ a controller, and only override the templates you want to change. The compiler will traverse the template dir stack and use the templates from parent controllers if they are not overriden.
def self.setup_template_dir_stack(stack)
super
stack << "custom/route/#{self.mount_path}"
stack << "another/route"
end
[ show source ]
# File lib/raw/controller/publishable.rb, line 138
138: def setup_template_dir_stack(path)
139: end
Check if the a template for this action and format exists. Returns a valid path or nil.
[ show source ]
# File lib/raw/controller/publishable.rb, line 70
70: def template?(action, format)
71: # Allow for template override using the :template annotation
72: #
73: # class MyController
74: # def myaction
75: # end
76: # ann :myaction, :template => :another_template
77: # end
78:
79: template = ann(action, :template) || action
80:
81: template = template.to_s.gsub(/__/, "/")
82:
83: for dir in ann(:self, :template_dir_stack)
84: name = "#{dir}/#{template}".squeeze("/")
85:
86: # attempt to find a template of the form:
87: # dir/action.xhtml
88:
89: path = "#{name}.#{format.template_extension}"
90: return path if File.exist?(path)
91:
92: # attempt to find a template of the form:
93: # dir/action/index.xhtml
94:
95: path = "#{name}/index.#{format.template_extension}"
96: return path if File.exist?(path)
97: end
98:
99: return nil
100: end