Class: Liquid2::BlockDrop

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid2/nodes/tags/extends.rb

Overview

A block object available within {% block %} tags.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, context, name, parent) ⇒ BlockDrop

Returns a new instance of BlockDrop.

Parameters:



243
244
245
246
247
248
# File 'lib/liquid2/nodes/tags/extends.rb', line 243

def initialize(token, context, name, parent)
  @token = token
  @context = context
  @name = name
  @parent = parent
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



237
238
239
# File 'lib/liquid2/nodes/tags/extends.rb', line 237

def token
  @token
end

Instance Method Details

#[](key) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/liquid2/nodes/tags/extends.rb', line 256

def [](key)
  return nil if key != "super" || @parent.nil?

  parent = @parent || raise
  buf = +""
  namespace = { "block" => BlockDrop.new(parent.first.token,
                                         @context,
                                         parent[2].path || parent[2].name,
                                         parent.last) }
  @context.extend(namespace) do
    parent.first.block.render(@context, buf)
  end

  buf.freeze
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


252
253
254
# File 'lib/liquid2/nodes/tags/extends.rb', line 252

def key?(key)
  key == "super" && @parent
end

#to_sObject



250
# File 'lib/liquid2/nodes/tags/extends.rb', line 250

def to_s = "BlockDrop(#{@name})"