Module: Pancake::Mixins::Render::InstanceMethods

Defined in:
lib/pancake/mixins/render.rb

Overview

ClassMethods

Instance Method Summary collapse

Instance Method Details

#partial(*args) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/pancake/mixins/render.rb', line 131

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(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

Yields:

  • (v)


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/pancake/mixins/render.rb', line 115

def render(*args)
  opts          = Hash === args.last ? args.pop : {}
  name          = args.shift
  template      = self.class.template(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)

  yield v if block_given?

  view_context = vc_class.new(self)
  view_context_before_render(view_context)
  view_context.render(template, opts)
end

#template(name_or_template, opts = {}) ⇒ Object



159
160
161
# File 'lib/pancake/mixins/render.rb', line 159

def template(name_or_template, opts = {})
  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!



168
169
# File 'lib/pancake/mixins/render.rb', line 168

def view_context_before_render(context)
end