Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a method to all Template classes that states whether the template…

… sllows running arbitrary Ruby script. This is useful for users of Tilt who want to disallow templates that support script or who want to treat them differently.
  • Loading branch information...
commit 01e18dd460ac11d1771090a36fbb4965c3d8b561 1 parent 10a8ffa
@bhollis authored
View
4 lib/tilt/coffee.rb
@@ -45,6 +45,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= CoffeeScript.compile(data, options)
end
+
+ def allows_script?
+ false
+ end
end
end
View
8 lib/tilt/css.rb
@@ -24,6 +24,10 @@ def evaluate(scope, locals, &block)
@output ||= @engine.render
end
+ def allows_script?
+ false
+ end
+
private
def sass_options
options.merge(:filename => eval_file, :line => line, :syntax => :sass)
@@ -67,6 +71,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_css
end
+
+ def allows_script?
+ false
+ end
end
end
View
4 lib/tilt/liquid.rb
@@ -37,5 +37,9 @@ def evaluate(scope, locals, &block)
locals['content'] = locals['yield']
@engine.render(locals)
end
+
+ def allows_script?
+ false
+ end
end
end
View
24 lib/tilt/markdown.rb
@@ -37,6 +37,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
+
+ def allows_script?
+ false
+ end
end
# Upskirt Markdown implementation. See:
@@ -61,6 +65,10 @@ def evaluate(scope, locals, &block)
@engine.evaluate(scope, locals, &block)
end
+ def allows_script?
+ false
+ end
+
# Compatibility mode for Redcarpet 1.x
class Redcarpet1 < RDiscountTemplate
self.default_mime_type = 'text/html'
@@ -116,6 +124,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.render(data)
end
+
+ def allows_script?
+ false
+ end
end
end
@@ -140,6 +152,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
+
+ def allows_script?
+ false
+ end
end
# Maruku markdown implementation. See:
@@ -161,6 +177,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
+
+ def allows_script?
+ false
+ end
end
# Kramdown Markdown implementation. See:
@@ -185,6 +205,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
+
+ def allows_script?
+ false
+ end
end
end
View
4 lib/tilt/radius.rb
@@ -47,5 +47,9 @@ def evaluate(scope, locals, &block)
parser = Radius::Parser.new(context, options)
parser.parse(data)
end
+
+ def allows_script?
+ false
+ end
end
end
View
4 lib/tilt/rdoc.rb
@@ -29,5 +29,9 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_s
end
+
+ def allows_script?
+ false
+ end
end
end
View
9 lib/tilt/template.rb
@@ -92,6 +92,15 @@ def eval_file
file || '(__TEMPLATE__)'
end
+ # Whether or not this template engine allows executing Ruby script
+ # within the template. If this is false, +scope+ and +locals+ will
+ # generally not be used, nor will the provided block be avaiable
+ # via +yield+.
+ # This should be overridden by template subclasses.
+ def allows_script?
+ true
+ end
+
protected
# Called once and only once for each template subclass the first time
# the template class is initialized. This should be used to require the
View
4 lib/tilt/textile.rb
@@ -20,6 +20,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
+
+ def allows_script?
+ false
+ end
end
end
View
8 lib/tilt/wiki.rb
@@ -24,6 +24,10 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
+
+ def allows_script?
+ false
+ end
end
# WikiCloth implementation. See:
@@ -46,5 +50,9 @@ def prepare
def evaluate(scope, locals, &block)
@output ||= @engine.to_html
end
+
+ def allows_script?
+ false
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.