Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sinatra-namespace: Allow for set :<engine> #1255

Merged
merged 1 commit into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion sinatra-contrib/lib/sinatra/namespace.rb
Expand Up @@ -225,6 +225,12 @@ module NamespacedMethods
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
Expand Down Expand Up @@ -279,7 +285,7 @@ def respond_to(*args)
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)
Expand Down
10 changes: 10 additions & 0 deletions sinatra-contrib/spec/namespace_spec.rb
Expand Up @@ -788,4 +788,14 @@ class CError < StandardError;
expect(last_response.body).to eq('true')
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