discourse/lib/source_url.rb
Robin Ward 57390d0bb9 FIX: Re-apply sourceURL in development mode
The `sourceURL` directive must be on the same line as the thing it's
referencing. This patch allows it to work again in development mode
because each Javascript file ends up in its own `define(...)` line.

It will strip out any trailing whitespace and put the `sourceURL`
comment on the same line and everything seems to work.
2020-01-22 18:12:41 -05:00

22 lines
490 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)
"#{data.rstrip} //# sourceURL=#{scope.logical_path}\n\n"
end
end