mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Clean up JS, add YUIDoc support, automatically create IIFE via asset pipeline
This commit is contained in:
22
lib/discourse_iife.rb
Normal file
22
lib/discourse_iife.rb
Normal file
@ -0,0 +1,22 @@
|
||||
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/ or 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
|
Reference in New Issue
Block a user