From 3e20c3a51ec41563d125a49d1177f77a9e2c3541 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Tue, 3 Aug 2021 20:10:24 -0400 Subject: [PATCH] remove mustache --- .gitignore | 3 +- frontend/files/index.html | 133 +++++++++++++++++++--------------- frontend/files/js/mustache.js | 1 - 3 files changed, 76 insertions(+), 61 deletions(-) delete mode 100644 frontend/files/js/mustache.js diff --git a/.gitignore b/.gitignore index 31d7886..255a042 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /server /manager -*.properties \ No newline at end of file +*.properties +.DS_Store \ No newline at end of file diff --git a/frontend/files/index.html b/frontend/files/index.html index ba031df..2aaa99b 100644 --- a/frontend/files/index.html +++ b/frontend/files/index.html @@ -3,7 +3,6 @@ Library - (e.rowNumber = i)); // re-key for new sort - $("#books").html(Mustache.render($("#Table").html(), { books })); + $("#books").html(TableTemplate(books)); $("#books tbody tr") .not(":first") // ignore the headers .on("click", function () { @@ -106,7 +105,7 @@ } function updateCurrentBook(book) { - $("#current").html(Mustache.render($("#View").html(), { book })); + $("#current").html(BookTemplate(book)); } function titleCleaner(title) { @@ -138,6 +137,78 @@ return ISBN + (checkdigit === 10 ? "X" : checkdigit); } + function BookTemplate({ + "isbn-13": isbn13, + authors, + coverurl, + description, + format, + notes, + onLoan, + publisher, + series, + signed, + title, + volume, + year, + }) { + return `${coverurl ? `` : ""} +

${title}

+

${authors}

+ ${isbn13}
+ ${publisher}, ${year}
+ ${ + series + ? `${series}${volume ? `, Volume ${volume}` : ""}
` + : "" + } + ${signed ? "Signed by the author ✒
" : ""} + ${format} + ${onLoan ? `

On loan to ${onLoan}

` : ""} +
+

${description}

+ ${notes ? `Notes:

${notes}

` : ""} +
`; + } + + function TableRowTemplate({ + "isbn-13": isbn13, + authors, + onLoan, + publisher, + rowNumber, + signed, + title, + year, + }) { + return ` + + ${title} ${ + signed + ? '︎' + : "" + } + + ${authors} + ${publisher} + ${year} + ${isbn13} + `; + } + + function TableTemplate(books) { + return ` + + + + + + + ${books.reduce((acc, book) => { + return acc.concat(TableRowTemplate(book)); + }, "")}
TitleAuthorPublisherYearISBN
`; + } + window.addEventListener("DOMContentLoaded", init); @@ -162,61 +233,5 @@
- - - - diff --git a/frontend/files/js/mustache.js b/frontend/files/js/mustache.js deleted file mode 100644 index dfe0b6a..0000000 --- a/frontend/files/js/mustache.js +++ /dev/null @@ -1 +0,0 @@ -(function defineMustache(global,factory){if(typeof exports==="object"&&exports&&typeof exports.nodeName!=="string"){factory(exports)}else if(typeof define==="function"&&define.amd){define(["exports"],factory)}else{global.Mustache={};factory(global.Mustache)}})(this,function mustacheFactory(mustache){var objectToString=Object.prototype.toString;var isArray=Array.isArray||function isArrayPolyfill(object){return objectToString.call(object)==="[object Array]"};function isFunction(object){return typeof object==="function"}function typeStr(obj){return isArray(obj)?"array":typeof obj}function escapeRegExp(string){return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function hasProperty(obj,propName){return obj!=null&&typeof obj==="object"&&propName in obj}var regExpTest=RegExp.prototype.test;function testRegExp(re,string){return regExpTest.call(re,string)}var nonSpaceRe=/\S/;function isWhitespace(string){return!testRegExp(nonSpaceRe,string)}var entityMap={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};function escapeHtml(string){return String(string).replace(/[&<>"'`=\/]/g,function fromEntityMap(s){return entityMap[s]})}var whiteRe=/\s*/;var spaceRe=/\s+/;var equalsRe=/\s*=/;var curlyRe=/\s*\}/;var tagRe=/#|\^|\/|>|\{|&|=|!/;function parseTemplate(template,tags){if(!template)return[];var sections=[];var tokens=[];var spaces=[];var hasTag=false;var nonSpace=false;function stripSpace(){if(hasTag&&!nonSpace){while(spaces.length)delete tokens[spaces.pop()]}else{spaces=[]}hasTag=false;nonSpace=false}var openingTagRe,closingTagRe,closingCurlyRe;function compileTags(tagsToCompile){if(typeof tagsToCompile==="string")tagsToCompile=tagsToCompile.split(spaceRe,2);if(!isArray(tagsToCompile)||tagsToCompile.length!==2)throw new Error("Invalid tags: "+tagsToCompile);openingTagRe=new RegExp(escapeRegExp(tagsToCompile[0])+"\\s*");closingTagRe=new RegExp("\\s*"+escapeRegExp(tagsToCompile[1]));closingCurlyRe=new RegExp("\\s*"+escapeRegExp("}"+tagsToCompile[1]))}compileTags(tags||mustache.tags);var scanner=new Scanner(template);var start,type,value,chr,token,openSection;while(!scanner.eos()){start=scanner.pos;value=scanner.scanUntil(openingTagRe);if(value){for(var i=0,valueLength=value.length;i0?sections[sections.length-1][4]:nestedTokens;break;default:collector.push(token)}}return nestedTokens}function Scanner(string){this.string=string;this.tail=string;this.pos=0}Scanner.prototype.eos=function eos(){return this.tail===""};Scanner.prototype.scan=function scan(re){var match=this.tail.match(re);if(!match||match.index!==0)return"";var string=match[0];this.tail=this.tail.substring(string.length);this.pos+=string.length;return string};Scanner.prototype.scanUntil=function scanUntil(re){var index=this.tail.search(re),match;switch(index){case-1:match=this.tail;this.tail="";break;case 0:match="";break;default:match=this.tail.substring(0,index);this.tail=this.tail.substring(index)}this.pos+=match.length;return match};function Context(view,parentContext){this.view=view;this.cache={".":this.view};this.parent=parentContext}Context.prototype.push=function push(view){return new Context(view,this)};Context.prototype.lookup=function lookup(name){var cache=this.cache;var value;if(cache.hasOwnProperty(name)){value=cache[name]}else{var context=this,names,index,lookupHit=false;while(context){if(name.indexOf(".")>0){value=context.view;names=name.split(".");index=0;while(value!=null&&index")value=this.renderPartial(token,context,partials,originalTemplate);else if(symbol==="&")value=this.unescapedValue(token,context);else if(symbol==="name")value=this.escapedValue(token,context);else if(symbol==="text")value=this.rawValue(token);if(value!==undefined)buffer+=value}return buffer};Writer.prototype.renderSection=function renderSection(token,context,partials,originalTemplate){var self=this;var buffer="";var value=context.lookup(token[1]);function subRender(template){return self.render(template,context,partials)}if(!value)return;if(isArray(value)){for(var j=0,valueLength=value.length;j