2016-04-17 22:47:52 -04:00
|
|
|
class DiscourseIIFE
|
|
|
|
def initialize(options = {}, &block)
|
|
|
|
end
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2016-04-17 22:47:52 -04:00
|
|
|
def self.instance
|
|
|
|
@instance ||= new
|
|
|
|
end
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2016-04-17 22:47:52 -04:00
|
|
|
def self.call(input)
|
|
|
|
instance.call(input)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add a IIFE around our javascript
|
|
|
|
def call(input)
|
|
|
|
path = input[:environment].context_class.new(input).pathname.to_s
|
|
|
|
data = input[:data]
|
2013-02-28 14:31:39 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
# Only discourse or admin paths
|
2013-06-18 13:44:20 -04:00
|
|
|
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/ || path =~ /\/test\/javascripts/)
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2013-06-20 13:58:54 -04:00
|
|
|
# Ignore the js helpers
|
2013-06-18 13:44:20 -04:00
|
|
|
return data if (path =~ /test\_helper\.js/)
|
2013-06-20 13:58:54 -04:00
|
|
|
return data if (path =~ /javascripts\/helpers\//)
|
2013-06-18 13:44:20 -04:00
|
|
|
|
2014-04-29 20:59:57 -04:00
|
|
|
# Ignore ES6 files
|
|
|
|
return data if (path =~ /\.es6/)
|
|
|
|
|
2013-06-18 13:44:20 -04:00
|
|
|
# Ignore translations
|
2013-02-22 15:41:12 -05:00
|
|
|
return data if (path =~ /\/translations/)
|
|
|
|
|
|
|
|
# We don't add IIFEs to handlebars
|
|
|
|
return data if path =~ /\.handlebars/
|
2013-02-28 14:31:39 -05:00
|
|
|
return data if path =~ /\.shbrs/
|
|
|
|
return data if path =~ /\.hbrs/
|
2014-09-26 15:23:15 -04:00
|
|
|
return data if path =~ /\.hbs/
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2016-11-15 11:41:16 -05:00
|
|
|
return data if path =~ /discourse-loader/
|
|
|
|
|
2015-08-13 15:19:27 -04:00
|
|
|
"(function () {\n\nvar $ = window.jQuery;\n// IIFE Wrapped Content Begins:\n\n#{data}\n\n// IIFE Wrapped Content Ends\n\n })(this);"
|
2013-02-22 15:41:12 -05:00
|
|
|
end
|
|
|
|
|
2014-04-29 20:59:57 -04:00
|
|
|
end
|