From: Gene Tani Date: 2005-09-11T00:26:31+09:00 Subject: Re: Using Ruby as a preprocessor for another language Looks like your template's distilled your business logic pretty well, but maybe you can locate a copy of Herrington's book on eRB for code generation. i've seen it at Borders in the past (doesn't talk about avoiding the '<%' '%>' and '<%' '=%>', except to say that you can use '<%%' etc for ASP, JSP.) Actually, i find that if those tags aren't set off by themselves and surrounded by blank lines, they're hard to pick out of HTML templates. http://www.manning.com/books/herrington debbie@theanimaro.com wrote: > I have the misfortune of being stuck programming in a very bad > scripting language that has poor support for functions, variable > substitutions, loops, etc. etc. (It's a proprietary language called > Aegis scripting language, for scripting NPCs in a game.) > > I've been using Ruby as a macro pre-processor so that I can write more > maintainable scripts without violating the DRY (Don't Repeat Yourself) > principle. Presently, I have the following functionality: > > 1. #{...} strings are evaluated by Ruby > 2. lines starting with @ are evaluated by Ruby > > Thanks to Ruby's power and simplicity, the ENTIRE pre-processor is > just these few lines: > > while line = gets > line.chomp! > if line =~ /^\s*\@(.*)$/ > # Line starts with a @; it is Ruby code > puts $1 > else > # Line should be printed, with #{} substitution > available > puts "puts \"#{line.gsub('"', '\"')}\"" > end > end > > This allows me to "compile" a template like this: > > http://theanimaro.com/debbie/ruby/template.sc > > into a script like this: > > http://theanimaro.com/debbie/ruby/test.sc > > Now my question is, am I reinventing the wheel here in that > pre-processor code I wrote---is there already an existing module in > the RAA that does this? I didn't want to use ERuby because I find that > those <% %> <%= %> tags everywhere make the script unreadable (ERuby > is more for HTML IMO).