shpnode

0.1.12 • Public • Published

shpnode

A Simple Hypertext Preprocessor.

experimental Build Status NPM MIT Licence

Introduction

SHP: Simple Hypertext Preprocessor

SHP : 简单超文本预处理器

const Shpnode = require('shpnode')

shpnode.newFile('/header.html', '<div>header content</div>')
shpnode.newFile('/index.shp', '<html><shp include="/header.html"></shp><html>')

const html = shpnode.buildFileToHtml('/index.shp')
console.log(html)
// <html><div>header content</div></html>

Install

npm:

npm install shpnode --save

Usage

Filename: /srcDir/index.shp:

<html><head></head>
  <body><shp include=""></shp></body>
</html>

Filename: /srcDir/template/header.html

<div><h1>Header</h1></div>

Filename: /build.js

const Shpnode = require('shpnode');
var shpnode = new Shpnode({
    srcDir: '/srcDir/',
    outDir : '/outDir/',
    resource: ['/template/']
});
shpnode.build();

Build:

# node build.js

Output file: /outDir/index.html

<html><head></head>
  <body><div><h1>Header</h1></div></body>
</html>

API

.build()

Build all files under the srcDir folder and Output to the outDir folder.

shpnode.build()	
.newFile(filePath, fileContent)
shpnode.newFile('/header.html', '<div>header content</div>')
shpnode.newFile('/index.shp', '<html><shp include="/header.html"></shp><html>')
.hasFile(filePath)
shpnode.hasFile('/index.shp')	// result: true
.getFileCount()
shpnode.getFileCount()		// result: 2. index.shp and header.html
.buildFileToHtml(filePath)
shpnode.buildFileToHtml('/index.shp')	
// result: <html><div>header content</div></html>
.buildFIle(filePath)
shpnode.buildFile('/index.shp')
.buildAllFile()
shpnode.buildAllFile()		
.outputFile(filePath)
shpnode.outputFile('/index.shp')
/*
  filename `/outDir/index.index`:
  <html><div>header content</div></html>
 */
.outputAllFile()
shpnode.outputAllFile()

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i shpnode

Weekly Downloads

0

Version

0.1.12

License

MIT

Last publish

Collaborators

  • maijz