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

Expose styles method #811

Closed

Conversation

stephannv
Copy link
Contributor

@stephannv stephannv commented Oct 10, 2024

What do you think about exposing styles method? I was building some style for my form builder (generating HTML via Rails), and I could not use style: { color: "white" } because it isn't processed by Phlex.

def view_template
  form_with(...) do |form|
    form.submit style: { background_color: "white", color: "red" }
    # => <input ... style="background_color white color red">
  end
end

So I thought using the same method Phlex uses but I noticed the __styles__ method is "internal" and generates unsafe code. I think it would be nice to expose it to users. I'm not sure about the method name, and I think we need at least one test to ensure this method is exposed.

With this change, we can do something like:

form.submit style: styles({ background_color: "white", color: "red" })
# => <input ... style="background_color: white; color: red">

@joeldrapper
Copy link
Collaborator

The method generates unsafe code because it’s escaped later. In theory, Rails should be escaping too. I’m not against making this part of our public API as long as it doesn’t introduce any security issues.

I recommend you add an alias_method :styles, :__styles__ and get a feel for it for a few days and report back.

@stephannv
Copy link
Contributor Author

It makes sense @joeldrapper. I will close this PR for now.

@stephannv stephannv closed this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants