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

Version Path
roda-3.86.0 lib/roda/plugins/erb_h.rb
roda-3.85.0 lib/roda/plugins/erb_h.rb
roda-3.84.0 lib/roda/plugins/erb_h.rb
roda-3.83.0 lib/roda/plugins/erb_h.rb
roda-3.82.0 lib/roda/plugins/erb_h.rb
roda-3.81.0 lib/roda/plugins/erb_h.rb
roda-3.79.0 lib/roda/plugins/erb_h.rb
roda-3.78.0 lib/roda/plugins/erb_h.rb
roda-3.77.0 lib/roda/plugins/erb_h.rb
roda-3.76.0 lib/roda/plugins/erb_h.rb
roda-3.75.0 lib/roda/plugins/erb_h.rb
roda-3.74.0 lib/roda/plugins/erb_h.rb
roda-3.73.0 lib/roda/plugins/erb_h.rb
roda-3.72.0 lib/roda/plugins/erb_h.rb
roda-3.71.0 lib/roda/plugins/erb_h.rb
roda-3.70.0 lib/roda/plugins/erb_h.rb
roda-3.69.0 lib/roda/plugins/erb_h.rb
roda-3.68.0 lib/roda/plugins/erb_h.rb
roda-3.67.0 lib/roda/plugins/erb_h.rb
roda-3.66.0 lib/roda/plugins/erb_h.rb