discourse/lib/source_url.rb

25 lines
553 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2015-04-17 04:44:24 +08: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)
2017-07-28 09:20:09 +08:00
result = new(filename) { source }.render(context)
context.metadata.merge(data: result)
end
2015-04-17 04:44:24 +08:00
def prepare
end
def evaluate(scope, locals, &block)
code = +"eval("
code << data.inspect
code << " + \"\\n//# sourceURL=#{scope.logical_path}\""
code << ");\n"
2015-04-17 04:44:24 +08:00
end
end