-
Notifications
You must be signed in to change notification settings - Fork 145
Description
I have a commenting system. I have implemented a transformer that turns mentions like @JasonBarnabe to links, much like GitHub does: @JasonBarnabe.
As it may be expensive to scan through text looking for valid mentions like this, I precalculate data on the mentions in the text (e.g. what text it is and where it should link to) when the comment is posted and save this data. At render time, my text going through sanitize, including a transformer to turn these mentions into hyperlinks.
There does not seem to be a built-in way to give my transformer access to this precalculated mention data. What I'm doing right now is creating a closure around the transformer and the mention data and giving that to my sanitize config. This has the drawback of requiring me to recreate my sanitize config at every call, lest the wrong mention data be included.
https://github.com/greasyfork-org/greasyfork/blob/b67a36456cf7b5f12f5ad082e72a04cbcec469e6/app/helpers/user_text_helper.rb#L34-L35
https://github.com/greasyfork-org/greasyfork/blob/b67a36456cf7b5f12f5ad082e72a04cbcec469e6/app/helpers/user_text_helper.rb#L107-L127
What would be better is if, when calling Sanitize.clean, I could pass in an additional option that would provide data to all transformers.