2013-02-23 04:41:12 +08:00
|
|
|
class DiscourseIIFE < Sprockets::Processor
|
|
|
|
|
|
|
|
# Add a IIFE around our javascript
|
|
|
|
def evaluate(context, locals)
|
|
|
|
|
|
|
|
path = context.pathname.to_s
|
2013-03-01 03:31:39 +08:00
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
# Only discourse or admin paths
|
2013-06-19 01:44:20 +08:00
|
|
|
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/ || path =~ /\/test\/javascripts/)
|
2013-02-23 04:41:12 +08:00
|
|
|
|
2013-06-19 01:44:20 +08:00
|
|
|
# Ignore the js helper
|
|
|
|
return data if (path =~ /test\_helper\.js/)
|
|
|
|
|
|
|
|
# Ignore translations
|
2013-02-23 04:41:12 +08:00
|
|
|
return data if (path =~ /\/translations/)
|
|
|
|
|
|
|
|
# We don't add IIFEs to handlebars
|
|
|
|
return data if path =~ /\.handlebars/
|
2013-03-01 03:31:39 +08:00
|
|
|
return data if path =~ /\.shbrs/
|
|
|
|
return data if path =~ /\.hbrs/
|
2013-02-23 04:41:12 +08:00
|
|
|
|
|
|
|
"(function () {\n\nvar $ = window.jQuery;\n\n#{data}\n\n})(this);"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|