Skip to content

Commit

Permalink
Merge pull request #143 from bhollis/master
Browse files Browse the repository at this point in the history
Add allows_script? method to Template
  • Loading branch information
rtomayko committed Aug 5, 2012
2 parents 5c8c202 + 01e18dd commit 2f269cb
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/tilt/coffee.rb
Expand Up @@ -45,6 +45,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= CoffeeScript.compile(data, options) @output ||= CoffeeScript.compile(data, options)
end end

def allows_script?
false
end
end end
end end


8 changes: 8 additions & 0 deletions lib/tilt/css.rb
Expand Up @@ -24,6 +24,10 @@ def evaluate(scope, locals, &block)
@output ||= @engine.render @output ||= @engine.render
end end


def allows_script?
false
end

private private
def sass_options def sass_options
options.merge(:filename => eval_file, :line => line, :syntax => :sass) options.merge(:filename => eval_file, :line => line, :syntax => :sass)
Expand Down Expand Up @@ -67,6 +71,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_css @output ||= @engine.to_css
end end

def allows_script?
false
end
end end
end end


4 changes: 4 additions & 0 deletions lib/tilt/liquid.rb
Expand Up @@ -37,5 +37,9 @@ def evaluate(scope, locals, &block)
locals['content'] = locals['yield'] locals['content'] = locals['yield']
@engine.render(locals) @engine.render(locals)
end end

def allows_script?
false
end
end end
end end
24 changes: 24 additions & 0 deletions lib/tilt/markdown.rb
Expand Up @@ -37,6 +37,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_html @output ||= @engine.to_html
end end

def allows_script?
false
end
end end


# Upskirt Markdown implementation. See: # Upskirt Markdown implementation. See:
Expand All @@ -61,6 +65,10 @@ def evaluate(scope, locals, &block)
@engine.evaluate(scope, locals, &block) @engine.evaluate(scope, locals, &block)
end end


def allows_script?
false
end

# Compatibility mode for Redcarpet 1.x # Compatibility mode for Redcarpet 1.x
class Redcarpet1 < RDiscountTemplate class Redcarpet1 < RDiscountTemplate
self.default_mime_type = 'text/html' self.default_mime_type = 'text/html'
Expand Down Expand Up @@ -116,6 +124,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.render(data) @output ||= @engine.render(data)
end end

def allows_script?
false
end
end end
end end


Expand All @@ -140,6 +152,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_html @output ||= @engine.to_html
end end

def allows_script?
false
end
end end


# Maruku markdown implementation. See: # Maruku markdown implementation. See:
Expand All @@ -161,6 +177,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_html @output ||= @engine.to_html
end end

def allows_script?
false
end
end end


# Kramdown Markdown implementation. See: # Kramdown Markdown implementation. See:
Expand All @@ -185,6 +205,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_html @output ||= @engine.to_html
end end

def allows_script?
false
end
end end
end end


4 changes: 4 additions & 0 deletions lib/tilt/radius.rb
Expand Up @@ -47,5 +47,9 @@ def evaluate(scope, locals, &block)
parser = Radius::Parser.new(context, options) parser = Radius::Parser.new(context, options)
parser.parse(data) parser.parse(data)
end end

def allows_script?
false
end
end end
end end
4 changes: 4 additions & 0 deletions lib/tilt/rdoc.rb
Expand Up @@ -29,5 +29,9 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_s @output ||= @engine.to_s
end end

def allows_script?
false
end
end end
end end
9 changes: 9 additions & 0 deletions lib/tilt/template.rb
Expand Up @@ -92,6 +92,15 @@ def eval_file
file || '(__TEMPLATE__)' file || '(__TEMPLATE__)'
end 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 protected
# Called once and only once for each template subclass the first time # Called once and only once for each template subclass the first time
# the template class is initialized. This should be used to require the # the template class is initialized. This should be used to require the
Expand Down
4 changes: 4 additions & 0 deletions lib/tilt/textile.rb
Expand Up @@ -20,6 +20,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_html @output ||= @engine.to_html
end end

def allows_script?
false
end
end end
end end


8 changes: 8 additions & 0 deletions lib/tilt/wiki.rb
Expand Up @@ -24,6 +24,10 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_html @output ||= @engine.to_html
end end

def allows_script?
false
end
end end


# WikiCloth implementation. See: # WikiCloth implementation. See:
Expand All @@ -46,5 +50,9 @@ def prepare
def evaluate(scope, locals, &block) def evaluate(scope, locals, &block)
@output ||= @engine.to_html @output ||= @engine.to_html
end end

def allows_script?
false
end
end end
end end

0 comments on commit 2f269cb

Please sign in to comment.