Sha256: 79451fcf0ec7e3a4bcea05d46444094e642de1f18aa4966649ff318f1cbf2f63

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

# auto_register: false

require "json" # required for Hanami::Action::Flash to work
require "hanami/controller"
require "hanami/action/cookies"
require "hanami/action/csrf_protection"
require "hanami/action/session"
require "<%= application_path %>/import"

module <%= application_module %>
  module Web
    class Action < Hanami::Action
      def self.inherited(klass)
        super

        # It would be nice if these could just be included on the top class,
        # rather than on subclasses via this inherited hook
        klass.include Hanami::Action::Cookies
        klass.include Hanami::Action::Session
        klass.include Hanami::Action::CSRFProtection
      end

      include Import[
        "assets",
        "web.action.configuration",
        view_context: "web.view.context",
      ]

      attr_reader :_deps

      def initialize(**deps)
        @_deps = deps
        super
      end

      def with(**new_deps)
        self.class.new(_deps.merge(new_deps))
      end

      private

      def render(view, req, res, **args)
        res.body = view.(context: view_context.with(view_context_options(req, res)), **args)
        res
      end

      def view_context_options(req, res)
        {
          assets: assets,
          csrf_token: req.session[Hanami::Action::CSRFProtection::CSRF_TOKEN],
          flash: res.flash,
        }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
snowpack-1.0.0.alpha7 lib/snowpack/generators/application/templates/lib/__application_path__/web/action.rb.tt
snowpack-1.0.0.alpha6 lib/snowpack/generators/application/templates/lib/__application_path__/web/action.rb.tt
snowpack-1.0.0.alpha5 lib/snowpack/generators/application/templates/lib/__application_path__/web/action.rb.tt
snowpack-1.0.0.alpha4 lib/snowpack/generators/application/templates/lib/__application_path__/web/action.rb.tt
snowpack-1.0.0.alpha3 lib/snowpack/generators/application/templates/lib/__application_path__/web/action.rb.tt
snowpack-1.0.0.alpha2 lib/snowpack/generators/application/templates/lib/__application_path__/web/action.rb.tt