Skip to content

Commit 7768ea2

Browse files
authored
Merge pull request #15 from osspkg/dev
[core@0.2.1] fix work with links
2 parents 4569686 + 146abe5 commit 7768ea2

File tree

14 files changed

+174
-195
lines changed

14 files changed

+174
-195
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ testem.log
3636
# System files
3737
.DS_Store
3838
Thumbs.db
39+
40+
/apigen/*.mjs

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18.18.0
1+
v20.14.0

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ lint:
1818
yarn run apigen
1919
yarn run lint
2020

21-
build: lint
21+
build: build_icons build_styles build_core build_kit
2222
yarn run build
2323

2424
prerender:
25-
jasta prerender --config=development/dev/config.yaml
25+
/home/user/.gvm/.cache/modules/bin/jasta prerender --config=development/dev/config.yaml
2626

27-
deploy: build prerender
27+
deploy: lint build prerender
2828
scp -r dist/website/* root@$(value STATIC_HOST):/home/onegaui/www/
2929
scp development/prod/jasta.yaml root@$(value STATIC_HOST):/etc/jasta/websites/onega-ui.yaml
3030
ssh root@$(value STATIC_HOST) 'systemctl restart jasta'

apigen/index.mts

Lines changed: 83 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import {readdirSync, writeFileSync} from "node:fs";
2-
import path from "node:path";
3-
import {readFileSync} from "fs";
1+
import {readFileSync} from 'fs';
2+
import {readdirSync, writeFileSync} from 'node:fs';
3+
import path from 'node:path';
44

55
function readAllFiles(dir: string, ext: string): string[] {
6-
const out: string[] = []
7-
const files = readdirSync(dir, {withFileTypes: true, recursive: true})
6+
const out = new Set<string>();
7+
const files = readdirSync(dir, {withFileTypes: true, recursive: true});
88
files.forEach(file => {
99
if (file.isFile() && path.extname(file.name) === ext) {
10-
out.push(path.join(dir, file.name))
11-
return
10+
out.add(path.join(file.path || dir, file.name));
11+
return;
1212
}
1313
if (file.isDirectory()) {
14-
out.push(...readAllFiles(path.join(dir, file.name), ext))
15-
return
14+
readAllFiles(path.join(dir, file.name), ext).forEach(v => out.add(v))
15+
return;
1616
}
17-
})
18-
return out
17+
});
18+
return Array.from(out).slice();
1919
}
2020

2121
interface TagProp {
@@ -34,7 +34,7 @@ interface Tag {
3434
}
3535

3636
function extractTags(data: string): Tag {
37-
const out: Tag = {name: '', code: '', desc: '', group: '', html: '', other: '', props: []}
37+
const out: Tag = {name: '', code: '', desc: '', group: '', html: '', other: '', props: []};
3838

3939
const rexName = /@name(.*?)$/gms;
4040
const rexGroup = /@group(.*?)$/gms;
@@ -45,38 +45,38 @@ function extractTags(data: string): Tag {
4545
const rexOther = /@other(.*?)[@*]/gms;
4646

4747
for (const item of data.matchAll(rexName)) {
48-
out.name = item[1].trim()
48+
out.name = item[1].trim();
4949
}
5050
for (const item of data.matchAll(rexGroup)) {
51-
out.group = item[1].trim()
51+
out.group = item[1].trim();
5252
}
5353
for (const item of data.matchAll(rexDesc)) {
54-
out.desc = item[1].trim()
54+
out.desc = item[1].trim();
5555
}
5656
for (const item of data.matchAll(rexHtml)) {
57-
out.html = item[1].trimEnd()
57+
out.html = item[1].trimEnd();
5858
}
5959
for (const item of data.matchAll(rexCode)) {
60-
out.code = item[1].trimEnd()
60+
out.code = item[1].trimEnd();
6161
}
6262
for (const item of data.matchAll(rexOther)) {
63-
out.other = item[1].trimEnd()
63+
out.other = item[1].trimEnd();
6464
}
6565
for (const item of data.matchAll(rexProp)) {
66-
out.props.push({key: item[1].trim(), value: item[2].trim()})
66+
out.props.push({key: item[1].trim(), value: item[2].trim()});
6767
}
6868

69-
return out
69+
return out;
7070
}
7171

7272
function extractComment(file: string): Tag[] {
73-
const out: Tag[] = []
74-
const buf = readFileSync(file).toString()
73+
const out: Tag[] = [];
74+
const buf = readFileSync(file).toString();
7575
const rex = /\/\*(.*?)\*\//sg;
76-
for (let item of buf.matchAll(rex)) {
77-
out.push(extractTags(item[0]))
76+
for (const item of buf.matchAll(rex)) {
77+
out.push(extractTags(item[0]));
7878
}
79-
return out
79+
return out;
8080
}
8181

8282
interface DocTemplate {
@@ -85,43 +85,43 @@ interface DocTemplate {
8585
filename: string
8686
}
8787

88-
function escapeHTML(data: string): string{
88+
function escapeHTML(data: string): string {
8989
return data
90-
.replaceAll('<','&lt;')
91-
.replaceAll('>','&gt;')
92-
.replaceAll('{','&#123;')
93-
.replaceAll('}','&#125;')
90+
.replaceAll('<', '&lt;')
91+
.replaceAll('>', '&gt;')
92+
.replaceAll('{', '&#123;')
93+
.replaceAll('}', '&#125;');
9494
}
9595

9696
function docTemplate(name: string, mod: string, data: Tag[]): DocTemplate {
97-
const selector = `${mod.toLowerCase()}-${name.toLowerCase().replaceAll(' ', '-')}`
98-
const modName = mod.split(' ').map(value => value[0].toUpperCase() + value.substring(1)).join('')
99-
const className = modName + name.split(' ').map(value => value[0].toUpperCase() + value.substring(1)).join('')
97+
const selector = `${mod.toLowerCase()}-${name.toLowerCase().replaceAll(' ', '-')}`;
98+
const modName = mod.split(' ').map(value => value[0].toUpperCase() + value.substring(1)).join('');
99+
const className = modName + name.split(' ').map(value => value[0].toUpperCase() + value.substring(1)).join('');
100100

101-
const other: string[] = []
102-
let view: string = `\n`;
101+
const other: string[] = [];
102+
let view = '\n';
103103

104104
data.forEach(tag => {
105-
other.push(tag.other)
106-
view += `<h4 class="bq bq-warning demo-name">${tag.name}</h4>\n`
107-
view += `<p class="demo-desc">${tag.desc}</p>\n`
105+
other.push(tag.other);
106+
view += `<h4 class="bq bq-warning demo-name">${tag.name}</h4>\n`;
107+
view += `<p class="demo-desc">${tag.desc}</p>\n`;
108108
if (tag.html.length > 0) {
109-
view += `<div class="demo-view w-full">${tag.html}</div>\n`
110-
view += `<pre class="demo-html w-full">${escapeHTML(tag.html)}</pre>\n`
109+
view += `<div class="demo-view w-full">${tag.html}</div>\n`;
110+
view += `<pre class="demo-html w-full">${escapeHTML(tag.html)}</pre>\n`;
111111
}
112112
if (tag.code.length > 0) {
113-
view += `<pre class="demo-code w-full">${tag.code}</pre>\n`
113+
view += `<pre class="demo-code w-full">${tag.code}</pre>\n`;
114114
}
115-
if (tag.props.length>0){
116-
view += `<table class="demo-attr">\n`
115+
if (tag.props.length > 0) {
116+
view += '<table class="demo-attr">\n';
117117
tag.props.forEach(value => {
118118
view += `<tr><td class="t-wrap-line" style="width: 30%;"><b>${value.key}</b></td>
119-
<td class="t-wrap-line">${value.value}</td></tr>`
120-
})
121-
view += `</table>\n`
119+
<td class="t-wrap-line">${value.value}</td></tr>`;
120+
});
121+
view += '</table>\n';
122122
}
123-
view += `<div class="demo-end">&nbsp;</div>\n`
124-
})
123+
view += '<div class="demo-end">&nbsp;</div>\n';
124+
});
125125

126126
return {
127127
data: `import { Component } from '@angular/core';
@@ -137,7 +137,7 @@ export class ${className} {
137137
}`,
138138
filename: selector,
139139
class: className,
140-
}
140+
};
141141
}
142142

143143
interface ModuleTemplate {
@@ -151,15 +151,16 @@ function moduleTemplate(mod: string, data: ModuleTemplate[]): string {
151151
const links: string[] = [];
152152
const declarations: string[] = [];
153153

154-
const modName = mod.split(' ').map(value => value[0].toUpperCase() + value.substring(1)).join('')
154+
const modName = mod.split(' ').map(value => value[0].toUpperCase() + value.substring(1)).join('');
155155

156156
data.forEach(value => {
157-
imports.push(`import { ${value.class} } from './${value.filename}';`)
158-
links.push(`{ link: '${value.title}', component: ${value.class} },`)
159-
declarations.push(`${value.class},`)
160-
})
157+
imports.push(`import { ${value.class} } from './${value.filename}';`);
158+
links.push(`{ link: '${value.title}', component: ${value.class} },`);
159+
declarations.push(`${value.class},`);
160+
});
161161

162162
return `import { NgModule } from '@angular/core';
163+
import { CoreModule } from '../../../../../core/src/lib/core.module';
163164
import { KitModule } from '../../../../../kit/src/lib/kit.module';
164165
import { ApiLink } from '../../root/api.models';
165166
${imports.join('\n')}
@@ -176,47 +177,52 @@ export function links(): ApiLink[] {
176177
],
177178
imports: [
178179
KitModule,
180+
CoreModule,
179181
],
180182
})
181183
export class ${modName}Module { }
182-
`
184+
`;
183185
}
184186

185-
function parse(dir: string, ext: string, mod: string, out: string): void {
187+
function parse(ext: string, mod: string, out: string, dirs: string[]): void {
186188
const tags: Tag[] = [];
187-
const files = readAllFiles(dir, ext)
188-
files.forEach(file => {
189-
tags.push(...extractComment(file))
189+
dirs.forEach(dir =>{
190+
const files = readAllFiles(dir, ext);
191+
files.forEach(file => {
192+
tags.push(...extractComment(file));
193+
});
190194
})
191195

192-
const _groups = new Map<string, string>();
193-
const groups : string[] = []
194-
tags.forEach(value => _groups.set(value.group, value.group))
195-
for (let group of _groups.keys()) {
196-
groups.push(group)
196+
const tmpGroups = new Map<string, string>();
197+
const groups: string[] = [];
198+
tags.forEach(value => tmpGroups.set(value.group, value.group));
199+
for (const group of tmpGroups.keys()) {
200+
groups.push(group);
197201
}
198-
groups.sort()
202+
groups.sort();
199203

200-
const module: ModuleTemplate[] = []
204+
const module: ModuleTemplate[] = [];
201205

202206
groups.forEach(group => {
203-
const list = tags.filter(value => value.group === group)
204-
const doc = docTemplate(group, mod, list)
205-
module.push({filename: doc.filename, class: doc.class, title: group})
207+
const list = tags.filter(value => value.group === group);
208+
const doc = docTemplate(group, mod, list);
209+
module.push({filename: doc.filename, class: doc.class, title: group});
206210

207211
writeFileSync(
208212
path.join(out, doc.filename + '.ts'),
209213
doc.data,
210-
{encoding: "utf-8"},
211-
)
212-
})
214+
{encoding: 'utf-8'},
215+
);
216+
});
213217

214218
writeFileSync(
215-
path.join(out, `module.ts`),
219+
path.join(out, 'module.ts'),
216220
moduleTemplate(mod, module),
217-
{encoding: "utf-8"},
218-
)
221+
{encoding: 'utf-8'},
222+
);
219223
}
220224

221-
parse('projects/styles/src/', '.scss', 'style', 'projects/website/src/pages/styles/models')
222-
parse('projects/kit/src/lib/', '.ts', 'comp', 'projects/website/src/pages/kit/models')
225+
parse('.scss', 'style', 'projects/website/src/pages/styles/models',
226+
['projects/styles/src/']);
227+
parse('.ts', 'comp', 'projects/website/src/pages/kit/models',
228+
['projects/kit/src/lib/', 'projects/core/src/lib/']);

apigen/tsconfig.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
{
2-
"extends": "ts-node/node16/tsconfig.json",
32
"compilerOptions": {
4-
5-
},
6-
"ts-node": {
7-
"esm": true,
8-
"compilerOptions": {
9-
"types": ["node"],
10-
"target": "ES2022",
11-
"module": "ES2022",
12-
"moduleResolution": "Node"
13-
}
3+
"module": "ESNext",
4+
"moduleResolution": "NodeNext",
5+
"target": "ES2022",
6+
"lib": [
7+
"ES2022",
8+
"dom"
9+
],
10+
"allowSyntheticDefaultImports": true
1411
}
1512
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"styles:css": "sass projects/styles/src/_index.scss dist/styles/styles.css --style compressed --no-source-map",
2222
"styles:themes": "sass projects/styles/src/themes:dist/styles/themes --style compressed --no-source-map",
2323
"styles": "yarn run styles:scss && yarn run styles:css && yarn run styles:themes",
24-
"apigen": "ts-node --project apigen/tsconfig.json apigen/index.mts"
24+
"apigen": "tsc --project apigen/tsconfig.json && node apigen/index.mjs"
2525
},
2626
"dependencies": {
2727
"@angular/animations": "^16.0.0",
@@ -53,7 +53,6 @@
5353
"eslint-plugin-import": "^2.0.0",
5454
"fs.notify": "^0.0.4",
5555
"ng-packagr": "^16.2.2",
56-
"ts-node": "^10.9.2",
5756
"typescript": "~5.1.0",
5857
"webfont": "^11.2.26"
5958
}

projects/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onega-ui/core",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Core library for creating Angular components and applications using Onega UI",
55
"author": "OSSPkg Team <github@osspkg.com> (https://github.com/osspkg)",
66
"maintainers": [

projects/core/src/lib/directives/active-route.directive.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Directive, ElementRef, Input, OnInit } from '@angular/core';
1+
import { AfterViewInit, Directive, ElementRef, Input } from '@angular/core';
22

33
@Directive({
44
selector: 'a[ong-active-route]',
55
})
6-
export class ActiveRouteDirective implements OnInit {
6+
export class ActiveRouteDirective implements AfterViewInit {
77
@Input({ alias: 'ong-active-route' }) classes!: string | string[];
88

99
constructor(
@@ -25,13 +25,30 @@ export class ActiveRouteDirective implements OnInit {
2525
}
2626
}
2727

28-
ngOnInit() {
28+
ngAfterViewInit() {
2929
const curr = new URL(location.href).pathname.substring(1);
30-
const link = new URL(this.ref.nativeElement.href).pathname.substring(1);
30+
if (
31+
this.ref.nativeElement?.href === null ||
32+
this.ref.nativeElement?.href === undefined ||
33+
this.ref.nativeElement?.href.length === 0
34+
) {
35+
console.warn('[ong-active-route]: href not found');
36+
return;
37+
}
38+
const link = new URL(this.ref.nativeElement?.href).pathname.substring(1);
3139
let isActive = curr.startsWith(link);
3240
if (link.length === 0) {
3341
isActive = curr.length === 0;
3442
}
3543
this.applyClass(isActive);
3644
}
3745
}
46+
47+
/*
48+
@name Active Route
49+
@group Links
50+
@prop [ong-active-route] := Adding a class if the link matches the current route or starts with it.
51+
@html
52+
<a href="/" [ong-active-route]="['btn']">HOME</a>
53+
<a href="/kit" [ong-active-route]="['btn']">KIT</a>
54+
*/

0 commit comments

Comments
 (0)