discourse/lib/discourse_iife.rb
Régis Hanol 239cbd2d58 enforce coding convention
replaced every `and` by `&&` and every `or` by `||`
2013-03-05 01:42:44 +01:00

22 lines
No EOL
593 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/)
# Ugh, 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