Skip to content

Commit 2dbd320

Browse files
author
Rafael Mendonça França
committed
Move default implementation to this gem
1 parent 371a6fa commit 2dbd320

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: lib/rails-html-sanitizer.rb

+28
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ module ClassMethods
3434
def sanitizer_vendor
3535
Rails::Html::Sanitizer
3636
end
37+
38+
if method_defined?(:sanitized_allowed_tags=) || private_method_defined?(:sanitized_allowed_tags=)
39+
undef_method(:sanitized_allowed_tags=)
40+
end
41+
42+
# Replaces the allowed tags for the +sanitize+ helper.
43+
#
44+
# class Application < Rails::Application
45+
# config.action_view.sanitized_allowed_tags = 'table', 'tr', 'td'
46+
# end
47+
#
48+
def sanitized_allowed_tags=(tags)
49+
sanitizer_vendor.white_list_sanitizer.allowed_tags = tags
50+
end
51+
52+
if method_defined?(:sanitized_allowed_attributes=) || private_method_defined?(:sanitized_allowed_attributes=)
53+
undef_method(:sanitized_allowed_attributes=)
54+
end
55+
56+
# Replaces the allowed HTML attributes for the +sanitize+ helper.
57+
#
58+
# class Application < Rails::Application
59+
# config.action_view.sanitized_allowed_attributes = ['onclick', 'longdesc']
60+
# end
61+
#
62+
def sanitized_allowed_attributes=(attributes)
63+
sanitizer_vendor.white_list_sanitizer.allowed_attributes = attributes
64+
end
3765
end
3866
end
3967
end

0 commit comments

Comments
 (0)