Ikko (project page, download) is a little templating engine. Rich Kilmer wrote it, and Tom Copeland is maintaining it. It's very simple and is only suitable for small projects. Fortunately, there are many of those around :-)
Say you want to plug some HTML into a little page:
<html> <body> <!--Fragment key="name"--> </body> </html>
Put ikko.rb in the same directory as your script and write a little script:
#!/usr/local/bin/ruby
require '/var/build/dashboard/ikko'
fm=Ikko::FragmentManager.new
fm.base_path="."
puts fm["index.frag", {"name"=>"Fred"}]
And run it:
[tom@ultraforge tmp]$ ./demo.rb <html> <body> Fred </body> </html> [tom@ultraforge tmp]$
You can include an entire file without replacing any tags:
puts fm["name.txt"]
Your fragment file can specify a default value if the key is nil:
<html> <!--Fragment key="name" empty="Nobody"--> </html>
Your fragment file can specify a prefix to each value:
<html> <!--Fragment key="name" empty="Nobody" prefix="The name specified was "--> </html>
Or a suffix:
<html> <!--Fragment key="name" empty="Nobody" suffix=" was the name"--> </html>
That's a start; please post any thoughts to the forum. Thanks!