# Writing my own generator

**URL:** <https://www.ruby-forum.com/t/writing-my-own-generator/100648>\
**Category:** Rails\
**Created:** [February 3, 2006, 3:45pm UTC](https://www.ruby-forum.com/t/writing-my-own-generator/100648 "2006-02-03T15:45:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [February 3, 2006, 3:45pm UTC](https://www.ruby-forum.com/t/writing-my-own-generator/100648/1 "2006-02-03T15:45:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [February 3, 2006, 5:28pm UTC](https://www.ruby-forum.com/t/writing-my-own-generator/100648/2 "2006-02-03T17:28:07Z")

</div>

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/](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

> **[Tree Removal Service For Home & Businesses in Salt Lake City, UT](https://www.rentamonkey.com/)**
>
> Rent A Monkey Tree Service provides the safest, highest-quality tree removal for Salt Lake City, UT homes and businesses. Request a service today!

PGP Key: [http://www.rentamonkey.com/pgpkey.asc](http://www.rentamonkey.com/pgpkey.asc)

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [February 3, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/writing-my-own-generator/100648/3 "2006-02-03T18:01:15Z")

</div>

On 2/3/06, Dave S. [removed\_email\_address@domain.invalid](mailto: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](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](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [February 3, 2006, 7:49pm UTC](https://www.ruby-forum.com/t/writing-my-own-generator/100648/4 "2006-02-03T19:49:58Z")

</div>

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

> **[Tree Removal Service For Home & Businesses in Salt Lake City, UT](https://www.rentamonkey.com/)**
>
> Rent A Monkey Tree Service provides the safest, highest-quality tree removal for Salt Lake City, UT homes and businesses. Request a service today!

PGP Key: [http://www.rentamonkey.com/pgpkey.asc](http://www.rentamonkey.com/pgpkey.asc)

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [February 3, 2006, 7:07pm UTC](https://www.ruby-forum.com/t/writing-my-own-generator/100648/5 "2006-02-03T19:07:47Z")

</div>

On 2/3/06, Dave S. [removed\_email\_address@domain.invalid](mailto: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](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 \*  
~

---

<div class="post-metadata">

**Author:** ![Harm\_de\_Laat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/9de053/32.png) [@Harm\_de\_Laat](https://www.ruby-forum.com/u/Harm_de_Laat)\
**Post date:** [February 4, 2006, 9:33am UTC](https://www.ruby-forum.com/t/writing-my-own-generator/100648/6 "2006-02-04T09:33:34Z")

</div>

Great! Thanks! I’ll look into this!

Regards,

Harm de Laat
