Module: Pancake::Mixins::Render::InstanceMethods
- Defined in:
- lib/pancake/mixins/render.rb
Overview
ClassMethods
Instance Method Summary collapse
- #content_type ⇒ Object
- #content_type=(format) ⇒ Object
- #mime_type ⇒ Object
- #mime_type=(mime) ⇒ Object
- #negotiate_content_type!(*allowed_types) ⇒ Object
- #partial(*args) ⇒ Object
- #render(*args) {|v| ... } ⇒ Object
- #template(name_or_template, opts = {}) ⇒ Object
-
#view_context_before_render(context) ⇒ Object
A place holder method for any implementor that wants to configure the view context prior to rendering occuring any time this method is overwritten, it should call super!.
Instance Method Details
#content_type ⇒ Object
156 157 158 |
# File 'lib/pancake/mixins/render.rb', line 156 def content_type env['pancake.request.format'] end |
#content_type=(format) ⇒ Object
160 161 162 |
# File 'lib/pancake/mixins/render.rb', line 160 def content_type=(format) env['pancake.request.format'] = format end |
#mime_type ⇒ Object
164 165 166 |
# File 'lib/pancake/mixins/render.rb', line 164 def mime_type env['pancake.request.mime'] end |
#mime_type=(mime) ⇒ Object
168 169 170 |
# File 'lib/pancake/mixins/render.rb', line 168 def mime_type=(mime) env['pancake.request.mime'] = mime end |
#negotiate_content_type!(*allowed_types) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/pancake/mixins/render.rb', line 136 def negotiate_content_type!(*allowed_types) return content_type if content_type allowed_types = allowed_types.flatten opts = allowed_types.pop if allowed_types.last.kind_of?(Hash) if opts[:format] cont, ct, mt = Pancake::MimeTypes.negotiate_by_extension(opts[:format].to_s, allowed_types) else env["HTTP_ACCEPT"] ||= "*/*" cont, ct, mt = Pancake::MimeTypes.negotiate_accept_type(env["HTTP_ACCEPT"], allowed_types) end raise Errors::NotAcceptable unless cont headers["Content-Type"] = ct self.mime_type = mt self.content_type = cont cont end |
#partial(*args) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pancake/mixins/render.rb', line 103 def partial(*args) opts = Hash === args.last ? args.pop : {} opts = opts.dup name = args.shift with = opts.delete(:with) as = opts.delete(:as) partial_name = _partial_template_name_for(name, opts) # Get the view context for the tempalte template, vc_class = self.class._renderer_and_view_context_class_for(partial_name) view_context = vc_class.new(env, self) view_context_before_render(view_context) out = "" if with.kind_of?(Array) with.each do |item| as.nil? ? (opts[name] = item) : (opts[as] = item) out << view_context.render(template, opts) end else as.nil? ? (opts[name] = with) : (opts[as] = with) out << view_context.render(template, opts) end out end |
#render(*args) {|v| ... } ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pancake/mixins/render.rb', line 87 def render(*args) opts = Hash === args.last ? args.pop : {} name = args.shift template_name = _template_name_for(name, opts) return opts[:text] if opts[:text] # Get the view context for the tempalte template, vc_class = self.class._renderer_and_view_context_class_for(template_name) yield v if block_given? view_context = vc_class.new(env, self) view_context_before_render(view_context) view_context.render(template, opts) end |
#template(name_or_template, opts = {}) ⇒ Object
131 132 133 134 |
# File 'lib/pancake/mixins/render.rb', line 131 def template(name_or_template, opts = {}) opts[:format] ||= content_type self.class.template(name_or_template, opts) end |
#view_context_before_render(context) ⇒ Object
A place holder method for any implementor that wants to configure the view context prior to rendering occuring any time this method is overwritten, it should call super!
179 180 |
# File 'lib/pancake/mixins/render.rb', line 179 def view_context_before_render(context) end |