lib/dry/view/controller.rb in dry-view-0.3.0 vs lib/dry/view/controller.rb in dry-view-0.4.0
- old
+ new
@@ -8,10 +8,12 @@
require 'dry/view/scope'
module Dry
module View
class Controller
+ UndefinedTemplateError = Class.new(StandardError)
+
DEFAULT_LAYOUTS_DIR = 'layouts'.freeze
DEFAULT_CONTEXT = Object.new.freeze
EMPTY_LOCALS = {}.freeze
include Dry::Equalizer(:config)
@@ -49,21 +51,21 @@
end
# @api public
def self.expose(*names, **options, &block)
if names.length == 1
- exposures.add(names.first, block, **options)
+ exposures.add(names.first, block, options)
else
names.each do |name|
- exposures.add(name, **options)
+ exposures.add(name, options)
end
end
end
# @api public
def self.private_expose(*names, **options, &block)
- expose(*names, **options.merge(private: true), &block)
+ expose(*names, **options, private: true, &block)
end
# @api private
def self.exposures
@exposures ||= Exposures.new
@@ -78,17 +80,19 @@
@exposures = self.class.exposures.bind(self)
end
# @api public
def call(format: config.default_format, context: config.context, **input)
+ raise UndefinedTemplateError, "no +template+ configured" unless template_path
+
renderer = self.class.renderer(format)
- template_content = renderer.(template_path, template_scope(renderer, context, **input))
+ template_content = renderer.template(template_path, template_scope(renderer, context, input))
return template_content unless layout?
- renderer.(layout_path, layout_scope(renderer, context)) do
+ renderer.template(layout_path, layout_scope(renderer, context)) do
template_content
end
end
# @api public
@@ -105,10 +109,10 @@
def layout_scope(renderer, context)
scope(renderer.chdir(layout_dir), context)
end
def template_scope(renderer, context, **input)
- scope(renderer.chdir(template_path), context, locals(**input))
+ scope(renderer.chdir(template_path), context, locals(input))
end
def scope(renderer, context, locals = EMPTY_LOCALS)
Scope.new(
renderer: renderer,