2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-16 16:44:24 -04:00
|
|
|
class SourceURL < Tilt::Template
|
|
|
|
self.default_mime_type = 'application/javascript'
|
|
|
|
|
2017-04-17 10:11:51 -04:00
|
|
|
def self.call(input)
|
|
|
|
filename = input[:filename]
|
|
|
|
source = input[:data]
|
|
|
|
context = input[:environment].context_class.new(input)
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
result = new(filename) { source }.render(context)
|
2017-04-17 10:11:51 -04:00
|
|
|
context.metadata.merge(data: result)
|
|
|
|
end
|
|
|
|
|
2015-04-16 16:44:24 -04:00
|
|
|
def prepare
|
|
|
|
end
|
|
|
|
|
|
|
|
def evaluate(scope, locals, &block)
|
2019-05-06 03:03:33 -04:00
|
|
|
code = +"eval("
|
2015-04-16 16:44:24 -04:00
|
|
|
code << data.inspect
|
2015-05-28 00:43:12 -04:00
|
|
|
code << " + \"\\n//# sourceURL=#{scope.logical_path}\""
|
2015-04-16 16:44:24 -04:00
|
|
|
code << ");\n"
|
|
|
|
code
|
|
|
|
end
|
|
|
|
end
|