Skip to content

Splat operator (conditional attributes) support? #29

@wulftone

Description

@wulftone

EDIT: Discovered the Splat operator, re-writing...

I'm trying to set up a conditional attribute... for example, I want the result to be one of the two following:

<a>Lotsa content</a>

or

<a href="some/link">Lotsa content</a>

The condition would be whether or not the href exists. So the skim pseudo-code would be something like this:

a *( if @url then { href: @url } else {} )
  Lotsa content

I know that doesn't work, obviously, but I can't find any way to do this in skim. Slim supports it via their splat operator. The "correct" coffeescript version would be like the example just above. In ruby/slim it's a *( @url ? { href: @url } : {} )

I'd rather not do this:

- if @url
  a href='#{@url}'
    Lotsa content
- else
  a
    Lotsa content

Because "Lotsa content" is a ton of code duplication. I also don't want the href in the a tag, because clicking on an empty href causes the page to reload. I could make the link do nothing when clicked on if there's no href, but it would be much easier just to omit the href and let that behavior happen naturally.

Would it be possible to implement the splat operator?

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