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

z-views

v1.0.40

Published

integrate between HTML files and JS objects

Downloads

9

Readme

this is a part of ZadaheaD's owner core tools for easier much more efficiant way to work with HTML, CSS, and Javascripts

look at z-http, if you want a lightweight "express like" http server engine

I never liked working with ejs, or these kind of tools cos I find them very messy, and I always liked working as clean and as seperated as possible. so in this project, I will use the same logic as ejs but with much cleaner way to handle HTML files and manipulate JS objects.

z-views

z-views is a server-side rendering module, inspired by ejs,

but aimed to be more html friendly and less of a "spaghetti code" type

To install, run npm install for your package.json dependencies:

npm install z-views

.
.

Render a simple html page

1) create and html file, inside views folder
project
|
└─── views
│   │   index.html

index.html

<h1>hello world</h1>
2) render the html
var zview = require('z-views');
zview.init();

zview.render('index', {}, (htmlContent) => {
     console.log(htmlContent) //html content  
});
3) use z-http to respond html on route
var http = require('z-http');

var zview = require('z-views');
zview.init();

http.start(3000, function (route, method) {
    return (data, callback) => {

        zview.render('index', {}, (htmlContent) => {
            callback(htmlContent)
        });

    }
}, {});

.
.

If you want to change views folder, you can set this on init.

zview.init({
    path: 'another_views_folder'
});

.
.

Data Objects - in order to pass data into the html you want to render, use that {{__param__}} key.

index.html

<h1>hello {{value}} world</h1>

zview.render

  zview.render('index', {
            value: 'great'
        }, (htmlContent) => {
            //rendered html is here
        });

response

<h1>hello great world</h1>

.
.

Global Values - are also possible by passing res object on init.

init

zview.init({
    res: {
        headline: 'Base Headline'
    }
});

index.html

<h1>{{res.defaultHeadline}}</h1>
<h2>hello {{value}} world</h2>

zview.render

  zview.render('index', {
            value: 'great'
        }, (htmlContent) => {
            //rendered html is here
        });

response

<h1>Base Headline</h1>
<h2>hello great world</h2>

.
.

Conditioned Rendering - is possible by {${__condition__}} key

index.html

<h2 style="color: {${data.hightlight ? 'red' : 'yellow'}}">html will be red, if hightlight param is passed as data</h2>

zview.render

  zview.render('index', {
            hightlight: true
        }, (htmlContent) => {
            //rendered html is here
        });

response

<h2 style="color: red">html will be red, if hightlight param is passed as data</h2>

.
.

Loops - <loop> is an z-view html tag, this will load a list and repeat the content while rendering data for each element

index.html

<h1>Loops</h1>
<div>
    <loop list>
        <div>{{name}}</div>
    </loop>
</div>

zview.render

  zview.render('index', {
            list: [
                { name: 'Mosh' },
                { name: 'David' },
                { name: 'Baruch' }
            ]
        }, (htmlContent) => {
            //rendered html is here
        });

response

<h1>Loops</h1>
<div>
  <div>Mosh</div>
  <div>David</div>
  <div>Baruch</div>
</div>

.
.

If - <if> is an z-view html tag, this will render its children if a condition is true.

index.html

<h1>If</h1>
<if cond="renderBlock">
    <div>this block will render if "renderBlock" is true</div>
</if>

zview.render

  zview.render('index', {
            renderBlock: true
        }, (htmlContent) => {
            //rendered html is here
        });

response

<h1>If</h1>
<div>this block will render if "renderBlock" is true</div>

.
.

If -> Then -> Else - <if><then><else> are z-view html tags, this is a fallback for the "if" tag.

index.html

<h1>If-Then-Else</h1>
<if cond="renderBlock">
    <then>
        <div>this block will render if "renderBlock" is true</div>
    </then>
    <else>
        <div>this will render if not</div>
    </else>
</if>

zview.render

  zview.render('index', {
            renderBlock: false
        }, (htmlContent) => {
            //rendered html is here
        });

response

<h1>If-Then-Else</h1>
<div>this will render if not</div>

. .

Copy -> Paste, <copy><paste> are z-view html tags. there are cases you want to copy a specific block of html to another location in page. this is why copy / paste was created

<h1>Copy-Paste</h1>
<copy divcopy>
    <div>this is an html template you want to copy</div>
</copy>

<paste divcopy></paste>
<paste divcopy></paste>

zview.render

  zview.render('index', {}, (htmlContent) => {
            //rendered html is here
        });

response

<h1>Copy-Paste</h1>
<div>this is an html template you want to copy</div>
<div>this is an html template you want to copy</div>

.
.

Templates, <template> is a z-view html tag, it aimed to use content from a different file location.

1) create another html file, inside views folder
project
|
└─── views
│   │   index.html
│   │   some_template.html

some_template.html

<h2>this is a template</h2>

index.html

<h1>Templates</h1>
<template src="some_template"></template>

zview.render

  zview.render('index', {}, (htmlContent) => {
            //rendered html is here
        });

response

<h1>Templates</h1>
<h2>this is a template</h2>

for more info, please contact me at: [email protected]

thank you, and enjoy programing