Update SourceURL to work better

This commit is contained in:
Robin Ward 2015-04-16 16:44:24 -04:00
parent e83bf7dc07
commit 788b66e4a3
4 changed files with 18 additions and 3 deletions

View File

@ -1,3 +1,5 @@
require 'discourse_iife'
require 'source_url'
Rails.application.assets.register_preprocessor('application/javascript', DiscourseIIFE)
Rails.application.assets.register_preprocessor('application/javascript', DiscourseIIFE)
Rails.application.assets.register_postprocessor('application/javascript', SourceURL)

View File

@ -32,7 +32,6 @@ class DiscourseIIFE < Sprockets::Processor
.sub("/app/assets/javascripts", "")
.sub("/test/javascripts", "")
res << "\nwindow.__jshintSrc = window.__jshintSrc || {}; window.__jshintSrc['/assets#{req_path}'] = #{data.to_json};\n"
res << "\n//@ sourceURL=/#{context.logical_path}\n"
end
res

View File

@ -127,7 +127,6 @@ module Tilt
req_path = "/assets/#{scope.logical_path}.#{extension}"
@output << "\nwindow.__jshintSrc = window.__jshintSrc || {}; window.__jshintSrc['#{req_path}'] = #{data.to_json};\n"
@output << "\n//@ sourceURL=/#{scope.logical_path}\n"
end
@output

15
lib/source_url.rb Normal file
View File

@ -0,0 +1,15 @@
class SourceURL < Tilt::Template
self.default_mime_type = 'application/javascript'
def prepare
end
def evaluate(scope, locals, &block)
code = ''
code << 'eval('
code << data.inspect
code << " + \"\\n//@ sourceURL=/#{scope.logical_path}\""
code << ");\n"
code
end
end