From 7ff5b228cd92e80c14a1962e5ea88e2374d69ddd Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 30 Jun 2016 17:10:08 -0400 Subject: [PATCH] REFACTOR: Raw Handlebars ported to ES6 --- .../discourse/lib/ember_compat_handlebars.js | 160 ----------------- .../javascripts/discourse/lib/helpers.js.es6 | 4 +- .../discourse/lib/raw-handlebars.js.es6 | 164 ++++++++++++++++++ app/assets/javascripts/main_include.js | 2 +- app/models/site_customization.rb | 2 +- ...compat_handlebars.rb => raw_handlebars.rb} | 37 ++-- spec/models/site_customization_spec.rb | 4 +- .../acceptance/category-hashtag-test.js.es6 | 14 +- 8 files changed, 198 insertions(+), 189 deletions(-) delete mode 100644 app/assets/javascripts/discourse/lib/ember_compat_handlebars.js create mode 100644 app/assets/javascripts/discourse/lib/raw-handlebars.js.es6 rename lib/freedom_patches/{ember_compat_handlebars.rb => raw_handlebars.rb} (54%) diff --git a/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js b/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js deleted file mode 100644 index 6539100a491..00000000000 --- a/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js +++ /dev/null @@ -1,160 +0,0 @@ -// keep IIF for simpler testing - -// EmberCompatHandlebars is a mechanism for quickly rendering templates which is Ember aware -// templates are highly compatible with Ember so you don't need to worry about calling "get" -// and computed properties function, additionally it uses stringParams like Ember does - -(function(){ - - // compat with ie8 in case this gets picked up elsewhere - var objectCreate = Object.create || function(parent) { - function F() {} - F.prototype = parent; - return new F(); - }; - - - var RawHandlebars = Handlebars.create(); - - RawHandlebars.helper = function() {}; - RawHandlebars.helpers = objectCreate(Handlebars.helpers); - - RawHandlebars.helpers.get = function(context, options){ - var firstContext = options.contexts[0]; - var val = firstContext[context]; - - if (val && val.isDescriptor) { return Em.get(firstContext, context); } - val = val === undefined ? Em.get(firstContext, context): val; - return val; - }; - - // adds compatability so this works with stringParams - var stringCompatHelper = function(fn){ - - var old = RawHandlebars.helpers[fn]; - RawHandlebars.helpers[fn] = function(context,options){ - return old.apply(this, [ - RawHandlebars.helpers.get(context,options), - options - ]); - }; - }; - - // #each .. in support (as format is transformed to this) - RawHandlebars.registerHelper('each', function(localName,inKeyword,contextName,options){ - var list = Em.get(this, contextName); - var output = []; - var innerContext = Object.create(this); - for (var i=0; i { - return [ - 200, - {"Content-Type": "application/json"}, - object - ]; - }; - - } -}); +acceptance("Category hashtag", { loggedIn: true }); test("category hashtag is cooked properly", () => { visit("/t/internationalization-localization/280");