1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

sinatra-namespace: Allow for set :<engine>

This allows to set render engine options local to a namespace
This commit is contained in:
Michishige Kaito 2017-02-09 20:54:16 +00:00 committed by Jordan Owens
parent 8fcaba8774
commit 28505410ec
2 changed files with 17 additions and 1 deletions

View file

@ -224,6 +224,12 @@ module Sinatra
include SharedMethods
attr_reader :base, :templates
ALLOWED_ENGINES = [
:erb, :erubi, :erubis, :haml, :hamlit, :builder, :nokogiri, :sass, :scss,
:less, :liquid, :markdown, :textile, :rdoc, :asciidoc, :radius, :markaby,
:rabl, :slim, :creole, :mediawiki, :coffee, :stylus, :yajl, :wlang
]
def self.prefixed(*names)
names.each { |n| define_method(n) { |*a, &b| prefixed(n, *a, &b) }}
end
@ -278,7 +284,7 @@ module Sinatra
end
def set(key, value = self, &block)
raise ArgumentError, "may not set #{key}" if key != :views
raise ArgumentError, "may not set #{key}" unless ([:views] + ALLOWED_ENGINES).include?(key)
return key.each { |k,v| set(k, v) } if block.nil? and value == self
block ||= proc { value }
singleton_class.send(:define_method, key, &block)

View file

@ -832,4 +832,14 @@ describe Sinatra::Namespace do
expect(last_response.body).to eq('[:foo_bar]')
end
end
it 'forbids unknown engine settings' do
expect {
mock_app do
namespace '/foo' do
set :unknownsetting
end
end
}.to raise_error(ArgumentError, 'may not set unknownsetting')
end
end