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

Feature: dynamic CSS classes with Hash #813

Closed
Spone opened this issue Jul 14, 2018 · 6 comments
Closed

Feature: dynamic CSS classes with Hash #813

Spone opened this issue Jul 14, 2018 · 6 comments

Comments

@Spone
Copy link
Contributor

Spone commented Jul 14, 2018

Hello,

I'd like to suggest a new feature. The idea would be to allow generating CSS classes dynamically based on a Hash:

div(class={one: true, two: false, three: true})

would render:

<div class="one three"></div>

I currently use this gem for that: https://github.com/komposable/klassnames but it would be great to have this feature included in Slim!

Let me know what you think.

@Spone Spone changed the title Feature: dynamic CSS classes Feature: dynamic CSS classes with Hash Jul 14, 2018
@minad
Copy link
Member

minad commented Jan 23, 2023

I don't think it is a good idea to complicate the Slim syntax for this feature, given that you can simply use a function like the classnames function from the gem you mentioned.

@minad minad closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2023
@Spone
Copy link
Contributor Author

Spone commented Jan 23, 2023

Thanks for taking the time to reply.

Since then, I've considered another approach: Spone#1
If you have a couple minutes to let me know if you would be open to a PR for this, I'd very much appreciate it!

@minad
Copy link
Member

minad commented Jan 23, 2023

This sounds like a useful generalization. My suggestion would be to make :attr a function instead which returns a pair of an attribute name and an attribute value. I would be happy to accept a PR which adds this. But it is also necessary that you update the documentation accordingly and add test cases.

@Spone
Copy link
Contributor Author

Spone commented Jan 23, 2023

Thank you! I'll try to get back to it!

@Spone
Copy link
Contributor Author

Spone commented Jan 23, 2023

My suggestion would be to make :attr a function instead which returns a pair of an attribute name and an attribute value.

Just to clarify, do you mean having:

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

instead of:

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

@minad
Copy link
Member

minad commented Jan 23, 2023

Just to clarify, do you mean having:

Yes. This generalizes attr instead of adding a new option attr_value.

@Spone Spone mentioned this issue Jan 23, 2023
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