Skip to content

Commit

Permalink
v2.91.0
Browse files Browse the repository at this point in the history
+ easily switch a component's view template using the _templateExt property.
  • Loading branch information
sucom committed Dec 20, 2022
1 parent b5b98a3 commit c090661
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Single Page Application (SPA) Simplified Framework/Library",
"main": "dist/spa-bundle.js",

"version": "2.90.0",
"version": "2.91.0",
"license": "MIT",
"homepage": "https://github.com/sucom/SPA.js",

Expand Down
4 changes: 2 additions & 2 deletions dist/spa-bundle.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/spa-bundle.slim.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spa.js",
"version": "2.90.0",
"version": "2.91.0",
"description": "Single Page Application (SPA) Simplified Framework/Library",
"main": "dist/spa-bundle.js",
"repository": {
Expand Down
24 changes: 18 additions & 6 deletions src/spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/

(function() {
var _VERSION = '2.90.0';
var _VERSION = '2.91.0';

/* Establish the win object, 'window' in the browser */
var win = window||globalThis, _doc = document, isSPAReady, docBody = _doc.body;
Expand Down Expand Up @@ -2840,7 +2840,7 @@
}

var _baseProps = [
'target', 'template', 'templateCache', 'templateScript', 'templateType', 'templateEngine', 'pugFilters', 'sanitizeApiXss'
'target', 'template', 'templateCache', 'templateScript', 'templateExt', 'templateType', 'templateEngine', 'pugFilters', 'sanitizeApiXss'
, 'templateUrl', 'templateUrlMethod', 'templateUrlParams', 'templateUrlPayload', 'templateUrlHeaders', 'onTemplateUrlError'
, 'style', 'styleCache', 'styles', 'stylesCache'
, 'scripts', 'scriptsCache', 'require', 'dataPreRequest', 'data', 'skipDataBind', 'skipDefaultBind', 'skipKoBind', 'useSpaBind', 'useDataBindRefresh'
Expand Down Expand Up @@ -5128,7 +5128,7 @@

function _adjustComponentOptions(componentName, options){
var tmplId = '_rtt_'+componentName, tmplBody = '';
if (options && _isObj(options) && xsr.hasPrimaryKeys(options, 'template|templateStr|templateString|templateUrl') ) {
if (options && _isObj(options) && xsr.hasPrimaryKeys(options, 'template|templateStr|templateString|templateUrl|templateExt') ) {
if (options.hasOwnProperty('template')) {
var givenTemplate = options['template'].trim();
var isContainerId = ((givenTemplate.beginsWithStr('#') && !givenTemplate.containsStr(' ')) || ((givenTemplate=='inline') || (givenTemplate=='.')));
Expand All @@ -5140,6 +5140,16 @@
options['templateStr'] = options['template'];
}
}

if (options.hasOwnProperty('templateExt')) {
if (!options.hasOwnProperty('templateUrl')) {
options.templateUrl = './'+componentName+'.'+(options.templateExt.trimLeftStr('.'));
}
if ((/pug/gi.test(options.templateExt)) && (!options.hasOwnProperty('templateType'))) {
options.templateType = 'pug';
}
}

if (xsr.hasPrimaryKeys(options, 'templateStr|templateString')) {
tmplBody = options['templateStr'] || options['templateString'] || '';
xsr.updateTemplateScript(tmplId, tmplBody);
Expand Down Expand Up @@ -5322,7 +5332,7 @@

options = _adjustComponentOptions(componentName, options);

var baseProps = [ 'target','template','templateCache','templateScript', 'templateType', 'templateEngine', 'pugFilters', 'sanitizeApiXss',
var baseProps = [ 'target','template','templateCache','templateScript', 'templateExt', 'templateType', 'templateEngine', 'pugFilters', 'sanitizeApiXss',
'templateUrl', 'templateUrlMethod', 'templateUrlParams', 'templateUrlPayload', 'templateUrlHeaders', 'onTemplateUrlError',
'style','styleCache','styles','stylesCache',
'scripts','scriptsCache','require','dataPreRequest','data','skipDataBind', 'skipDefaultBind', 'skipKoBind', 'useSpaBind', 'useDataBindRefresh',
Expand Down Expand Up @@ -6001,7 +6011,8 @@

var _cFldrPath = xsr.defaults.components.rootPath+ ((xsr.defaults.components.inFolder || isChildComponent)? (componentPath+"/"): '')
, _cFilesPath = _cFldrPath+componentFileName
, _cTmplFile = _cFilesPath+xsr.defaults.components.templateExt
, _cTmplExt = '.'+((options.templateExt||xsr.defaults.components.templateExt).trimLeftStr('.'))
, _cTmplFile = _cFilesPath+_cTmplExt
, _cScriptExt = xsr.defaults.components.scriptExt
, _cScriptFile = (options && _isObj(options) && options.hasOwnProperty('script'))? options['script'] : ((_cScriptExt)? (_cFilesPath+_cScriptExt) : '')
, _asyncAttempt= 300
Expand Down Expand Up @@ -6845,6 +6856,7 @@
, dataTemplatesCache: true
, templateScript: false
, templateType: ''
, templateExt:'.html'
, templateEngine: ''
, sanitizeApiXss: false

Expand Down Expand Up @@ -7726,7 +7738,7 @@

var isSpaTemplate = /<!--\s*#+(spa-template|spaTemplate|spa|nxt-template|nxtTemplate|nxt)/gi.test(templateContentToBindAndRender)? 'spa' : '';
var isDotTemplate = /<!--\s*#+(dot-template|dotTemplate|dot)/gi.test(templateContentToBindAndRender)? 'dot' : '';
var isPugTemplate = /<!--\s*#+(pug-template|pugTemplate|pug)/gi.test(templateContentToBindAndRender)? 'pug' : '';
var isPugTemplate = /(\/\/\s*-*\s*pug)|(<!--\s*#*(pug-template|pugTemplate|pug))/gi.test(templateContentToBindAndRender)? 'pug' : '';

var $templateEngine = (spaRVOptions.templateType || spaRVOptions.templateEngine || isDotTemplate || isSpaTemplate || isPugTemplate || xsr.defaults.components.templateType || xsr.defaults.components.templateEngine);
var spaTemplateEngine = ($templateEngine || 'handlebars').toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion src/spa.min.js

Large diffs are not rendered by default.

0 comments on commit c090661

Please sign in to comment.