Sha256: 6328b6f028f4df6e42e2db1535af256b05cf8bdce6a821eca9d1f2b11de92f13

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"
require "pakyow/support/message_verifier"
require "pakyow/support/safe_string"

module Pakyow
  module Presenter
    class Renderer
      module Behavior
        module InstallAuthenticity
          extend Support::Extension

          apply_extension do
            build do |view, app:|
              if app.config.presenter.embed_authenticity_token && head = view.head
                head.append(Support::SafeStringHelpers.html_safe("<meta name=\"pw-authenticity-token\">"))
                head.append(Support::SafeStringHelpers.html_safe("<meta name=\"pw-authenticity-param\" content=\"#{app.config.security.csrf.param}\">"))
              end
            end

            attach do |presenter|
              presenter.render node: -> {
                node = object.each_significant_node(:meta).find { |meta_node|
                  meta_node.attributes[:name] == "pw-authenticity-token"
                }

                unless node.nil?
                  View.from_object(node)
                end
              } do
                attributes[:content] = @presentables[:__verifier].sign(Support::MessageVerifier.key)
              end
            end

            expose do |connection|
              connection.set(:__verifier, connection.verifier)
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pakyow-presenter-1.0.1 lib/pakyow/presenter/renderer/behavior/install_authenticity.rb
pakyow-presenter-1.0.0 lib/pakyow/presenter/renderer/behavior/install_authenticity.rb
pakyow-presenter-1.0.0.rc5 lib/pakyow/presenter/renderer/behavior/install_authenticity.rb
pakyow-presenter-1.0.0.rc4 lib/pakyow/presenter/renderer/behavior/install_authenticity.rb
pakyow-presenter-1.0.0.rc3 lib/pakyow/presenter/renderer/behavior/install_authenticity.rb