A
download BindingsParser.rb
Language: Ruby
LOC: 32
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

# Parse through binding declarations to resolve bindings.
# Resolved bindings are stored within an object variable,
# @bindings.

class BindingsParser

	MainPattern = /([\w.]+)\s*(:\s*(\w+)\s*)?[{](.*?)^\s*[}]/m

	BodyPattern = /(\w+)\s*=\s*(.+)/

        TrimPattern = /\s*$/
	
	# Apply the MainPattern to the binding data, passing matched
	# information to processMatch().

	def initialize(data)
		@bindings = {}
		while data.sub!(MainPattern, "")
			processMatch($1, $3, $4)
		end
	end

	# Create the defined binding.	

	def processMatch(id, klass, data)
		bindingHash = {}
		
		if klass
			bindingHash["class"] = klass
		end
	
		while data.sub!(BodyPattern, "")
			key, value = $1, $2
			value.sub!(TrimPattern,"")
			# Just to make sure it is clear, if the binding value either
			# starts with a digit, a quote character, or a colon, then
			# it is assumed to be literal binding.  The value will be
			# ran through eval, and whatever is returned will be used
			# as the value of the binding.
			if value =~ /^[\d"':]/
				bindingHash[key] = LiteralAssociation.new(eval(value))
			else
				bindingHash[key] = PathAssociation.new(value)
			end
		end

		@bindings[id] = bindingHash
	end

	# Return the Hash of bindings.	

	def bindings
		@bindings
	end
end

end

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