Writing my own generator


#1

Hi all,

I wanted to write my own generator. What would be a good starting point.
Is there any documentation on this, Best practices, etc?

Regards,

Harm de Laat


#2

On Friday 03 Feb 2006 14:45, Harm de Laat wrote:

I wanted to write my own generator. What would be a good starting point.
Is there any documentation on this, Best practices, etc?

I am also very interested in this.

I have common stuff that I often do on sites - news archives, portfolios
of
work, fairly standard contact pages and a standard-ish form mailer in
the
background and so on. Have been considering that it might be very
useful for
me to have a few custom generators set up, to avoid having to rebuild
pretty
similar systems on various sites, when essentially I’d like to be able
to
go…

ruby script/generate newsarchive News

… or …

ruby script/generate contactform Contact

…and then just tweak it a tiny bit for each site’s individual needs.

Perhaps there is a better way of doing this anyway? I’m not sure!

I guess I’ll take a look at something relatively simple like the
original
login generator and see how that was done.

And yes, I have read…

http://weblog.rubyonrails.org/articles/2005/11/11/

… but what I’m suggesting isn’t something to be distributed
necessarily,
just something I want to use for my own needs here, to avoid me
“repeating
myself” (albeit from one project to the next, and where code-sharing
between
those projects isn’t necessarily desirable or a possibility).

Does that make sense?

~Dave

Dave S.
Rent-A-Monkey Website Development
http://www.rentamonkey.com/

PGP Key: http://www.rentamonkey.com/pgpkey.asc


#3

On 2/3/06, Dave S. removed_email_address@domain.invalid wrote:

On Friday 03 Feb 2006 14:45, Harm de Laat wrote:

I wanted to write my own generator. What would be a good starting point.
Is there any documentation on this, Best practices, etc?

My acts_as_authenticated plugin would be a good place to start:

http://techno-weenie.net/svn/projects/plugins/acts_as_authenticated

You can generate a new plugin with the generator stubs all setup too.

./script/generate plugin my_plugin_generator_thing --with-generator

Two gotchas I’ve run into:

  • It’s ERB, so you use <%= foo %> to spit out variables. However, if
    you’re generating a view that needs ERB, you have to use <%%= %> to
    keep it from being evaluated at generation time.

  • You can’t symlink a generator plugin into multiple apps. The
    generate script won’t find it. It’d be best to keep it in SVN
    somewhere and use svn:externals in each app.


Rick O.
http://techno-weenie.net


#4

On Friday 03 Feb 2006 18:06, James A. wrote:

The engines plugin is primarily designed to help you do exactly this.

It’s simply a plugin which adds a bit of flexibility to Rails in an attempt
to avoid some of the pain of using generators in a multi-project
environment.

Ahhh!! Now that’s EXACTLY what I was looking for - perfect, thanks!!

~Dave

Dave S.
Rent-A-Monkey Website Development
http://www.rentamonkey.com/

PGP Key: http://www.rentamonkey.com/pgpkey.asc


#5

On 2/3/06, Dave S. removed_email_address@domain.invalid wrote:

similar systems on various sites, when essentially I’d like to be able to
go…

The engines plugin is primarily designed to help you do exactly this.
For various reasons
(http://rails-engines.org/wiki/pages/Engines+vs.+Generators), we’ve
found generators to work against us with regards to long-term
maintainability. Don’t be put off developing your common features as a
set of engines for you and noone else to use. That’s exactly what
we’re using it for in my team, and exactly the problem it was
concieved to solve.

I’m sure when people hear “engines” they think that they’re going to
have to buy in 100% to a monolithic set of mandated, high-level
components. That couldn’t be farther from the truth. It’s simply a
plugin which adds a bit of flexibility to Rails in an attempt to avoid
some of the pain of using generators in a multi-project environment.

Best of luck whatever you decide though…

  • J *
    ~

#6

Great! Thanks! I’ll look into this!

Regards,

Harm de Laat