mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 17:06:31 -06:00
26 lines
562 B
Ruby
26 lines
562 B
Ruby
# frozen_string_literal: true
|
|
|
|
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
|
|
|
|
def prepare
|
|
end
|
|
|
|
def evaluate(scope, locals, &block)
|
|
code = +"eval("
|
|
code << data.inspect
|
|
code << " + \"\\n//# sourceURL=#{scope.logical_path}\""
|
|
code << ");\n"
|
|
code
|
|
end
|
|
end
|