Sha256: 618d6fddb493b9859b1b1490e0e58ce58c0a2cbce3605fa7e2883f7f4e10b524

Contents?: true

Size: 1.98 KB

Versions: 92

Compression:

Stored size: 1.98 KB

Contents

module Radius
  #
  # 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.
  #
  class TagBinding
    # The Context that the TagBinding is associated with. Used internally. Try not to use
    # this object directly.
    attr_reader :context
  
    # The locals object for the current tag.
    attr_reader :locals
  
    # The name of the tag (as used in a template string).
    attr_reader :name
  
    # The attributes of the tag. Also aliased as TagBinding#attr.
    attr_reader :attributes
    alias :attr :attributes
  
    # The render block. When called expands the contents of the tag. Use TagBinding#expand
    # instead.
    attr_reader :block
  
    # Creates a new TagBinding object.
    def initialize(context, locals, name, attributes, block)
      @context, @locals, @name, @attributes, @block = context, locals, name, attributes, block
    end
  
    # Evaluates the current tag and returns the rendered contents.
    def expand
      double? ? block.call : ''
    end

    # Returns true if the current tag is a single tag.
    def single?
      block.nil?
    end

    # Returns true if the current tag is a container tag.
    def double?
      not single?
    end
  
    # The globals object from which all locals objects ultimately inherit their values.
    def globals
      @context.globals
    end
  
    # Returns a list of the way tags are nested around the current tag as a string.
    def nesting
      @context.current_nesting
    end
  
    # Fires off Context#tag_missing for the current tag.
    def missing!
      @context.tag_missing(name, attributes, &block)
    end
  
    # Renders the tag using the current context .
    def render(tag, attributes = {}, &block)
      @context.render_tag(tag, attributes, &block)
    end
  
    # Shortcut for accessing tag.attr[key]
    def [](key)
      attr[key]
    end
  end
end

Version data entries

92 entries across 60 versions & 10 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/radius-0.7.5/lib/radius/tag_binding.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/radius-0.8.0/lib/radius/tag_binding.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/radius-0.7.5/lib/radius/tag_binding.rb
radius-0.8.0 lib/radius/tag_binding.rb
radius-0.7.5 lib/radius/tag_binding.rb
bkerley-radius-0.6.1 lib/radius/tagbinding.rb
depengine-0.0.31 etc/isolate/jruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.31 etc/isolate/ruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.30 etc/isolate/ruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.30 etc/isolate/jruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.29 etc/isolate/jruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.29 etc/isolate/ruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.28 etc/isolate/jruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.28 etc/isolate/ruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.27 etc/isolate/jruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.27 etc/isolate/ruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.26 etc/isolate/jruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.26 etc/isolate/ruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.25 etc/isolate/ruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb
depengine-0.0.25 etc/isolate/jruby-1.8/gems/radius-0.6.1/lib/radius/tag_binding.rb