Module: Rango::ExplicitRendering

Includes:
RenderMixin
Included in:
StackController
Defined in:
lib/rango/mixins/rendering.rb

Instance Method Summary collapse

Instance Method Details

#contextObject

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_keysObject



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

#scopeObject

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