Module: Pancake::Mixins::Render::ViewContext::ContentInheritance

Included in:
Pancake::Mixins::Render::ViewContext
Defined in:
lib/pancake/mixins/render/render.rb

Overview

Capture

Defined Under Namespace

Classes: Helper

Instance Method Summary collapse

Instance Method Details

#content_block(label = nil, &block) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/pancake/mixins/render/render.rb', line 146

def content_block(label = nil, &block)
  return self if label.nil?
  current_label = @_inherit_helper.current_label
  @_inherit_helper.current_label = label
  capture_method = ViewContext.capture_method_for(_current_renderer)
  @_inherit_helper.blocks[label] << [block, capture_method]
  if @_inherit_helper.inherits_from.nil?
    result = _capture_content_block(label)
    send(ViewContext.concat_method_for(_current_renderer), result)
  end
  @_inherit_helper.current_label = current_label
end

#inherits_from(ntos, name_or_opts = nil, opts = {}) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pancake/mixins/render/render.rb', line 123

def inherits_from(ntos, name_or_opts = nil, opts = {})
  name_or_template = case ntos
  when String, Symbol
    if ntos == :default!
      begin
        Pancake.default_base_template(:format => content_type)
      rescue
        :base
      end
    else
      ntos
    end
  else
    if name_or_opts.kind_of?(Hash)
      opts = name_or_opts
      name_or_opts = nil
    end
    name_or_opts ||= ntos.base_template_name
    ntos.template(name_or_opts, opts)
  end
  @_inherit_helper.inherits_from = name_or_template
end

#initialize(*args) ⇒ Object



118
119
120
121
# File 'lib/pancake/mixins/render/render.rb', line 118

def initialize(*args)
  super()
  @_inherit_helper = Helper.new
end

#superObject



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

def super
  @_inherit_helper.increment_super!
  result = _capture_content_block(@_inherit_helper.current_label)
  @_inherit_helper.decrement_super!
  result
end