Skip to content

Sanitizer#20

Open
bluesnotred wants to merge 4 commits intobithavoc:masterfrom
bluesnotred:sanitizer
Open

Sanitizer#20
bluesnotred wants to merge 4 commits intobithavoc:masterfrom
bluesnotred:sanitizer

Conversation

@bluesnotred
Copy link
Copy Markdown

I needed to sanitize my strings for each locale, which was difficult to implement at the model level.

That’s why I introduced an option called :sanitizer at the multilang attribute level. It accepts a custom sanitizer method, which is being called for all locales of a certain attribute.

Example sanitizer methods:

def self.squish(value)
  value.squish!
end
def self.sanitize_html(value)
  value.gsub!(/<\/?[^>]*>/, '')
end

Setting the sanitizer options:

multilang :title, sanitizer: method(:squish)
multilang :body,  sanitizer: method(:sanitize_html)

The sanitizer method is both called on read and write to make sure unsanitized content (which could be already stored in db before activating the sanitizer option) is always displayed as sanitized content.

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.

1 participant