Sha256: 1fff0c4ba1dd3ea263d6ac6b10c420da77b694ce66bde300134d37024cf3d688

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

require 'nano/string/capitalized'
require 'nano/string/camelize'
require 'mega/annotation'

require 'glue/flexob'
require 'glue/configuration'

# load the element compiler here for compatibility?
#require 'nitro/compiler/elements'

module Nitro

# A programmatically generated element.
# 
# === Design
#
# An underscore is used for the standard attibutes to
# avoid name clashes.
#--
# TODO: 
# * separate 'view' template files.
#++

class Element
  # The prefix for element tags (in xhtml compatibility mode)
  
  setting :prefix, :default => 'x', :doc => 'The prefix for element tags'

  # The parent of this element.
  
  attr_accessor :_parent
  
  # The children of this element.
  
  attr_accessor :_children
  
  # The named children of this element.
  
  attr_accessor :_named
  
  # The text of this element.
  
  attr_accessor :_text

  # The view of this element.
  
  attr_accessor :_view

  def initialize(*args)
    @_children = []
    @_named = Flexob.new
    @_text = ''
  end
    
  def open
  end
  
  # If an optional name parameter is passed renders
  # the content of the named child element.
  
  def content(cname = nil)
    if cname
      @_named[cname].content
    else
      @_text
    end
  end
  
  def close
  end  

  def render
    "#{open}#{content}#{close}"
  end

  def render_children
    str = ''
    for c in @_children
      str << c.render
    end
    
    return str
  end  
  
  def add_child(child)
    child._parent = self  
    @_children << child
    if cname = child.class.ann.self[:name]
      @_named[cname] = child
    end
  end
  
  alias_method :children, :_children
  
  class << self
    def name(sym)
      ann self, :name => sym.to_sym
    end
  end
end

end
# * George Moschovitis <gm@navel.gr>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.26.0 lib/nitro/element.rb