Module: Pancake::Mixins::Render::InstanceMethods
- Defined in:
- lib/pancake/mixins/render.rb
Overview
ClassMethods
Instance Method Summary collapse
- #partial(*args) ⇒ Object
- #render(*args) {|v| ... } ⇒ Object
- #template(name_or_template) ⇒ 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
#partial(*args) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/pancake/mixins/render.rb', line 84 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 = "" case with when 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pancake/mixins/render.rb', line 68 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) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/pancake/mixins/render.rb', line 112 def template(name_or_template) case name_or_template when String, Symbol self.class._find_template(_template_name_for(name_or_template, {})) when Template name_or_template else nil end 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!
129 130 |
# File 'lib/pancake/mixins/render.rb', line 129 def view_context_before_render(context) end |