mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 10:43:57 +08:00
26 lines
752 B
Ruby
26 lines
752 B
Ruby
class DiscourseIIFE < Sprockets::Processor
|
|
|
|
# Add a IIFE around our javascript
|
|
def evaluate(context, locals)
|
|
|
|
path = context.pathname.to_s
|
|
|
|
# Only discourse or admin paths
|
|
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/ || path =~ /\/test\/javascripts/)
|
|
|
|
# Ignore the js helpers
|
|
return data if (path =~ /test\_helper\.js/)
|
|
return data if (path =~ /javascripts\/helpers\//)
|
|
|
|
# Ignore translations
|
|
return data if (path =~ /\/translations/)
|
|
|
|
# We don't add IIFEs to handlebars
|
|
return data if path =~ /\.handlebars/
|
|
return data if path =~ /\.shbrs/
|
|
return data if path =~ /\.hbrs/
|
|
|
|
"(function () {\n\nvar $ = window.jQuery;\n\n#{data}\n\n})(this);"
|
|
end
|
|
|
|
end |