Generating List Of Mustache Tags In A Template

Google falls over again looking for:

“generating list of mustache tags in a template”
“regular expression list of mustache tags in a template”
“grep list of mustache tags in a template”
“get list of mustache tags in a template”
“grep expression for mustache tags”

What am I trying to do? I have a Mustache template, and I want to pull out the list of tags I am using in it, because I need to filter a bigger chunk of JSON data to only contain those tags. This JSON data will eventually be used as the context that is then used to .render() the output.

Google needs to reinstate exact-quote indexing, the fuzzy searches of the past few years are making it really hard to find relevant links. (Yes, I probably should have the regex rules memorized, but this can’t be the first time someone’s been looking for this.)

For the record, the command I used to generate this list:

Update 2 March 2013:

The above command was perhaps a bit too simple, it gives the tags in the form of a list of “{{tag}}”.

To get rid of the mustache brackets, you have to run the point through sed.

In Python, the following regex will also give you all the tag names, sans brackets:

Implicit Things

As a learning exercise, I converted a piece of Javascript code i’d written into CoffeeScript.

So what’s wrong with this?

Oh that’s right, initialize doesn’t get called.

It must be “initialize()” when you want to call a function w/no params. But when you do have params, you can leave the parens off. What inconsistent bullshit is this? I guess it’s nice that “initialize” by itself is a statement w/o a side effect. But then when you run it through the compiler (when the hanging return isn’t there), it spits out “return initialize;”, which isn’t what I meant at all and could be a side effect for anyone trying to maintain this down the road. Better to make it explicit that this thing won’t return anything a caller can (ab)use, until and unless I choose to make that the case.

So I’ve been adding hanging returns so the compiled code returns nothing as often as it should.

Sigh, I don’t know that I dig the whole implicit “return whatever was on the last line” thing that so many of these terse scripting languages have. And it strikes me as a weird idea to try and save on parens.

So the CoffeeScript adventure begins, but I’ll be damned if I’m not already building the defensive programming idioms in.

emacs Settings

emacs is incredibly powerful, but configuration can be a royal pain sometime.

Here’s me trying to set the indentation levels when editing HTML. (Because it’s not obvious at all.)

Go to Nxml Child Indent, set that to what you want. In my case, I use 4 spaces per TAB.

These are the settings in my .emacs (you can see that I’m really trying to just set 4 spaces per TAB for all the modes):

Emacs can be annoying in the sheer number of uncorrelated variables it uses for the various modes.

Building An Assets Subdirectory When Using Brunch

Brunch has an opinion about the app/assets/ directory that it generates as part of an app skeleton. It simply copies these files over to the deployment directory, w/o running them through any minification.

But let’s say I want to build a standalone page under the assets/ directory, maybe for a signup form for my website (which I don’t really feel like making into a Backbone View). This form could share the vendor/ minified files, but would not have a need for the app.js or app.css files.

By default, Brunch wouldn’t process those files, as they would be somewhere under, say, app/assets/signup.

Here’s a custom config_signup.coffee file that builds files in the assets/signup/ directory and copies them where I expect. It would be pretty sweet if this could be somehow chained onto the main CoffeeScript file.

Now when I run brunch build -c config_signup.coffee –minify, I can get the same processing on this particular subset of the site.