mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 10:24:27 +08:00
5c3f994c80
This allows us to use `sourceURL` which otherwise does not work. In the future we hope to have proper source maps in development mode and disable this again.
25 lines
553 B
Ruby
25 lines
553 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"
|
|
end
|
|
end
|