Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Nov 11, 2023
1 parent d0ce165 commit 349c1a1
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 78 deletions.
12 changes: 10 additions & 2 deletions packages/cache/docs/demo/simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ order: 0
Simplest of usage.

```ts
import { JsonPipe } from '@angular/common';
import { Component, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';

import { CacheService } from '@delon/cache';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzMessageService } from 'ng-zorro-antd/message';
import { Subscription } from 'rxjs';

@Component({
selector: 'app-demo',
Expand All @@ -40,6 +43,8 @@ import { Subscription } from 'rxjs';
<button nz-button (click)="unRegisterNotify()">UnRegister</button>
</div>
`,
standalone: true,
imports: [JsonPipe, NzButtonModule]
})
export class DemoComponent implements OnDestroy {
value: any;
Expand All @@ -50,7 +55,10 @@ export class DemoComponent implements OnDestroy {
return +new Date();
}

constructor(public srv: CacheService, private msg: NzMessageService) {}
constructor(
public srv: CacheService,
private msg: NzMessageService
) {}

getByHttp(): void {
this.srv.get(`https://randomuser.me/api/?results=1`).subscribe(res => {
Expand Down
1 change: 1 addition & 0 deletions packages/util/pipes/currency/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: currency
subtitle: Currency Pipes
type: Pipes
module: import { CurrencyPipeModule } from '@delon/util/pipes/currency';
standalone: true
---

> You can override to set the `startingUnit`, `megaUnit`, `precision`, `ingoreZeroPrecision` through [Global Configuration](/docs/global-config).
Expand Down
1 change: 1 addition & 0 deletions packages/util/pipes/currency/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: currency
subtitle: 货币管道
type: Pipes
module: import { CurrencyPipeModule } from '@delon/util/pipes/currency';
standalone: true
---

> 可以通过[全局配置](/docs/global-config)覆盖 `startingUnit``megaUnit``precision``ingoreZeroPrecision` 等参数。
Expand Down
1 change: 1 addition & 0 deletions packages/util/pipes/filter/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: filter
subtitle: Filter
type: Pipes
module: import { FilterPipeModule } from '@delon/util/pipes/filter';
standalone: true
---

## filter
Expand Down
1 change: 1 addition & 0 deletions packages/util/pipes/filter/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: filter
subtitle: 过滤数组
type: Pipes
module: import { FilterPipeModule } from '@delon/util/pipes/filter';
standalone: true
---

## filter
Expand Down
1 change: 1 addition & 0 deletions packages/util/pipes/format/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: format
subtitle: Mask
type: Pipes
module: import { FormatPipeModule } from '@delon/util/pipes/format';
standalone: true
---

## mask
Expand Down
1 change: 1 addition & 0 deletions packages/util/pipes/format/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: format
subtitle: 掩码
type: Pipes
module: import { FormatPipeModule } from '@delon/util/pipes/format';
standalone: true
---

## mask
Expand Down
30 changes: 23 additions & 7 deletions scripts/site/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';

import {
ContentTemplateData,
DemoData,
ExampleModules,
Meta,
MetaOriginal,
Expand Down Expand Up @@ -83,7 +84,7 @@ function generateModule(config: ModuleConfig): void {
});
}

function fixDemo(fileObject: any, demos: any): void {
function fixDemo(fileObject: any, demos: DemoData): void {
const demoHTML: string[] = [];
demoHTML.push(`<div nz-row [nzGutter]="16">`);
if (demos.tpl.left.length > 0 && demos.tpl.right.length > 0) {
Expand Down Expand Up @@ -174,9 +175,9 @@ function generateModule(config: ModuleConfig): void {
// #endregion

// #region generate document file
const demoList = demos.data.filter((w: { type: string }) => w.type !== 'example');
const demoList = demos.data.filter(w => w.type !== 'example');
const isDemo = demoList.length > 0;
const isExample = demos.data.filter((w: { type: string }) => w.type === 'example').length > 0;
const isExample = demos.data.filter(w => w.type === 'example').length > 0;
const fileObject: ContentTemplateData = {
componentName: genComponentName(config.name, meta.name),
selector: genSelector(config.name, meta.name),
Expand All @@ -188,8 +189,21 @@ function generateModule(config: ModuleConfig): void {
// i18n: meta.i18n,
} as any,
demos: '',
demo: isDemo
demo: isDemo,
imports: '',
standaloneImports: ''
};
const standaloneDemo = config.standalone && demoList.length > 0;
if (standaloneDemo) {
fileObject.imports = demoList
.map(v => `import { ${v.componentName} } from './${v.name}';`)
.concat(`import { NzGridModule } from 'ng-zorro-antd/grid';`)
.join('\n');
fileObject.standaloneImports = `,${demoList
.map(v => v.componentName)
.concat('NzGridModule')
.join(', ')}`;
}
if (fileObject.demo) {
fixDemo(fileObject, demos);
} else if (isExample) {
Expand All @@ -205,9 +219,11 @@ function generateModule(config: ModuleConfig): void {
// #region register module
appendToModule(fileObject.componentName, meta.name, 'index');
// demo
demoList.forEach((demo: { componentName: string; name: string }) => {
appendToModule(demo.componentName, meta.name, demo.name, false);
});
if (!standaloneDemo) {
demoList.forEach((demo: { componentName: string; name: string }) => {
appendToModule(demo.componentName, meta.name, demo.name, false);
});
}
// #endregion
});
});
Expand Down
27 changes: 27 additions & 0 deletions scripts/site/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export interface ContentTemplateData {
demos?: string;
/** */
codes?: string;
imports?: string;
/** standalone 的导入列表 */
standaloneImports?: string;
}

export interface ModuleTemplateData {
Expand All @@ -123,3 +126,27 @@ export interface ExampleModules {
list: any[];
[key: string]: any;
}

export interface DemoData {
tpl: { left: string[]; right: string[] };
data: DemoDataItem[];
}

export interface MTData {
name: string;
filePath: string;
[key: string]: any;
}

export interface DemoDataItem {
id: string;
meta: any;
summary: string | any;
code: string;
lang: string;
componentName: string;
name: string;
urls: string;
type: 'demo' | 'example';
point: number;
}
15 changes: 9 additions & 6 deletions scripts/site/utils/generate-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'path';

import { toHtml } from './generate-md';
import { getCode, genUpperName, genUrl, generateDoc } from './utils';
import { ModuleConfig, SiteConfig } from '../interfaces';
import { DemoData, DemoDataItem, MTData, ModuleConfig, SiteConfig } from '../interfaces';

const JsonML = require('jsonml.js/lib/utils');
const MT = require('mark-twain');
Expand Down Expand Up @@ -33,11 +33,11 @@ export function generateDemo(
cols: number,
config: ModuleConfig,
siteConfig: SiteConfig
): any {
): DemoData {
if (!exampleIndexTpl) {
exampleIndexTpl = fs.readFileSync(path.join(rootDir, siteConfig.template.examples_index)).toString('utf8');
}
const ret: { tpl: { left: string[]; right: string[] }; data: any[] } = {
const ret: DemoData = {
tpl: {
left: [],
right: []
Expand All @@ -47,7 +47,7 @@ export function generateDemo(

if (!fse.pathExistsSync(dir)) return ret;

const demos: any[] = fse.readdirSync(dir).map(name => {
const demos: MTData[] = fse.readdirSync(dir).map(name => {
const filePath = path.join(dir, name);
let mt: any = null;
try {
Expand All @@ -67,11 +67,14 @@ export function generateDemo(
demos
.sort((a: any, b: any) => a.meta.order - b.meta.order)
.forEach((markdownData: any, index: number) => {
const item: any = {
const item: DemoDataItem = {
id: `${config.name}-${key}-${markdownData.name}`,
meta: markdownData.meta,
summary: ``,
code: ``,
lang: '',
componentName: '',
point: 0,
name: markdownData.name,
urls: genUrl(rootDir, markdownData.filePath),
type: markdownData.meta.type || 'demo'
Expand Down Expand Up @@ -143,7 +146,7 @@ export function generateDemo(
const pos = isTwo ? (index % 2 === 0 ? 'left' : 'right') : 'left';
ret.tpl[pos].push(`
<code-box [item]="codes[${point}]" [attr.id]="codes[${point}].id">
<${item.id}></${item.id}>
<${item.id} />
</code-box>
`);
item.point = point;
Expand Down
4 changes: 2 additions & 2 deletions src/app/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const routes: Routes = [
{ path: 'theme', loadChildren: () => import('./gen/theme/theme.module').then(m => m.ThemeModule) },
{ path: 'auth', loadChildren: () => import('./gen/auth/routes').then(m => m.routes) },
{ path: 'acl', loadChildren: () => import('./gen/acl/routes').then(m => m.routes) },
{ path: 'cache', loadChildren: () => import('./gen/cache/cache.module').then(m => m.CacheModule) },
{ path: 'cache', loadChildren: () => import('./gen/cache/routes').then(m => m.routes) },
{ path: 'mock', loadChildren: () => import('./gen/mock/routes').then(m => m.routes) },
{ path: 'util', loadChildren: () => import('./gen/util/util.module').then(m => m.UtilModule) },
{ path: 'util', loadChildren: () => import('./gen/util/routes').then(m => m.routes) },
{ path: 'chart', loadChildren: () => import('./gen/chart/chart.module').then(m => m.ChartModule) },
{ path: 'form', loadChildren: () => import('./gen/form/form.module').then(m => m.FormModule) },
{
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './route-transfer/route-transfer.directive';
export * from './code-box/code-box.component';
export * from './edit-button/edit-button.component';
export * from './docs/docs.component';
export * from './content/content.component';
1 change: 1 addition & 0 deletions src/app/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './components/index';
export * from './shared.module';
101 changes: 60 additions & 41 deletions src/dev/demo.component.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,71 @@
import { Component, ViewChild } from '@angular/core';
import { JsonPipe } from '@angular/common';
import { Component, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';

import { STColumn, STComponent, STModule } from '@delon/abc/st';
import { CacheService } from '@delon/cache';
import { NzButtonModule } from 'ng-zorro-antd/button';

interface User {
id: number;
picture: {
thumbnail: string;
};
name: {
last: string;
first: string;
};
nat: string;
gender: string;
email: string;
phone: string;
price: number;
registered: Date;
}
import { NzMessageService } from 'ng-zorro-antd/message';

@Component({
selector: 'app-demo',
template: `
<button nz-button nzType="primary" (click)="setRow()">setRow Method</button>
<st #st [widthMode]="{ type: 'strict' }" [data]="url" [req]="{ params: params }" [columns]="columns" />
<p>value: {{ value | json }}</p>
<div class="pt-sm">
Basic:
<button nz-button (click)="srv.set(key, newValue)">Set</button>
<button nz-button (click)="value = srv.getNone(key)">Get</button>
<button nz-button (click)="srv.remove(key)">Remove</button>
<button nz-button (click)="srv.clear()">Clear</button>
</div>
<div class="pt-sm">
Key is valid request:
<button nz-button (click)="getByHttp()">Get</button>
</div>
<div class="pt-sm">
Notify:
<button nz-button (click)="registerNotify()">Register</button>
<button nz-button (click)="unRegisterNotify()">UnRegister</button>
</div>
`,
standalone: true,
imports: [STModule, NzButtonModule]
imports: [JsonPipe, NzButtonModule]
})
export class DemoComponent {
url = `/users?total=2&field=list`;
params = { a: 1, b: 2 };
@ViewChild('st', { static: false }) private st!: STComponent;
columns: Array<STColumn<User>> = [
{ title: '编号', index: 'id', width: 80 },
{ title: '头像', index: 'picture.thumbnail', type: 'img', width: 60 },
{ title: '邮箱', index: 'email', width: 80 },
{ title: '电话', index: 'phone' },
{
title: { text: '佣金', optional: '(单位:元)', optionalHelp: '计算公式=订单金额 * 0.6%' },
index: 'price',
type: 'currency'
},
{ title: '注册时间', type: 'date', index: 'registered' }
];

setRow(): void {
this.st.setRow(0, { price: 100000000 });
export class DemoComponent implements OnDestroy {
value: any;
key = 'demo';
private notify$?: Subscription;

get newValue(): number {
return +new Date();
}

constructor(
public srv: CacheService,
private msg: NzMessageService
) {}

getByHttp(): void {
this.srv.get(`https://randomuser.me/api/?results=1`).subscribe(res => {
this.value = res;
});
}

registerNotify(): void {
if (this.notify$) this.notify$.unsubscribe();
this.notify$ = this.srv.notify(this.key).subscribe(res => {
if (res == null) {
this.msg.success('register success');
return;
}
this.msg.warning(`"${this.key}" new status: ${res.type}`);
});
}

unRegisterNotify(): void {
this.srv.cancelNotify(this.key);
}

ngOnDestroy(): void {
if (this.notify$) this.notify$.unsubscribe();
}
}
Loading

0 comments on commit 349c1a1

Please sign in to comment.