Class: Radius::TagBinding
- Inherits:
-
Object
- Object
- Radius::TagBinding
- 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
-
#attributes ⇒ Object
(also: #attr)
readonly
The attributes of the tag.
-
#block ⇒ Object
readonly
The render block.
-
#context ⇒ Object
readonly
The Context that the TagBinding is associated with.
-
#locals ⇒ Object
readonly
The locals object for the current tag.
-
#name ⇒ Object
readonly
The name of the tag (as used in a template string).
Instance Method Summary collapse
-
#[](key) ⇒ Object
Shortcut for accessing tag.attr.
-
#double? ⇒ Boolean
Returns true if the current tag is a container tag.
-
#expand ⇒ Object
Evaluates the current tag and returns the rendered contents.
-
#globals ⇒ Object
The globals object from which all locals objects ultimately inherit their values.
-
#initialize(context, locals, name, attributes, block) ⇒ TagBinding
constructor
Creates a new TagBinding object.
-
#missing! ⇒ Object
Fires off Context#tag_missing for the current tag.
-
#nesting ⇒ Object
Returns a list of the way tags are nested around the current tag as a string.
-
#render(tag, attributes = {}, &block) ⇒ Object
Renders the tag using the current context .
-
#single? ⇒ Boolean
Returns true if the current tag is a single tag.
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
#attributes ⇒ Object (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 |
#block ⇒ Object (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 |
#context ⇒ Object (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 |
#locals ⇒ Object (readonly)
The locals object for the current tag.
13 14 15 |
# File 'lib/radius/tag_binding.rb', line 13 def locals @locals end |
#name ⇒ Object (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.
42 43 44 |
# File 'lib/radius/tag_binding.rb', line 42 def double? not single? end |
#expand ⇒ Object
Evaluates the current tag and returns the rendered contents.
32 33 34 |
# File 'lib/radius/tag_binding.rb', line 32 def double? ? block.call : '' end |
#globals ⇒ Object
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 |
#nesting ⇒ Object
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.
37 38 39 |
# File 'lib/radius/tag_binding.rb', line 37 def single? block.nil? end |