Module: Rango::ExplicitRendering
Instance Method Summary collapse
-
#context ⇒ Object
def show context = Post.get(params) render “show.html”, context end.
- #context_keys ⇒ Object
- #get_context_value(key) ⇒ Object
- #render(template, context = Hash.new) ⇒ Object
-
#scope ⇒ Object
class Posts < Rango::Controller def scope Object.new end.
- #set_context_value(key, value) ⇒ Object
Instance Method Details
#context ⇒ Object
def show
context[:post] = Post.get(params[:id])
render "show.html", context
end
88 89 90 |
# File 'lib/rango/mixins/rendering.rb', line 88 def context @context ||= {request: self.request} end |
#context_keys ⇒ Object
100 101 102 |
# File 'lib/rango/mixins/rendering.rb', line 100 def context_keys @context.keys end |
#get_context_value(key) ⇒ Object
92 93 94 |
# File 'lib/rango/mixins/rendering.rb', line 92 def get_context_value(key) @context[key] end |
#render(template, context = Hash.new) ⇒ Object
61 62 63 |
# File 'lib/rango/mixins/rendering.rb', line 61 def render(template, context = Hash.new) super(template, self.scope, self.context.merge!(context)) end |
#scope ⇒ Object
class Posts < Rango::Controller
def scope
Object.new
end
def show
# you can't use @explicit
post = Post.get(params[:id])
render "post.html", post: post
end
end
Context for rendering templates This scope will be extended by same crucial methods from template mixin We are in scope of current controller by default
80 81 82 |
# File 'lib/rango/mixins/rendering.rb', line 80 def scope Object.new.extend(Rango::Helpers) end |
#set_context_value(key, value) ⇒ Object
96 97 98 |
# File 'lib/rango/mixins/rendering.rb', line 96 def set_context_value(key, value) @context[key] = value end |