Sha256: 9e560445f9454a16b879ff5064a9fa0af797552d1416870f238e8f394609e439

Contents?: true

Size: 714 Bytes

Versions: 4

Compression:

Stored size: 714 Bytes

Contents

# frozen_string_literal: true

class Roda
  module RodaPlugins
    module DryView
      def self.load_dependencies(app)
        app.plugin :flow
      end

      module InstanceMethods
        def view_context
          self.class["view_context"].with(view_context_options)
        end

        def view_context_options
          {}
        end

        def view_key(name)
          "views.#{name}"
        end
      end

      module RequestMethods
        def view(name, options = {})
          resolve(scope.view_key(name)) do |renderer|
            renderer.call({ context: scope.view_context }.merge(options)).to_s
          end
        end
      end
    end

    register_plugin :dry_view, DryView
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-web-roda-0.14.0 lib/roda/plugins/dry_view.rb
dry-web-roda-0.13.1 lib/roda/plugins/dry_view.rb
dry-web-roda-0.13.0 lib/roda/plugins/dry_view.rb
dry-web-roda-0.12.0 lib/roda/plugins/dry_view.rb