Skip to content

Combining with client-side templates, syntax compatibility #762

@wnewbery

Description

@wnewbery

Often I have the need to do at least some of the rendering client side. But as well as really liking Slim's syntax, its often useful to still have a server-side pass (e.g. to make use of Rails helpers like image_path/image_tag, route helpers, etc.).

For example Ive been trying out JsRender recently, and so would be nice to be able to have Slim pass through certain things.

a.add href=new_item_path New Item
ul.items
  {{for items}}
    li id={{>id}}
      a [{{if external}}target="_blank"{{/if}}] href={{>url}} {{>title}}
      button.del

But the { confuses Slim and it wont accept that indentation.
{ can already be disabled as an attribute wrapper, but I cant see how to treat lines or attributes starting with { as literal text up to a }, or some sort of plugin interface so I can tell Slim what to do when it encounters a {.

Is there any light-weight client syntax with better compatibility?

Or scope to make it easier to tell Slim to output certain patterns as literal unescaped text in attribute and indentation contexts?

A compromise syntax style for example might be like:

a.add href=new_item_path New Item
ul.items
  / slim doesnt know what this `{` means, so just ignore the indent change
  / (as if it was  `=some_unknown_ruby do`, but no automatic `end` either)
  {{for items}}
    li id=="{{>id}}"
      / just put the evaluation of ~"ruby-string" in the relative position in the <a> tag
      a ~'{{if external}}target="_blank"{{/if}}' href=="{{>url}}" {{>title}}
      button.del
  / slim doesnt know what {{for}} is so cant auto-close it, but also doesnt throw a syntax
  / error for the indent change (and does the `</li>` as normal
  {{/for}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions