Comparing version 1.10.0 to 1.10.1
@@ -7,4 +7,7 @@ import { RegexReplaceCommand } from "../../RegexReplaceCommand.js"; | ||
* Replaces SSI's <!-- #echo var="someVar" --> by someVar's value. | ||
* | ||
* @see Context.setVar(varName, value) | ||
*/ | ||
export declare class SsiEchoVarReplaceCommand<V = any, C extends HtmlSsgContext<V> = HtmlSsgContext<V>> extends RegexReplaceCommand<V, HtmlSsgContext<V>> { | ||
protected varName: string; | ||
protected defaultHandlers: StringContextHandler[]; | ||
@@ -11,0 +14,0 @@ constructor(varName?: string, defaultHandlers?: StringContextHandler[]); |
@@ -5,11 +5,14 @@ import { RegexReplaceCommand } from "../../RegexReplaceCommand.js"; | ||
* Replaces SSI's <!-- #echo var="someVar" --> by someVar's value. | ||
* | ||
* @see Context.setVar(varName, value) | ||
*/ | ||
export class SsiEchoVarReplaceCommand extends RegexReplaceCommand { | ||
constructor(varName = "(.*?)", defaultHandlers = []) { | ||
constructor(varName = VarRegexReplacer.REGEXP_DEFAULT, defaultHandlers = []) { | ||
super(new RegExp(`<!--\\s*#echo\\s+var="${varName}"\\s*-->`, "gs")); | ||
this.varName = varName; | ||
this.defaultHandlers = defaultHandlers; | ||
} | ||
async createReplacer(context) { | ||
return new VarRegexReplacer(context, this.defaultHandlers); | ||
return new VarRegexReplacer(context, this.varName, this.defaultHandlers); | ||
} | ||
} |
@@ -5,3 +5,9 @@ import { RegexReplaceCommand } from "../RegexReplaceCommand.js"; | ||
import { SsgContext } from "../../../../SsgContext.js"; | ||
/** | ||
* Replaces ${varName} strings by the variable value. | ||
* | ||
* @see Context.setVar(varName, value) | ||
*/ | ||
export declare class StringEchoVarReplaceCommand<V = any, C extends SsgContext = SsgContext<V>> extends RegexReplaceCommand<V, C> { | ||
protected varName: string; | ||
protected defaultHandlers: StringContextHandler[]; | ||
@@ -8,0 +14,0 @@ constructor(varName?: string, defaultHandlers?: StringContextHandler[]); |
import { RegexReplaceCommand } from "../RegexReplaceCommand.js"; | ||
import { VarRegexReplacer } from "./VarRegexReplacer.js"; | ||
/** | ||
* Replaces ${varName} strings by the variable value. | ||
* | ||
* @see Context.setVar(varName, value) | ||
*/ | ||
export class StringEchoVarReplaceCommand extends RegexReplaceCommand { | ||
constructor(varName = "(.*?)", defaultHandlers = []) { | ||
constructor(varName = VarRegexReplacer.REGEXP_DEFAULT, defaultHandlers = []) { | ||
super(new RegExp(`\\$\{${varName}\}`, "gs")); | ||
this.varName = varName; | ||
this.defaultHandlers = defaultHandlers; | ||
} | ||
async createReplacer(context) { | ||
return new VarRegexReplacer(context, this.defaultHandlers); | ||
return new VarRegexReplacer(context, this.varName, this.defaultHandlers); | ||
} | ||
} |
@@ -6,5 +6,7 @@ import { RegexReplacer } from "../RegexReplacer.js"; | ||
protected context: C; | ||
protected varName: string; | ||
protected defaultHandlers: StringContextHandler<C>[]; | ||
constructor(context: C, defaultHandlers: StringContextHandler<C>[]); | ||
static readonly REGEXP_DEFAULT = "(.*?)"; | ||
constructor(context: C, varName?: string, defaultHandlers?: StringContextHandler<C>[]); | ||
replace(_match: string, ...args: any[]): string; | ||
} |
export class VarRegexReplacer { | ||
constructor(context, defaultHandlers) { | ||
constructor(context, varName = VarRegexReplacer.REGEXP_DEFAULT, defaultHandlers = []) { | ||
this.context = context; | ||
this.varName = varName; | ||
this.defaultHandlers = defaultHandlers; | ||
} | ||
replace(_match, ...args) { | ||
let varStr = this.context.getVar(args[0]); | ||
let varStr = this.context.getVar(this.varName === VarRegexReplacer.REGEXP_DEFAULT ? args[0] : this.varName); | ||
if (!varStr) { | ||
@@ -14,1 +15,2 @@ this.defaultHandlers.some(handle => !varStr && (varStr = handle(this.context))); | ||
} | ||
VarRegexReplacer.REGEXP_DEFAULT = "(.*?)"; |
@@ -5,3 +5,3 @@ { | ||
"author": "Jérôme Beau <javarome@gmail.com> (https://javarome.com)", | ||
"version": "1.10.0", | ||
"version": "1.10.1", | ||
"description": "Static Site Generation TypeScript API", | ||
@@ -24,3 +24,3 @@ "exports": "./dist/src/index.js", | ||
"test": "rm -Rf out && tsx src/testAll.ts", | ||
"test-one": "rm -Rf out && tsx src/step/content/replace/html/ssi/SsiEchoVarCommandTest.ts", | ||
"test-one": "rm -Rf out && tsx src/step/content/replace/html/StringEchoVarReplaceCommandTest.ts", | ||
"test-ci": "rm -Rf out && tsx src/testAll.ts" | ||
@@ -27,0 +27,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135755
2096