jfirebaugh/skim — Issue #4: Add server-side evaluation
Author: jfirebaugh
Created: 2012-02-23 04:09:10+00:00
State: open

One occasionally wants to use Rails helper methods (especially asset and route helpers) in client-side templates. [Existing solutions are ugly.](http://stackoverflow.com/questions/8316814/rails-with-backbone-rails-asset-helpers-image-path-in-ejs-files)

The fact that Skim is implemented in Ruby and compiles server-side affords a unique solution: server-side evaluation within the language. I'm thinking of adding two new sigils: `~` and `≈`, server-side analogs of `-` and `=`. (Think of `~` as a sideways S, for Server.) Within these sigils, you write Ruby instead of CoffeeScript. You are responsible for keeping your template logic simple enough that writing in two different embedded languages doesn't become confusing.

Example:

```
a href≈my_path
≈ image_tag "logo.png"
```

`my_path` and `image_tag` would be evaluated at compile time, generating the equivalent of:

```
a href="/my/path"
img src="/assets/logo.png"
```

Maybe ≈ isn't the best choice, as it's hard to type and forces the [encoding issue](https://github.com/rtomayko/tilt/issues/75). But you get the idea.