@@ -11,18 +11,20 @@ import { Edge } from 'edge.js'
1111import { debug } from '#src/debug'
1212import { Config } from '@athenna/config'
1313import { resolve , isAbsolute } from 'node:path'
14- import { Is , File , Path } from '@athenna/common'
14+ import type { TagContract } from '#src/types/TagContract'
15+ import { Is , File , Path , Macroable } from '@athenna/common'
1516import { EmptyComponentException } from '#src/exceptions/EmptyComponentException'
1617import { NotFoundComponentException } from '#src/exceptions/NotFoundComponentException'
1718import { AlreadyExistComponentException } from '#src/exceptions/AlreadyExistComponentException'
1819
19- export class ViewImpl {
20+ export class ViewImpl extends Macroable {
2021 /**
2122 * Edge instance that is handling all the views.
2223 */
2324 public edge : Edge
2425
2526 public constructor ( ) {
27+ super ( )
2628 this . edge = Edge . create ( Config . get ( 'view.edge' , { } ) )
2729 }
2830
@@ -152,6 +154,54 @@ export class ViewImpl {
152154 return this
153155 }
154156
157+ /**
158+ * Add a new tag to templates. Just like @component
159+ * @if , etc.
160+ *
161+ * @example
162+ * ```ts
163+ * import type { TagContract } from '@athenna/view'
164+ *
165+ * const reverseTagOptions: TagContract = {
166+ * block: false,
167+ * seekable: true,
168+ * compile(parser, buffer, token) {
169+ * buffer.outputRaw('Hello from reverse tag')
170+ * }
171+ * }
172+ *
173+ * View.addTag('reverse', reverseTagOptions)
174+ *
175+ * const output = await View.renderRaw('@reverse()') // 'Hello from reverse tag'
176+ * ```
177+ */
178+ public addTag ( name : string , options : TagContract ) {
179+ this . edge . registerTag ( { tagName : name , ...options } )
180+
181+ return this
182+ }
183+
184+ /**
185+ * Remove some tag from views registered using
186+ * "addTag" method.
187+ *
188+ * @example
189+ * ```ts
190+ * View
191+ * .addTag('reverse', { ... })
192+ * .removeTag('reverse')
193+ * ```
194+ */
195+ public removeTag ( name : string ) {
196+ if ( ! this . edge . tags [ name ] ) {
197+ return this
198+ }
199+
200+ delete this . edge . tags [ name ]
201+
202+ return this
203+ }
204+
155205 /**
156206 * Create a new view disk. View disks can be used
157207 * to register multiple views at the same time.
0 commit comments