VYD-19575: Add custom plugin functionality and create sanitize plugin - #28
Conversation
| # set_default_attribute_options at the gem level or consumer level. | ||
| value.strip! if options.fetch(:strip, true) | ||
| value.upcase! if options.fetch(:upcase, false) | ||
| value = Loofah.html4_fragment(value).scrub!(:prune).to_s if options.fetch(:sanitize, false) |
There was a problem hiding this comment.
should we sanitize by default?
There was a problem hiding this comment.
should we sanitize before we strip? if the input string is "<b>a</b> <script>x</script> " then after we sanitize we'd end up with "<b>a</b> " with a surviving trailing space.
There was a problem hiding this comment.
nice catch, fixed
TSMMark
left a comment
There was a problem hiding this comment.
LGTM But greg had some good feedback.
also we might consider making the coercers extensible so a user of this gem could add similar logic like this for their own project, without us having to add things like loofah as a gem dependency and add it to the base gem
TSMMark
left a comment
There was a problem hiding this comment.
magnifique! incroyable!
| value = send(:"coerce_#{type}", value, options) if type | ||
|
|
||
| if type | ||
| raise ":coerce_#{type} does not exist. Did you forget to add a plugin for :coerce_#{type}?" unless respond_to?(:"coerce_#{type}") |
| # @param name [Symbol, Module] a name to look up under Gourami::Plugins | ||
| # (e.g. :sanitize loads gourami/plugins/sanitize and resolves | ||
| # Gourami::Plugins::Sanitize), or a Module to apply directly. | ||
| def self.plugin(name, *args, &block) |
There was a problem hiding this comment.
maybe we should leave a comment linking to the blog post about this @jeremyevans pattern
| coercer.setter_filter(:name, "foo", :type => :whatever) | ||
| end | ||
|
|
||
| assert_equal(":coerce_whatever does not exist. Did you forget to add a plugin for :coerce_whatever?", error.message) |
|
|
||
| describe Gourami::Form do | ||
| describe ".plugin" do | ||
| it "mixes in ClassMethods, InstanceMethods, and calls apply then configure" do |
Created a
Sanitizeplugin that can sanitize stringsUse:
Also added custom plugin functionality. User's can now create their own plugin and use it in
FormUse: