npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plugdo-view-engine

v1.0.5

Published

plugdo view engine for render of .pve files using the view module of our EUI framework

Downloads

5

Readme

plugdo-view-engine

This module is a view engine for express. It render view components of plugdo EUI JS Framework from server side.

npm install plugdo-view-engine --save

The following configuration must be in place before you start using it.

  • Include the module to your main index.js
  • Register the new view engine to express or to the plugdo-mvc web server property
  • Register the path of the view component files
// Register the module
const { pve } = require("plugdo-view-engine");

// Using plugdo-mvc
const mvc = require("@dellasera/plugdo-mvc").mvc();

// Helper for path handling
const path = require("path");

// Register the view engine
mvc.webserver.engine('pve', pve.render);

// Register the path of the view component that you will create
pve.setPath(path.resolve(__dirname) + "/content/component");

// Start the plugdo mvc server
mvc.start(3000, path.resolve(__dirname));

Now you can add your files with the extension PVE, and the Express will apply this view engine.

Let's see an example for Static Component

Create a view component file within the component folder, and name it plugdo-title.html. The name of the file must be the same of the view component, just add the html extension. Always add the .html extension to the components.

note: for more information about the view component, go to the documentation in Plugdo View Component

Component plugdo-title.html

<plugdo-title>
    <template>
        <h1>Hello World</h1>
    </template>
</plugdo-title>

Web page to be rendered index.pve

<html>
    <head>
        <title>First Demo</title>
    </head>
    <body>
        <plugdo-title id="title"></plugdo-title>
    </body>
</html>

Let's understand what is going to happend:

  • Express with detect the extension .pve and it will apply this view engine module for rendering
  • This module will load the .pve file and It will collect each plugdo-* component
  • Using the names collected, this module will check if the file exists within the component folder
  • This module will process the view component render process, replacing the plugdo-* component with the final html result
  • The html is returned to the express buffer

Output to the Web Browser

<html>
    <head>
        <title>First Demo</title>
    </head>
    <body>
        <div id="title">
            <h1>Hello World</h1>
        </div>
    </body>
</html>

Let's see an example for Dynamic Component

The view component also accept a model to be used for dynamic render. Let's see the title will be dynamic in the following template.

Component plugdo-title.html

<plugdo-title>
    <template>
        <h1>[json:title]</h1>
    </template>
</plugdo-title>

Web page to be rendered index.pve

<html>
    <head>
        <title>First Demo</title>
    </head>
    <body>
        <plugdo-title id="componentID"></plugdo-title>
    </body>
</html>

Now you must pass a model to the view component following this instructions:

  • The model structure is static
  • The model must provide a property named component
  • The name of the view component is the container of data within the component property
  • Each view component will also include the id assigned to the view component
  • At the end, a static hierarchy is created.
model = {
    component: { // Immutable
        "plugdo-title": { // view component
            "componentID": { // id of the view component
                title: "Hello World"
            }
        }
    }
}

Let's pass the model using a controller of our plugdo-mvc module.

To get more information about our MVC framework go to Plugdo MVC

mvc.controller({
    name: "home",
    action: "index",
    path: "",
    view: "home/index.pve"
}, function (req, res) {
    
    model = {
        component: { // Immutable
            "plugdo-title": { // view component
                "componentID": { // id of the view component
                    title: "Hello World"
                }
            }
        }
    }

    res(model);
});

Let's understand what is going to happen:

  • If the model is undefined, nothing will be passed to the view engine
  • If the view component exists and the id also exists, the model will be passed to the view component for rendering

We know, this module is not a dynamic solution, but It is matter of time to get use to it, and replicate always the same. The advantage for us is that we use the same view component in the front-end for ajax architecture, or in the server-side for post back architecture.

The big limitation for server-side is that the view component does not provide a state in memory for later use and it will never be reloaded as a view component in the front-end.