Code Monkey home page Code Monkey logo

edge's Introduction

Contributors Forks Stargazers Issues License GitHub Build


Logo

@lithium/edge

A NestJS module to use EdgeJS templating language.

Request Feature · Report Bug · Request Modification

Table of Contents
  1. About The Project
  2. Install the package
  3. Use the package
  4. Utils links
  5. Contact

About the project

The Edge module is based on the idea of using EdgeJS templating within a NestJS application. The main problem with using EdgeJS within Nest comes from the resolution of Edge in ESM. In this case, we're using a workaround to make use of the dynamic import.

This module is built dynamically, allowing you to define a customized configuration for each use case. We recommend that you create a dedicated custom configuration file by importing a configuration object such as edge.config.ts.

We welcome contributions and improvements to this module. Don't hesitate to submit features and improvements ;)

(back to top)

Built With

  • TypeScript
  • NestJS
  • EdgeJS

(back to top)

Install the package

For now the package isn't published to npm, but you can install it from the GitHub registry and can be installed in any project.

  1. You need to create a .npmrc file at the root of your project with the following content:

    @lithium-apps:registry=https://npm.pkg.github.com
  2. For the login process you need to set a personal access token with the read:packages scope. Then you can login to the GitHub registry with the following command:

    pnpm login --registry=https://npm.pkg.github.com --scope=@lithium-apps
  3. You can now install the packages using the following command:

    pnpm install @lithium-apps/edge

(back to top)

Use the package

  1. Create a configuration file for Edge.JS :

    import { EdgeConfig } from '@lithium-apps/edge';
    
    export const edgeConfig: EdgeConfig = {
        mount: {
            // Define all the named disk mount points
            views: join(__dirname, 'path_to_views'),
        },
    
        // You can set plugins here
        plugins: [],
    
        // You can set globals here
        globals: {},
    
        // Check other options in the EdgeConfig interface
    };
  2. Import the EdgeModule in your application module:

    import { Module } from '@nestjs/common';
    import { EdgeModule } from '@lithium-apps/edge';
    
    import { edgeConfig } from './edge.config';
    import { MyController } from './my.controller';
    
    @Module({
        imports: [
            EdgeModule.forFeature(edgeConfig)
        ],
    
        controllers: [MyController]
    })
    export class MyModule {}
  3. Use the @Render() decorator in your controller:

    import { Controller, Get } from '@nestjs/common';
    import { EdgeService } from '@lithium-apps/edge';
    
    @Controller()
    export class MyController {
    
        @Get('/')
        @Render('views::welcome') // Specify the view to render
        async getHello() {
            return { name: 'Kylian' }; // Data to pass to the view
        }
    }

Useful links

Here are a few useful links to help you use the module or learn more about it! Don't thank us, you'll sleep better :)

Contact

(back to top)

edge's People

Contributors

kylian-mallet avatar

Stargazers

Vasco avatar Guillaume VARIN avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.