PDA

View Full Version : Template processing in ruby


elriba
January 31st, 2006, 03:14 PM
I would like to process a text file which contains macros (or user-defined symbols) and generate output.

The format I would like to use is something like this (the specific characters used to signal might be different):

#!This is a comment
#DECLARE(%mySymbol) #!Here I declare a macro or symbol for use
#SET(%mySymbol,1) #!assign a value of 1

#!The code that goes below goes straight into the output,
#!except where the #IF is evaluated.
class myTestClass
def initialize
#IF(%mySymbol)
@msg = 'Test1'
#ELSE
@msg = 'Test2'
#ENDIF
end
end

The output would be:

class myTestClass
def initialize
@msg = 'Test1'
end
end

Are any of you guys familiar with a library that will do something similar to the above?

Thanks,
ER

steve_d555
January 31st, 2006, 10:51 PM
There is a Ruby-Template library, but it has slightly different syntax. The license of the library is GPL so you can modify it to your pleasing. The website is: http://www.aracnet.com/~ptkwt/