Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(npm): update dependencies #35

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions configurer/view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

import { Env } from '@athenna/config'
import { Path } from '@athenna/common'
import { Env, Config } from '@athenna/config'

export default {
/*
Expand All @@ -24,6 +24,7 @@ export default {
| ```typescript
| // Render the Path.views('home.edge') file
| View.render('home')
|
| // Render the Path.views('pages/posts/post.edge') file
| View.render('pages/posts/post')
| ```
Expand All @@ -50,21 +51,33 @@ export default {

/*
|--------------------------------------------------------------------------
| View components
| In memory view components
|--------------------------------------------------------------------------
|
| Here you may define your in-memory components. Components works exactly
| like the `disk` to be rendered, the only difference is that they are
| saved in-memory.
|
| ```typescript
| View.render('button', { content: 'Login' })
| ```
| like any other view, the only difference is that they are saved in-memory
| instead of reloading the view file every-time.
|
*/

components: {},

/*
|--------------------------------------------------------------------------
| Shared global properties
|--------------------------------------------------------------------------
|
| Here you may define the properties you want to be available between all
| your views. By default, we have already set the `env` and `config`
| helpers for you.
|
*/

properties: {
env: Env,
config: Config
},

/*
|--------------------------------------------------------------------------
| Edge options
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/view",
"version": "4.18.1",
"version": "4.19.0",
"description": "The Athenna template engine. Built on top of Edge.js.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
9 changes: 5 additions & 4 deletions src/providers/ViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
* file that was distributed with this source code.
*/

import { Env, Config } from '@athenna/config'
import { Config } from '@athenna/config'
import { ViewImpl } from '#src/views/ViewImpl'
import { ServiceProvider } from '@athenna/ioc'

export class ViewProvider extends ServiceProvider {
public register() {
const view = new ViewImpl()

view.addProperty('Env', Env)
view.addProperty('Config', Config)

this.container.instance('Athenna/Core/View', view)

if (Config.exists('view.disk')) {
Expand All @@ -28,6 +25,10 @@ export class ViewProvider extends ServiceProvider {

Object.keys(disks).forEach(k => view.createViewDisk(k, disks[k]))

const properties = Config.get('view.properties', {})

Object.keys(properties).forEach(k => view.addProperty(k, properties[k]))

const components = Config.get('view.components', {})

Object.keys(components).forEach(k =>
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/config/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import { Path } from '@athenna/common'
import { Env, Config } from '@athenna/config'

export default {
disk: Path.fixtures('views'),
Expand All @@ -16,6 +17,11 @@ export default {
admin: Path.fixtures('views/admin')
},

properties: {
env: Env,
config: Config
},

components: {
button: Path.fixtures('views/components/button.edge'),
copyright: Path.fixtures('views/components/copyright.edge'),
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/providers/ViewProviderTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ export default class ViewProviderTest {
}

@Test()
public async shouldRegisterTemplatesInViewConfigInTheViewInstance({ assert }: Context) {
public async shouldRegisterPropertiesToBeAvailableToAllViewsInViewConfigInTheViewInstance({ assert }: Context) {
new ViewProvider().register()

assert.isDefined(View.edge.globals.env)
assert.isDefined(View.edge.globals.config)
assert.isUndefined(View.edge.globals.notFound)
}

@Test()
public async shouldRegisterComponentsInViewConfigInTheViewInstance({ assert }: Context) {
new ViewProvider().register()

assert.isTrue(View.hasComponent('button'))
Expand Down
Loading