Skip to content

Commit

Permalink
Merge pull request #645 from voidlabs/template-url-helper
Browse files Browse the repository at this point in the history
Add experimental Url.templatePath and Url.imageProcessor methods for the templating language
  • Loading branch information
bago authored May 12, 2022
2 parents bd73791 + b373a7a commit 45ebf25
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var performanceAwareCaller = require("./timed-call.js").timedCall;
var addUndoStackExtensionMaker = require("./undomanager/undomain.js");
var colorPlugin = require("./ext/color.js");
var utilPlugin = require("./ext/util.js");
var urlPlugin = require("./ext/url.js");
var inlinerPlugin = require("./ext/inliner.js");

var localStorageLoader = require("./ext/localstorage.js");
Expand Down Expand Up @@ -118,7 +119,7 @@ var start = function(options, templateFile, templateMetadata, jsorjson, customEx
};

// simpleTranslationPlugin must be before the undoStack to translate undo/redo labels
var extensions = [simpleTranslationPlugin, addUndoStackExtensionMaker(performanceAwareCaller), colorPlugin, utilPlugin, inlinerPlugin];
var extensions = [simpleTranslationPlugin, addUndoStackExtensionMaker(performanceAwareCaller), colorPlugin, utilPlugin, urlPlugin, inlinerPlugin];
if (typeof customExtensions !== 'undefined')
for (var k = 0; k < customExtensions.length; k++) extensions.push(customExtensions[k]);
extensions.push(fileUploadMessagesExtension);
Expand Down
2 changes: 1 addition & 1 deletion src/js/converter/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var conditionBinding = function(expression, bindingProvider, defVal) {
// return gen(node.object) + '[' + gen(node.property) + ']';
} else if (node.type == 'MemberExpression' && !node.computed) {
var me = gen(node.object, bindingProvider, false) + '.' + gen(node.property, bindingProvider, false);
if (lookupmember && node.object.name !== 'Math' && node.object.name !== 'Color' && node.object.name !== 'Util') return bindingProvider(me, defVal) + '()';
if (lookupmember && node.object.name !== 'Math' && node.object.name !== 'Color' && node.object.name !== 'Util' && node.object.name !== 'Url') return bindingProvider(me, defVal) + '()';
return me;
} else if (node.type === "Literal") {
return node.raw;
Expand Down
18 changes: 18 additions & 0 deletions src/js/ext/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
/* global global: false */
var ko = require("knockout");

// WARNING: these are experimental and we may remove them in future releases,
// if you use them please get in touch with developers
var urlPlugin = function(vm) {
global.Url = {
'templatePath': function() {
return vm.templatePath.apply(vm, arguments);
},
'imageProcessor': function() {
return ko.bindingHandlers.wysiwygSrc.convertedUrl.apply(ko.bindingHandlers.wysiwygSrc, arguments);
},
};
};

module.exports = urlPlugin;
3 changes: 3 additions & 0 deletions src/js/ext/util.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"use strict";
/* global global: false */

var utilPlugin = function(vm) {
global.Util = {
'decodeURI': decodeURI,
Expand Down

0 comments on commit 45ebf25

Please sign in to comment.