Sha256: 3cf101ba2b2d6c48eed29092aa2e24355f48c7c37fd1ec7cef4f87061451dbc9
Contents?: true
Size: 1.25 KB
Versions: 22
Compression:
Stored size: 1.25 KB
Contents
# frozen-string-literal: true require 'erb/escape' # class Roda module RodaPlugins # The erb_h plugin adds an +h+ instance method that will HTML # escape the input and return it. This is similar to the h # plugin, but it uses erb/escape to implement the HTML escaping, # which offers faster performance. # # To make sure that this speeds up applications using the h # plugin, this depends on the h plugin, and overrides the # h method. # # The following example will return "<foo>" as the body. # # plugin :erb_h # # route do |r| # h('<foo>') # end # # The faster performance offered by the erb_h plugin is due # to erb/escape avoiding allocations if not needed (returning the # input object if no escaping is needed). That behavior change # can cause problems if you mutate the result of the h method # (which can mutate the input), or mutate the input of the h # method after calling it (which can mutate the result). module ErbH def self.load_dependencies(app) app.plugin :h end module InstanceMethods define_method(:h, ERB::Escape.instance_method(:html_escape)) end end register_plugin(:erb_h, ErbH) end end
Version data entries
22 entries across 22 versions & 1 rubygems