[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: The Ruby/ERB way to do this?

Peter Booth

7/27/2006 4:37:00 PM

Thanks for taking the time to reply. Using a variable of require is a good
idea.

Referencing variables as X::Size seems verbose. Is there any way for require
to define a set of local scoped variables so the ERB template could drop the
X:: prefix?

-----Original Message-----
From: Jeff Barczewski [mailto:jeff.barczewski@gmail.com]
Sent: Thursday, July 27, 2006 12:29 PM
To: ruby-talk@ruby-lang.org
Subject: Re: The Ruby/ERB way to do this?

Not sure if I totally understand your question, but I'll try to help.

Note that if you want to, you can make your require use a variable so that
you can vary which file to require in.

Also note that you can do your require and include in the module that calls
erb since you can pass in a binding. The binding gives erb access to
everything that was available where ever the binding was created. So you
don't have to put the require and inlude in the erb template.

On 7/27/06, Peter Booth <pbooth@marketaxess.com> wrote:
>
> Hello, I was wondering if someone could point me to a smarter way of doing
> the following? It's probably a Ruby basics question.
>
> I am using ERB to generate sets of configuration files for different
> environments. I imagined that I would use a different config file per
> environment, that sets variables, and apply this against a list of
> configuration file templates.
>
> Currently each environment file defines a module "X" that has constants
> for
> each variable:
> module X
> MgrPort = '3000'
> MsgPort2s = '4000'
>
> The template files reference the variables like so
> domain = <%= X::Domain %>
>
> The script that calls erb.result() uses require/include to reference the
> config file
>
> require "Configs/stagingProperties"
> include X
>
>
> There must be a better way to do this. Is there a "Right Way" here? I've
> perused the erb docs and the Pickaxe book but neither explicitly join the
> dots.
>
>
----------------------------------------------------------------------------
> ----------------------------------------
>
> The information contained in and accompanying this communication is
> strictly
> confidential and intended solely for the use of the intended recipient(s).
> If you have received it by mistake please let us know by reply and then
> delete it from your system; you should not copy the message or disclose
> its
> content to anyone.
> MarketAxess reserves the right to monitor the content of emails sent to or
> from its systems.
> Any comments or statements made are not necessarily those of MarketAxess.
> For more information, please visit www.marketaxess.com. MarketAxess Europe
> Limited is regulated in the UK by the FSA, registered in England no.
> 4017610, registered office at 71 Fenchurch Street, London, EC3M 4BS.
> Telephone (020) 7709 3100.
> MarketAxess Corporation is regulated in the USA by the SEC and the NASD,
> incorporated in Delaware, executive offices at 140 Broadway, New York, NY
> 10005. Telephone (1) 212 813 6000.
>
>
>
----------------------------------------------------------------------------
----------------------------------------

The information contained in and accompanying this communication is strictly
confidential and intended solely for the use of the intended recipient(s).
If you have received it by mistake please let us know by reply and then
delete it from your system; you should not copy the message or disclose its
content to anyone.
MarketAxess reserves the right to monitor the content of emails sent to or
from its systems.
Any comments or statements made are not necessarily those of MarketAxess.
For more information, please visit www.marketaxess.com. MarketAxess Europe
Limited is regulated in the UK by the FSA, registered in England no.
4017610, registered office at 71 Fenchurch Street, London, EC3M 4BS.
Telephone (020) 7709 3100.
MarketAxess Corporation is regulated in the USA by the SEC and the NASD,
incorporated in Delaware, executive offices at 140 Broadway, New York, NY
10005. Telephone (1) 212 813 6000.