title: In CoffeeScript, is there an 'official' way to interpolate a string at run-time instead of when compiled?
body: <p>I have an options object in my CS class, and I'd like to keep some templates in it:</p>
  
  <pre><code>class MyClass
      options:
          templates:
              list: "&lt;ul class='#{ foo }'&gt;&lt;/ul&gt;"
              listItem: "&lt;li&gt;#{ foo + bar }&lt;/li&gt;"
              # etc...
  </code></pre>
  
  <p>Then I'd like to interpolate these strings <strong>later</strong> in the code... But of course these are compiled to <code>"&lt;ul class='" + foo +"'&gt;&lt;/ul&gt;"</code>, and foo is undefined.</p>
  
  <p>Is there an official CoffeeScript way to do this at run-time using <code>.replace()</code>?</p>
  
  <hr>
  
  <p>Edit: I ended up writing a little utility to help:</p>
  
  <pre><code># interpolate a string to replace {{ placeholder }} keys with passed object values
  String::interp = (values)-&gt;
      @replace /{{ (\w*) }}/g,
          (ph, key)-&gt;
              values[key] or ''
  </code></pre>
  
  <p>So my options now look like:</p>
  
  <pre><code>templates:
      list: '&lt;ul class="{{ foo }}"&gt;&lt;/ul&gt;'
      listItem: '&lt;li&gt;{{ baz }}&lt;/li&gt;'
  </code></pre>
  
  <p>And then later in the code:</p>
  
  <pre><code>template = @options.templates.listItem.interp
      baz: foo + bar
  myList.append $(template)
  </code></pre>