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
Decouple ActionView and Rails HTML Sanitizer to Allow Other Frameworks to Use ActionView #49643
Conversation
1630bbf
to
ee2d79c
Compare
* allow actionview to be use outside of rails
ee2d79c
to
b375de8
Compare
This change breaks a lot of tests, so I think we cannot change it so easily. |
I'm confused. How does this couple Action View to Rails? Rails is just an empty namespace. Isn't the full framework. |
There is no reason to frameworks like Jets to not be able to use Action View as is. For sure this change doesn't make anything easier. The If that is not the case let us know, but I don't think there is a need to implement this in order to Jets to use Action View. |
All good if it's not merge, I understand. Working around it anyway. |
I'm really curious where is the coupling, because it should not have any without this PR. Can you please explain what do you need to workaround? The Are you trying to use action view without the sanitizer? Because it is possible to use without Rails already and the sanitizer require doesn't load anything related to Rails. |
I found rubyonjets/jets@faa5ce1. Can you explain what is the problem with the |
Is the problem that there are code that does |
Wow. You figured it out before I was able to explain it. 🎉 Yup, that's it. Found that once the some_gem/railtie.rb require "some_gem/railtie" if defined?(Rails) Once ActionView is loaded: Boom! The Rails constant is defined because the To allow Jets to use other gems, Jets makes sure that the Rails constant is not defined. There's even a spec for it. I could had explained it better initially. The workaround: Jets intercepts Again, no sweat either way 👌 |
lol, not judging. I have seeing gems doing this but the right way that I found to solve this problem was to change those gems to check for the right thing:
Now, I totally get isn't easy to do this. I think we can rename the I'll do it for next release. But like I said, there are a few other gems that define that same module: https://github.com/rails/rails-controller-testing/blob/master/lib/rails/controller/testing.rb#L6 Not sure if it will be feasible to really avoid the But of course, having action view already defining it is something we can fix by rename the gem. |
That would be amazing! Would be able to get rid of the Kernel require hack 🙌 Here are related PRs for consideration to help with the rename: For the curious, here's a comment I forgot about from a while back rubyonjets/jets#251 (comment) Lol. Totally get that there will be issues with gems still. It just gives Jets a chance to work with more of them. 👍 |
Motivation / Background
This Pull Request has been created because it decouples ActionView and Rails::HTML::Sanitizer. This allows other frameworks like Jets to use ActionView for rendering.
Detail
This Pull Request changes the actionview
sanitize_helper.rb
to removerails/actionview/lib/action_view/helpers/sanitize_helper.rb
Line 3 in 53438e9
rails/actionview/lib/action_view/helpers/sanitize_helper.rb
Line 12 in 53438e9
I've found that these are only spot in actionview that refers to
Rails
.Instead, this PR sets the default
config.action_view.sanitizer_vendor
is set in the actionview railtie. This decouples actionview from Rails. It makes ActionView easier to use with other frameworks.Thanks for considering this PR.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]