Module: Decidim::SanitizeHelper
- Included in:
- ApplicationMailer, CardGCell, CheckBoxesTreeHelper, DecidimDeviseMailer, Events::BaseEvent, HtmlTruncation, Log::ResourcePresenter, PushNotificationMessage, ResourcePresenter, TraceabilityHelper, ValidationErrorsPresenter, ViewModel
- Defined in:
- app/helpers/decidim/sanitize_helper.rb
Overview
Helper that provides methods to render order selector and links
Class Method Summary collapse
Instance Method Summary collapse
- #decidim_escape_translated(text) ⇒ Object
- #decidim_html_escape(text) ⇒ Object
-
#decidim_sanitize(html, options = {}) ⇒ Object
Public: It sanitizes a user-inputted string with the ‘Decidim::UserInputScrubber` scrubber, so that video embeds work as expected.
- #decidim_sanitize_admin(html, options = {}) ⇒ Object
- #decidim_sanitize_editor(html, options = {}) ⇒ Object
- #decidim_sanitize_editor_admin(html, options = {}) ⇒ Object
- #decidim_sanitize_newsletter(html, options = {}) ⇒ Object
- #decidim_sanitize_translated(text) ⇒ Object
- #decidim_url_escape(text) ⇒ Object
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 6 def self.included(base) base.include ActionView::Helpers::SanitizeHelper base.include ActionView::Helpers::TagHelper base.include Decidim::TranslatableAttributes end |
Instance Method Details
#decidim_escape_translated(text) ⇒ Object
61 62 63 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 61 def decidim_escape_translated(text) decidim_html_escape(translated_attribute(text)) end |
#decidim_html_escape(text) ⇒ Object
49 50 51 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 49 def decidim_html_escape(text) ERB::Util.unwrapped_html_escape(text.to_str) end |
#decidim_sanitize(html, options = {}) ⇒ Object
Public: It sanitizes a user-inputted string with the ‘Decidim::UserInputScrubber` scrubber, so that video embeds work as expected. Uses Rails’ ‘sanitize` internally.
html - A string representing user-inputted HTML.
Returns an HTML-safe String.
19 20 21 22 23 24 25 26 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 19 def decidim_sanitize(html, = {}) scrubber = [:scrubber] || Decidim::UserInputScrubber.new if [:strip_tags] sanitize(html, scrubber:) else sanitize(html, scrubber:) end end |
#decidim_sanitize_admin(html, options = {}) ⇒ Object
28 29 30 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 28 def decidim_sanitize_admin(html, = {}) decidim_sanitize(html, { scrubber: Decidim::AdminInputScrubber.new }.merge()) end |
#decidim_sanitize_editor(html, options = {}) ⇒ Object
40 41 42 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 40 def decidim_sanitize_editor(html, = {}) content_tag(:div, decidim_sanitize(html, ), class: %w(rich-text-display)) end |
#decidim_sanitize_editor_admin(html, options = {}) ⇒ Object
44 45 46 47 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 44 def decidim_sanitize_editor_admin(html, = {}) html = Decidim::IframeDisabler.new(html, ).perform decidim_sanitize_editor(html, { scrubber: Decidim::AdminInputScrubber.new }.merge()) end |
#decidim_sanitize_newsletter(html, options = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 32 def (html, = {}) if [:strip_tags] sanitize(html, scrubber: Decidim::NewsletterScrubber.new) else sanitize(html, scrubber: Decidim::NewsletterScrubber.new) end end |
#decidim_sanitize_translated(text) ⇒ Object
57 58 59 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 57 def decidim_sanitize_translated(text) decidim_sanitize(translated_attribute(text)) end |
#decidim_url_escape(text) ⇒ Object
53 54 55 |
# File 'app/helpers/decidim/sanitize_helper.rb', line 53 def decidim_url_escape(text) decidim_html_escape(text).sub(/^javascript:/, "") end |