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

node-razor

v0.0.3

Published

razor view engine (based on vash)

Downloads

3

Readme

razor

NPM version

一、简介

基于 vash 扩展的razor视图引擎

视图引擎语法文档:(vash)

二 安装

npm install node-razor

三、Express使用


const path = require('path');
const express = require('express');
const razor = require('razor');

const app = express();

const razorOptions = {
  //默认使用的母版页
  layout: 'layout',
  //母版页的查找目录
  layoutDir: path.resolve('api/views/layout'),
}

//添加vash视图引擎
app.engine('vash', razor(razorOptions));
//设置当前使用的默认视图引擎
app.set('view engine', 'vash');
//设置视图查找目录
app.set('views', path.resolve('api/views'));

四、扩展

扩展了母版页的使用方式

  • 母版页变动如下

    • 新增 @html.renderBody() 用于在(layout)母版页中输出具体页面的内容 用于替代vash中的 @html.block('content') 同时无需在具体页面中指定@html.block('content', function(model){ ...}

    • 将母版页选择改成express.render('home/index',{ layout:'layout'}) 渲染时指定layout参数来分配页面需要使用的母版页 从而不用再具体的页面使用@html.extend('layout', function(model){ ...}

  • 母版页使用方式如下

home.controller.js


  app.get('/home/index.html',(req,resp,next){
      resp.render('/home/index',{ layout:'layout' });
  })

/home/index.vash

<h1 class="name">Welcome to </h1>

/layout/layout.vash (母版页)


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>@model.title</title>
        <link rel="stylesheet" href="stylesheets/style.css" type="text/css" media="screen" charset="utf-8">
    </head>
    <body>
        @html.renderBody()
        <footer>
            @html.block('footer')
        </footer>
    </body>
</html>

五、开源许可

基于 MIT License 开源,使用代码只需说明来源,或者引用 license.txt 即可。