discourse/lib/source_url.rb

24 lines
527 B
Ruby
Raw Normal View History

2015-04-16 15:44:24 -05:00
class SourceURL < Tilt::Template
self.default_mime_type = 'application/javascript'
def self.call(input)
filename = input[:filename]
source = input[:data]
context = input[:environment].context_class.new(input)
result = new(filename){source}.render(context)
context.metadata.merge(data: result)
end
2015-04-16 15:44:24 -05:00
def prepare
end
def evaluate(scope, locals, &block)
code = "eval("
2015-04-16 15:44:24 -05:00
code << data.inspect
code << " + \"\\n//# sourceURL=#{scope.logical_path}\""
2015-04-16 15:44:24 -05:00
code << ");\n"
code
end
end