| Path: | SiteGenerator_Tag.rb |
| Last Update: | Mon Mar 28 19:25:59 Westeuropäische Sommerzeit 2005 |
SiteGeneratorTag.rb
Based on Version 1.0.4 of Tag.rb from MoonWolf <moonwolf-ruby@moonwolf.com>. www.moonwolf.com/ruby/tag.html raa.ruby-lang.org/project/tag/
I missed some features of the tag.rb-code. So I extended the Tag-class of the original tag.rb, later I rewrote it.
Changes:
Example of usage:
require "tag"
doc = []
html = Tag('html') #<html>
doc << html #doc
html << head = Tag('head') #html
head << (Tag('title') << "TITLE") #head
html << body = Tag('body',{'bgcolor'=>'#FFFFFF'})
#<body bgcolor="#FFFFFF">
print doc.to_s #HTML
Result is:
<html><head><title>TITLE</title></head><body bgcolor="#FFFFFF"></body></html>
Example2:
img = Tag('img/')
img['src']='xxx.png' #<img src="xxx.png">
o = Tag('option')
o['selected']=true #<option selected>
Differences between tag.rb and WebSiteTag.rb:
-
This part of teh Sitegenerator should be replaced by DocGenerator.
Create a Tag directly without a new. This feature allows also the usage of a block.
Usage:
Tag(tagname [, attr [, item]])
Tag(tagname [, attr [, item]]) {...}
Example:
Tag('a', {'href'=> 'url'} )
Tag('a', {'href'=> 'url'}, 'content' )
Tag('a', {'href'=> 'url'} ){'content' }
Tag('a', {'href'=> 'url'}, ['x'] ){'content' }
returns:
<a href="url"></a>
<a href="url">content</a>
<a href="url">content</a>
<a href="url">xcontent</a>
If a tag without content is required (e.g. img has only attributes, or br) the tagname must contain a ’/’ in the end. Example:
Tag('br/')