Sha256: 3ca65d15a1b703d62d577fcc6a3044decf2726c541680abaf0dc873bf1a3fc61

Contents?: true

Size: 958 Bytes

Versions: 3

Compression:

Stored size: 958 Bytes

Contents

module Immunio
  # Hook for `ActionController::Caching::Fragments` responsible for
  # handling the `<% cache do %>...` in templates.
  module FragmentCachingHooks
    extend ActiveSupport::Concern

    included do
      Immunio::Utils.alias_method_chain self, :write_fragment, :immunio
    end

    def write_fragment_with_immunio(key, content, options = nil)
      return content unless cache_configured?

      template = Template.current
      if template
        # We're rendering a template.
        # Defer caching 'till we get the escaped content from the hook handler.
        content = Template.mark_and_defer_fragment_write(key, content, options)
      else
        # Not rendering a template. Ignore.
        # Shouldn't happen. But, just to be safe in case fragment caching
        # is used in the controller for something else.
        content = write_fragment_without_immunio(key, content, options)
      end

      content
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
immunio-2.0.4 lib/immunio/plugins/action_view/fragment_caching.rb
immunio-2.0.3 lib/immunio/plugins/action_view/fragment_caching.rb
immunio-2.0.2 lib/immunio/plugins/action_view/fragment_caching.rb