Yesterday I was writing this code over and over and over:
%li
= f.label :first_name, "What is your first name, good sir"
= f.text_area :first_name
The process I needed to do was:
- Add a field to the database
- Write those three lines of code that referenced the field I created.
I had about 40 fields to create. Half way through my task I realized I could use a Jig.
A jig in woodworking is a custom tool created to control the location of another tool.
In our case it’s a temporary tool created by us, used by our text editor to automate a task. But I write this jig with the intention that I’ll throw it away and never use it again.
After I came to terms with creating something, using it 20 times then throwing it away, I wrote the following BBEdit clipping.
%li
= f.label :#CLIPBOARD#, "<##>"
= f.text_area :#CLIPBOARD#
My process for using this jig was:
- Create the field in the database, and copy the new field name to the clipboard.
- Run the jig. My database field name is now populated
- Start typing the desired custom label
My initial problem creating this jig was that I needed the same value two places. Clippings don’t let you mirror one value to another place, so I thought I was stuck, until I realized that I could use the clipboard here.
Sometimes automation happens at a strategic level: “I know I do this a lot, and I know I’m going to do this a lot in the future, so let me let my editor help me”. Sometimes automation happens at a tactical level: “I need to do this 40 times, but then I’ll never do this again”. Both are equally valid!
I put this clipping in its own folder (“Jigs”) and gave it a keyboard shortcut (F10). The next time I need to create a jig I’m going to put it in that same folder and reuse the keyboard shortcut.