UNPKG

ocat-lang

Version:

A programming language for the web design and development

35 lines (34 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processContent = processContent; exports.viewAdapter = viewAdapter; exports.viewAdapt = viewAdapt; const html_1 = require("./html"); function processContent(content, memory, key) { const keyRegex = /{\@key\s+(.*?)}(.*?)\{\@endkey\}/gs; return (0, html_1.processHTML)(memory, content.replace(keyRegex, (match, expectedKey, result) => { return key === expectedKey ? result : ""; })); } function viewAdapter(name, content) { return { name: `/${name .replace(/\.html$/, "") .replace(/index$/, "") .replace(/\.all$/, "*") .replace(/\.key$/, ":key")}`, content, useKey: name.endsWith(".key.html"), useAll: name.endsWith(".all.html"), }; } function viewAdapt(view, mem, key) { const content = processContent(view.content, mem, key); if (view.useKey) { if (!key) { throw new Error("Key is required for key view"); } return content.replace(/{\*key\*}/g, key); } return content; }