On Monday, 11 February 2013 at 21:41:33 UTC, Jacob Carlborg wrote:
On 2013-02-11 22:07, FG wrote:

The problem I have with those is that they are designed for HTML.
What if I wanted to make an email template instead?

Erb is like a Ruby preprocessor that can be used for any format. It's used for many things in Ruby on Rails:

index.html.erb - Erb preprocessor, result is HTML

<% if foo %>
  <li>asd</li>
<% end %>

bar.js.coffee.erb - Erb then CoffeeScript preprocessor, result is JavaScript

<% if foo %>
  bar = -> console.log("asd")
<% end %>

foo.text.erb - Erb preprocessor, result is plain text

<% if foo %>
  asd
<% end %>

database.yml.erb - Erb preprocessor, result is YAML

development:
  username: <%= username %>
  password: <%= password %>

This really makes sense for D. It can be easily combined with D's mixin capabilities to make it so you don't even need to implement stuff like various loops:

<%  [d code] %>   ->   [d code]
<%= [d expr] %>   ->   buffer.write([d expr]);
    [text]        ->   buffer.write("[text]");

NMS

Reply via email to