| Path: | README |
| Last Update: | Mon Sep 08 23:05:18 +0100 2008 |
Description:
reparcs is a XHTML generation library for Ruby, and written in ruby.
Features:
-Generation of XHTML documents using nothing but Ruby.
-Creates well-formed, Valid XHMTL(reparcs won't let you create invalid markup).
-Numerous shortcut methods for common tasks
-Add javascript(scriptaculous) effects using nothing but Ruby.
Download & Installation:
You need to have gems install, and simply type the following...
gem install reparcs
License:
MIT(see LICENSE file)
Author & maintainer:
Lee Caine | kanodii@gmail.com | http://kanodi.com
Homepage:
http://reparcs.rubyforge.org
Rubyforge project page:
http://rubyforge.org/projects/reparcs
Example:
#Include the library
require 'rubygems'
require 'reparcs'
#Create a new website
my_project = Website.new
#Create and add a page
index_page = Page.new
my_project.append("index", index_page)
#Now lets design the page...
#Set the title
index_page.head.append(shortcut_title("Home"))
#Create a layer 'div'
main_layer = Division.new
#Add a header
main_layer.append(shortcut_header(1, "Welcome.."))
#Add a paragraph with some text..
para = Paragraph.new
para.append(%{
"Welcome to my site, it contains a whole bunch of crap...."
})
#Add the paragraph to the layer
main_layer.append(para)
#Lets add some links
links = [
shortcut_anchor("http://google.co.uk", "Google"),
shortcut_anchor("http://rubyforge.org", "Rubyforge"),
shortcut_anchor("http://kanodi.com", "Kanodi"),
shortcut_anchor("http://reparcs.rubyforge.org", "Reparcs")
]
ul = shortcut_unordered_list(links)
main_layer.append(ul)
#I suppose we better add the layer to the page's body..
index_page.body.append(main_layer)
#It is all going to look a little boring lets style it..
#before we add some css, we better add some id attributes to
#our elements
main_layer.set_attribute("id", "main")
ul.set_attribute("id", "links")
#Ok lets add some style
index_page.head.append(shortcut_style(%{
#main {
width: 400px;
border: 5px solid #666666
float: left;
}
#links {
list-style-type: none;
}
#links ul li {
display: block;
}
})
#Why we are at it shall we add some cool effects?...
#To add an effect to an element it must have an id attribute
#So lets add id's to out anchors..
id = 0
links.each do |l|
l.set_attribute("id", "link#{id}")
id += 1
#We may aswell add the effect whilst we are in the loop
index_page.add_effect(l, "onmouseover", "Grow")
end
#Aswell as setting the effect, we need to include the prototype &
#scriptaculous libraries..
my_project.include_scriptaculous_files
index_page.include_scriptaculous
#Now lets publish the whole lot
my_project.publish("/Users/bigk/Desktop/www")
#This would create 1 html file called "index.html" and a javascript directory containing all the
#scriptaculous library files.