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

Lambda shortcuts #903

Merged
merged 4 commits into from
Mar 16, 2023
Merged

Lambda shortcuts #903

merged 4 commits into from
Mar 16, 2023

Conversation

Spone
Copy link
Contributor

@Spone Spone commented Jan 23, 2023

This allows passing a lambda as attr param when defining a shortcut.

Slim::Parser.options[:shortcut].update({
  '~' => { attr: ->(v) { ["class", "\"styled-#{v}\""] } }
})

Then in your slim template you can do:

h1~title Hello
~text~question How are you?

which renders to:

<h1 class="styled-title">Hello</h1>
<div class="styled-text styled-question">How are you?</div>

Related discussions

lib/slim/parser.rb Outdated Show resolved Hide resolved
@Spone Spone marked this pull request as ready for review February 6, 2023 20:47
@Spone
Copy link
Contributor Author

Spone commented Feb 6, 2023

@minad I addressed your comments.

Please let me know if you think more tests should be added.

@Spone Spone requested a review from minad February 23, 2023 22:14
@minad minad merged commit 32ea93d into slim-template:main Mar 16, 2023
@Spone Spone deleted the shortcut-attr-value branch March 16, 2023 19:24
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

Successfully merging this pull request may close these issues.

None yet

2 participants