A
download Element.rb
Language: Ruby
LOC: 69
Project Info
IOWA
Server: RubyForge
Type: cvs
...Forge\i\iowa\iowa\iowa\src\
   Application.rb
   ApplicationStats.rb
   Association.rb
   BindingsParser.rb
   Client.rb
   Component.rb
   ComponentProxy.rb
   config.rb
   Context.rb
   DbPool.rb
   DynamicElements.rb
   Element.rb
   Form.rb
   HTTPServer.rb
   ISAAC.rb
   KeyValueCoding.rb
   LRUCache.rb
   PageStore.rb
   read_multipart.rb
   Request.rb
   SciTE.properties
   Session.rb
   SessionStats.rb
   SessionStore.rb
   Tag.rb
   TemplateParser.rb
   WEBrickServlet.rb

module Iowa

# Superclass for all Iowa elements.  An element is something that looks
# like an HTML tag, and is in many cases named like an HTML tag, but
# that implements some sort of dynamic behavior.

class Element

	ElementClasses={"element" => Element}
	def Element.inherited(subclass)
		if subclass.name[0,34] == 'Iowa::Application::Content_Classes'
			ElementClasses[subclass.name.sub(/Iowa::Application::Content_Classes::/,'').downcase] = subclass
		else
			ElementClasses[subclass.name.split("::").last.downcase] = subclass
		end
	end
	
	def Element.newElement(classname, name, bindings, attributes)
		mylog = Logger['iowa_log']
		if name == "BodyContent"
			BodyContent.new(name, bindings, attributes)
		else
			klass = ElementClasses[classname.downcase]
			begin
				unless klass.ancestors.include?(Component)
					klass.new(name, bindings, attributes)	
				else
					ComponentProxy.new(klass, name, bindings, attributes)
				end
			rescue Exception
				el = ''
				ElementClasses.each_pair do |k,v|
					el << "#{k} == #{v}<br/>\n"
				end
			
				raise "unknown Element type: #{classname}<br/>\n#{el}"
				
			end
		end
	end
	
	attr_accessor :name, :children
	
	def initialize(name, bindings, attributes)
		@name = name
		@attributes = attributes
		@bindings = {}
		defaultBindings()

		bindings.each do |key,val|
			@bindings[key]=val
		end

		@children = []
	end
	
	def addChild(child)
		@children.push child
	end
	
	def each(&b)
		@children.each(&b)
	end
	
	def defaultBindings
	end
	
	def handleChildren(method, context)
		context.pushElement
		for child in @children
			context.nextElement!
			child.send(method, context)
		end
		context.popElement
	end
	
	def handleRequestOrResponse(method, context)
		handleChildren(method, context)
	end
	
	def handleRequest(context)
		handleRequestOrResponse(:handleRequest, context)
	end

	def handleResponse(context)
		handleRequestOrResponse(:handleResponse, context)
	end	
end

end

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us