Class: Radius::TagBinding

Inherits:
Object
  • Object
show all
Defined in:
lib/radius/tag_binding.rb

Overview

A tag binding is passed into each tag definition and contains helper methods for working with tags. Use it to gain access to the attributes that were passed to the tag, to render the tag contents, and to do other tasks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, locals, name, attributes, block) ⇒ TagBinding

Creates a new TagBinding object.



27
28
29
# File 'lib/radius/tag_binding.rb', line 27

def initialize(context, locals, name, attributes, block)
  @context, @locals, @name, @attributes, @block = context, locals, name, attributes, block
end

Instance Attribute Details

#attributesObject (readonly) Also known as: attr

The attributes of the tag. Also aliased as TagBinding#attr.



19
20
21
# File 'lib/radius/tag_binding.rb', line 19

def attributes
  @attributes
end

#blockObject (readonly)

The render block. When called expands the contents of the tag. Use TagBinding#expand instead.



24
25
26
# File 'lib/radius/tag_binding.rb', line 24

def block
  @block
end

#contextObject (readonly)

The Context that the TagBinding is associated with. Used internally. Try not to use this object directly.



10
11
12
# File 'lib/radius/tag_binding.rb', line 10

def context
  @context
end

#localsObject (readonly)

The locals object for the current tag.



13
14
15
# File 'lib/radius/tag_binding.rb', line 13

def locals
  @locals
end

#nameObject (readonly)

The name of the tag (as used in a template string).



16
17
18
# File 'lib/radius/tag_binding.rb', line 16

def name
  @name
end

Instance Method Details

#[](key) ⇒ Object

Shortcut for accessing tag.attr



67
68
69
# File 'lib/radius/tag_binding.rb', line 67

def [](key)
  attr[key]
end

#double?Boolean

Returns true if the current tag is a container tag.

Returns:

  • (Boolean)


42
43
44
# File 'lib/radius/tag_binding.rb', line 42

def double?
  not single?
end

#expandObject

Evaluates the current tag and returns the rendered contents.



32
33
34
# File 'lib/radius/tag_binding.rb', line 32

def expand
  double? ? block.call : ''
end

#globalsObject

The globals object from which all locals objects ultimately inherit their values.



47
48
49
# File 'lib/radius/tag_binding.rb', line 47

def globals
  @context.globals
end

#missing!Object

Fires off Context#tag_missing for the current tag.



57
58
59
# File 'lib/radius/tag_binding.rb', line 57

def missing!
  @context.tag_missing(name, attributes, &block)
end

#nestingObject

Returns a list of the way tags are nested around the current tag as a string.



52
53
54
# File 'lib/radius/tag_binding.rb', line 52

def nesting
  @context.current_nesting
end

#render(tag, attributes = {}, &block) ⇒ Object

Renders the tag using the current context .



62
63
64
# File 'lib/radius/tag_binding.rb', line 62

def render(tag, attributes = {}, &block)
  @context.render_tag(tag, attributes, &block)
end

#single?Boolean

Returns true if the current tag is a single tag.

Returns:

  • (Boolean)


37
38
39
# File 'lib/radius/tag_binding.rb', line 37

def single?
  block.nil?
end