Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server-side evaluation #4

Open
jfirebaugh opened this issue Feb 23, 2012 · 4 comments
Open

Add server-side evaluation #4

jfirebaugh opened this issue Feb 23, 2012 · 4 comments

Comments

@jfirebaugh
Copy link
Collaborator

One occasionally wants to use Rails helper methods (especially asset and route helpers) in client-side templates. Existing solutions are ugly.

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. But you get the idea.

@joliss
Copy link

joliss commented Feb 23, 2012

Do you not like chaining .skim.erb? I do this with my .coffee.erb and .scss.erb files all the time, and I find it reasonably intuitive.

img src="<%= image_path('logo.png') %>"

It doesn't support routing helpers out-of-the-box, but you posted this a while ago, right? (I wonder why Rails isn't doing that by default.)

With Erb being an easy solution, I'm not really sure if this problem is worth complicating the language with a notion of a server-side context.

@joliss
Copy link

joliss commented Feb 23, 2012

And I think you can also do

| <%= image_tag 'logo.png' %>

@jfirebaugh
Copy link
Collaborator Author

Ugh, I hate it. If I wanted an ugly syntax I'd be using ejs. :)

@joliss
Copy link

joliss commented Feb 23, 2012

Haha, I know what you mean. :) I can personally live with it since it tends to be just a few lines in a longish file, but if it bothers you ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants