htmx-router
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -26,9 +26,9 @@ /// <reference types="node" /> | ||
constructor(req: http.IncomingMessage, res: http.ServerResponse, url: URL); | ||
addLinks(links: MetaHTML[], override?: boolean): void; | ||
addMeta(links: MetaHTML[], override?: boolean): void; | ||
addLinks: (links: MetaHTML[], override?: boolean) => void; | ||
addMeta: (links: MetaHTML[], override?: boolean) => void; | ||
Outlet: () => Promise<string>; | ||
_addOutlet(route: RouteLeaf): void; | ||
_applyMask(mask: boolean[], depth: number): void; | ||
renderHeadHTML(): string; | ||
renderHeadHTML: () => string; | ||
} | ||
export {}; |
@@ -27,2 +27,22 @@ "use strict"; | ||
constructor(req, res, url) { | ||
this.addLinks = (links, override = false) => { | ||
if (!ValidateMetaHTMLs(links)) | ||
throw new Error(`Provided links have invalid attribute`); | ||
if (override) { | ||
this.links = links; | ||
} | ||
else { | ||
this.links.push(...links); | ||
} | ||
}; | ||
this.addMeta = (links, override = false) => { | ||
if (!ValidateMetaHTMLs(links)) | ||
throw new Error(`Provided links have invalid attribute`); | ||
if (override) { | ||
this.meta = links; | ||
} | ||
else { | ||
this.meta.push(...links); | ||
} | ||
}; | ||
// unpacking Outlet caused this to be undefined | ||
@@ -42,2 +62,20 @@ // hence the weird def | ||
}; | ||
this.renderHeadHTML = () => { | ||
let out = ""; | ||
for (const elm of this.links) { | ||
out += "<link"; | ||
for (const attr in elm) { | ||
out += ` ${attr}="${elm[attr].replace(/"/g, "\\\"")}"`; | ||
} | ||
out += "></link>"; | ||
} | ||
for (const elm of this.meta) { | ||
out += "<meta"; | ||
for (const attr in elm) { | ||
out += ` ${attr}="${elm[attr].replace(/"/g, "\\\"")}"`; | ||
} | ||
out += "></meta>"; | ||
} | ||
return out; | ||
}; | ||
this.req = req; | ||
@@ -54,22 +92,2 @@ this.res = res; | ||
} | ||
addLinks(links, override = false) { | ||
if (!ValidateMetaHTMLs(links)) | ||
throw new Error(`Provided links have invalid attribute`); | ||
if (override) { | ||
this.links = links; | ||
} | ||
else { | ||
this.links.push(...links); | ||
} | ||
} | ||
addMeta(links, override = false) { | ||
if (!ValidateMetaHTMLs(links)) | ||
throw new Error(`Provided links have invalid attribute`); | ||
if (override) { | ||
this.meta = links; | ||
} | ||
else { | ||
this.meta.push(...links); | ||
} | ||
} | ||
_addOutlet(route) { | ||
@@ -80,3 +98,5 @@ this._outletChain.push(route); | ||
const padded = new Array(this._outletChain.length - mask.length).fill(false); | ||
padded.push(...mask); | ||
for (let i = mask.length - 1; i >= 0; i--) { | ||
padded.push(mask[i]); | ||
} | ||
this._maskChain = padded | ||
@@ -90,21 +110,3 @@ .map((x, i) => x === true ? | ||
} | ||
renderHeadHTML() { | ||
let out = ""; | ||
for (const elm of this.links) { | ||
out += "<link"; | ||
for (const attr in elm) { | ||
out += ` ${attr}="${elm[attr].replace(/"/g, "\\\"")}"`; | ||
} | ||
out += "></link>"; | ||
} | ||
for (const elm of this.meta) { | ||
out += "<meta"; | ||
for (const attr in elm) { | ||
out += ` ${attr}="${elm[attr].replace(/"/g, "\\\"")}"`; | ||
} | ||
out += "></meta>"; | ||
} | ||
return out; | ||
} | ||
} | ||
exports.RenderArgs = RenderArgs; |
@@ -98,2 +98,3 @@ "use strict"; | ||
if (path.length === 0) { | ||
override.push(false); | ||
this.route = new RouteLeaf(module, override); | ||
@@ -103,2 +104,3 @@ return; | ||
if (path.length === 1 && path[0] === "_index") { | ||
override.push(false); | ||
this.default = new RouteLeaf(module, override); | ||
@@ -260,3 +262,3 @@ return; | ||
if (matching) { | ||
depth = args._outletChain.length; | ||
depth = args._outletChain.length - 1; | ||
} | ||
@@ -263,0 +265,0 @@ args._applyMask(mask, depth); |
{ | ||
"name": "htmx-router", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A remix.js style file path router for htmX websites", | ||
@@ -5,0 +5,0 @@ "main": "./bin/index.js", |
25544
682