From 41aa67c402d72611663ceddad9c3f9729da6a35b Mon Sep 17 00:00:00 2001 From: Arnaud Freismuth Date: Fri, 23 Aug 2024 11:27:18 +0200 Subject: [PATCH] Expose code raw --- package-lock.json | 4 ++-- package.json | 2 +- src/filters/Documentation.ts | 2 +- src/filters/component-doc.ts | 4 +++- src/filters/doc-utils.ts | 2 +- src/filters/documentation-templates.ts | 2 ++ src/filters/template-doc.ts | 4 +++- test/CommandLine.spec.ts | 10 +++++----- test/faketikui-self/part/code.pug | 4 ++-- test/filters/DocumentationTemplates.spec.ts | 2 +- 10 files changed, 21 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3839529..3494f98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tikui/core", - "version": "6.1.1", + "version": "6.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@tikui/core", - "version": "6.1.1", + "version": "6.2.0", "license": "MIT", "dependencies": { "@johnsoncodehk/html2pug": "1.0.0", diff --git a/package.json b/package.json index 65e24be..bf947c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tikui/core", - "version": "6.1.1", + "version": "6.2.0", "description": "Tikui core", "main": "src/tikui.js", "scripts": { diff --git a/src/filters/Documentation.ts b/src/filters/Documentation.ts index c251492..0dad7af 100644 --- a/src/filters/Documentation.ts +++ b/src/filters/Documentation.ts @@ -1,4 +1,4 @@ -export type Code = (escaped: string, escapedPug: string) => string; +export type Code = (escaped: string, escapedPug: string, htmlRaw: string, pugRaw: string) => string; export type Render = (src: string) => string; export type Markdown = () => string; diff --git a/src/filters/component-doc.ts b/src/filters/component-doc.ts index 4542170..0ac7fe4 100644 --- a/src/filters/component-doc.ts +++ b/src/filters/component-doc.ts @@ -2,9 +2,11 @@ import { docUtils } from './doc-utils'; import { ComponentOptions, Render, Code } from './Documentation'; import * as documentationTemplates from './documentation-templates'; -const templateCode: Code = (escaped, escapedPug): string => documentationTemplates.code({ +const templateCode: Code = (escaped, escapedPug, htmlRaw, pugRaw): string => documentationTemplates.code({ htmlCode: escaped, pugCode: escapedPug, + htmlRaw, + pugRaw, }); const render = (height: string): Render => (src) => documentationTemplates.componentRender({ diff --git a/src/filters/doc-utils.ts b/src/filters/doc-utils.ts index 595d73a..d070c0e 100644 --- a/src/filters/doc-utils.ts +++ b/src/filters/doc-utils.ts @@ -20,7 +20,7 @@ const getCode = (filename: string) => (code: Code): string => { const renderedPug = htmlToPug(rendered); const escapedPug = escapeHtml(renderedPug); - return code(escaped, escapedPug); + return code(escaped, escapedPug, rendered, renderedPug); }; const getRender = (filename: string) => (template: Render): string => { diff --git a/src/filters/documentation-templates.ts b/src/filters/documentation-templates.ts index 245266c..1300f74 100644 --- a/src/filters/documentation-templates.ts +++ b/src/filters/documentation-templates.ts @@ -26,6 +26,8 @@ interface TemplateRenderVariables { interface CodeVariables { htmlCode: string; pugCode: string; + htmlRaw: string; + pugRaw: string; } type Component = (variables: ComponentVariables) => string; diff --git a/src/filters/template-doc.ts b/src/filters/template-doc.ts index 5953b7b..3b907f4 100644 --- a/src/filters/template-doc.ts +++ b/src/filters/template-doc.ts @@ -2,9 +2,11 @@ import { docUtils } from './doc-utils'; import { Render, Code, TemplateOptions } from './Documentation'; import * as documentationTemplates from './documentation-templates'; -const code: Code = (escaped, escapedPug) => documentationTemplates.code({ +const code: Code = (escaped, escapedPug, htmlRaw, pugRaw) => documentationTemplates.code({ htmlCode: escaped, pugCode: escapedPug, + htmlRaw, + pugRaw, }); const render: Render = (src) => documentationTemplates.templateRender({ diff --git a/test/CommandLine.spec.ts b/test/CommandLine.spec.ts index 8f51a47..17a8f01 100644 --- a/test/CommandLine.spec.ts +++ b/test/CommandLine.spec.ts @@ -192,19 +192,19 @@ describe('Command line usage', () => { const expectExistsFile = expectExistingPath(faketikuiSelf.dist); const stringContent = stringContaining(faketikuiSelf.dist); - const out = buildTikui(faketikuiSelf); + buildTikui(faketikuiSelf); expectExistsFile('index.html'); expectExistsFile('tikui.css'); const indexContent = stringContent('index.html'); - expect(indexContent).toMatch(/
[^]*
[^]*
[^]*component-class[^]*<\/div>/); - expect(indexContent).toMatch(/
[^]*
[^]*
[^]*\.component-class[^]*<\/div>/); + expect(indexContent).toMatch(/
[^]*
[^]*
[^]*component-class[^]*<\/div>/); + expect(indexContent).toMatch(/
[^]*
[^]*
[^]*\.component-class[^]*<\/div>/); expect(indexContent).toMatch(/
[^]*Component Markdown<\/h2>[^]*<\/div>/); expect(indexContent).toMatch(/
[^]*