Sha256: 3d74c4e2db0119878dbef169ddea622691f396743749232d315b76b41d539ba8

Contents?: true

Size: 787 Bytes

Versions: 6

Compression:

Stored size: 787 Bytes

Contents

require "roda"
require "rack/csrf"

class Roda
  module RodaPlugins
    module Page
      module InstanceMethods
        def current_page
          page.with_flash(flash)
        end

        def page
          self.class["page"].with(
            csrf_token: -> { Rack::Csrf.token(request.env) },
            csrf_metatag: -> { Rack::Csrf.metatag(request.env) },
            csrf_tag: -> { Rack::Csrf.tag(request.env) },
          )
        end
      end
    end

    module View
      module RequestMethods
        def view(name, overrides = {})
          options = {scope: scope.current_page}.merge(overrides)
          is to: "#{scope.name}.views.#{name}", call_with: [options]
        end
      end
    end

    register_plugin :page, Page
    register_plugin :view, View
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dry-web-roda-0.4.0 lib/dry/web/roda/skeletons/umbrella/lib/roda_plugins.rb
dry-web-roda-0.3.0 lib/dry/web/roda/skeletons/umbrella/lib/roda_plugins.rb
dry-web-roda-0.2.3 lib/dry/web/roda/skeletons/umbrella/lib/roda_plugins.rb
dry-web-roda-0.2.2 lib/dry/web/roda/skeletons/umbrella/lib/roda_plugins.rb
dry-web-roda-0.2.1 lib/dry/web/roda/skeletons/umbrella/lib/roda_plugins.rb
dry-web-roda-0.2.0 lib/dry/web/roda/skeletons/umbrella/lib/roda_plugins.rb