Class: Ruta::Handlers
- Inherits:
-
Object
- Object
- Ruta::Handlers
- Defined in:
- lib/ruta/handler.rb
Class Method Summary collapse
-
.define_for(context) { ... } ⇒ Object
define handlers for a context.
Instance Method Summary collapse
-
#default ⇒ Object
Render the default content for this component as it is defined in the context.
-
#handle(handler_name) {|params, path| ... } ⇒ Object
create a handle to be excuted when a matching route is hit.
-
#initialize(context, block) ⇒ Handlers
constructor
A new instance of Handlers.
-
#mount(context) ⇒ Object
wipe the matching element and render a context.
Constructor Details
#initialize(context, block) ⇒ Handlers
Returns a new instance of Handlers.
17 18 19 20 |
# File 'lib/ruta/handler.rb', line 17 def initialize context,block @context = context instance_exec(&block) end |
Class Method Details
.define_for(context) { ... } ⇒ Object
define handlers for a context
62 63 64 65 |
# File 'lib/ruta/handler.rb', line 62 def define_for context, &block new(Context.collection.fetch(context){|c_n|raise"Tried to define handlers for #{c_n} before it exists"}, block) end |
Instance Method Details
#default ⇒ Object
Render the default content for this component as it is defined in the context.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruta/handler.rb', line 35 def default handler_name = @handler_name proc { comp = @context.elements[handler_name][:content] if comp.kind_of?(Proc) comp.call else Context.wipe handler_name Context.render comp, handler_name end } end |
#handle(handler_name) {|params, path| ... } ⇒ Object
create a handle to be excuted when a matching route is hit
11 12 13 14 |
# File 'lib/ruta/handler.rb', line 11 def handle handler_name,&handler @handler_name = handler_name @context.handlers[@handler_name] = handler end |