# How do I write a generator?

**URL:** <https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889>\
**Category:** Rails\
**Created:** [January 6, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889 "2006-01-06T22:49:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 6, 2006, 10:49pm UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/1 "2006-01-06T22:49:11Z")

</div>

I’d like to take some advice and write a generator to change the  
scaffold.css. How do I do that? I looked on the wiki and googled it  
but have not found anything yet.

Any help would be much appreciated.

bruce

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 6, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/2 "2006-01-06T23:10:15Z")

</div>

On Jan 6, 2006, at 1:45 PM, Bruce B. wrote:

> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Bruce-

```
There isn't a whole lot of documentation on how to write a generator

```

that I have seen. You are better off dissecting one yourself. Here is  
a very simple one for you to play with that I wrote. Its just a  
lighttpd.conf file generator for either scgi or fcgi configuration  
generation. But it ought to show you how to build a basic generator  
so you can look at some more complex oones and see whats going on.

Cheers-

-Ezra Z.  
Yakima Herald-Republic  
WebMaster  
[http://yakimaherald.com](http://yakimaherald.com)  
509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 6, 2006, 11:22pm UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/3 "2006-01-06T23:22:41Z")

</div>

bruce balmer wrote:

> I’d like to take some advice and write a generator to change the  
> scaffold.css. How do I do that? I looked on the wiki and googled it  
> but have not found anything yet.
> 
> Any help would be much appreciated.
> 
> bruce

I would just reverse engineer the standard scaffold generator, there are  
probably big chunks of text in it that you can just replace.

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 6, 2006, 11:28pm UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/4 "2006-01-06T23:28:18Z")

</div>

On Jan 6, 2006, at 2:03 PM, Ezra Z. wrote:

> > * * *
> 
> wrote. Its just a lighttpd.conf file generator for either scgi or  
> fcgi configuration generation. But it ought to show you how to  
> build a basic generator so you can look at some more complex oones  
> and see whats going on.

Sorry forgot to paste the link:

[http://brainspl.at/files/lighttpd.tar.gz](http://brainspl.at/files/lighttpd.tar.gz)

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster  
[http://yakimaherald.com](http://yakimaherald.com)  
509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 7, 2006, 12:01am UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/5 "2006-01-07T00:01:20Z")

</div>

Ezra:

thanks for sending that. I took a quick look at it. I would love to  
find some good documentation. I think that what may be obvious to you  
is not YET obvious to me. Maybe I could start with altering the  
template the generator uses and keep a copy somewhere so that I can  
put it back each time I upgrade rails.

Where could I find that file. Two people have given me answers on its  
location but I can find nothing similar to the paths they give me. I  
am on OS X using Locomotive. (which I love, by the way)

bruce

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 6, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/6 "2006-01-06T23:58:20Z")

</div>

Kevin:

thanks, Happy to do that if I could ever find out where it is so I  
could look at the file. Also, I am using Locomotive. Not sure if  
that complicates things re finding these files. Do you know where  
the file lives? I tried which rails\_generator and got nothing back.

tia.

bruce

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 7, 2006, 2:10am UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/7 "2006-01-07T02:10:48Z")

</div>

Bruce-

```
I am attaching a copy of the scaffolding generator in its entirety

```

from rails1.0 on osx. You can edit a copy to keep even through rails  
version upgrades by putting in a dir called ~/.rails/generators/  
myscaffold . So you can take the one I am sending you and edit the  
templates and css however you like and then run script/generate  
myscaffold Foo B. just like a normal scaffold to get your  
personalized version instead.

```
When you use locomotive it has its own self contained gems and so if

```

you want to find the rails generators in the locomotive bundle you  
will need to open your terminal shell from inside of locomotive  
becasue it changes you $PATH in order to keep itself contained. I  
don’t know offhand what the path to the generators are in locomotive.

Hope that gets you going.

Cheers-  
-Ezra

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 7, 2006, 1:04am UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/8 "2006-01-07T01:04:41Z")

</div>

[http://wiki.rubyonrails.com/rails/pages/UnderstandingGenerators](http://wiki.rubyonrails.com/rails/pages/UnderstandingGenerators)

I used that page as a reference when writing my OpenIDLoginGenerator.

Hope that helps,  
Brian E.  
[http://openidenabled.com/openid/libraries/ruby](http://openidenabled.com/openid/libraries/ruby)

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [January 7, 2006, 6:59am UTC](https://www.ruby-forum.com/t/how-do-i-write-a-generator/59889/9 "2006-01-07T06:59:20Z")

</div>

Ezra:

Thanks, very much.

bruce
