Giter VIP home page Giter VIP logo

page-press's Introduction

PagePress - NodeJS Template Engine

page-press takes static html file, plugs whatever you want inside and sends it to the web browser.

Features:

  • Lightweight & easy to use
  • Caching support
  • Localization support
  • Works with express

QUICK START

Prepare the frontend index.html page:

<html>
    <body>
    <h1>greet-text</h1>
    </body>
</html>

greet-text is a placeholder. It will be replaced by a value when the browser sees it.

Prepare the backend index.js file:

const express = require('express')
const app = express()

const pagePress = require('page-press')
app.use(pagePress)

app.get('/', (req, res) => {

    let fileToServe = __dirname + '/index.html'
    res.render(
        fileToServe,                // template file
        {'greet-text':'Hello!'}     // placeholder bindings
    )

})

app.listen(80)

In res.render() we first specify the template file, and then a JSON object with the values we wish to bind to placeholders in index.html.

Do npm index.js and visit http://localhost from your web browser.

Adding multi-language support

Prepare your language file index.html.lang next to index.html:

{
    "default":{
        "greet-text":"Hello!",
        "original text":"replacement text"
    },
    "sp":{
        "greet-text":"Hola!"
    },
    "jp":{
        "greet-text":"Konichiva!"
    }
}

Pass your prefered language into the res.render():

res.render(
    fileToServe,    // template file
    {},             // placeholder bindings
    'sp'            // language
)

PagePress will read the .lang file and fill the placeholder with the specified spanish value. If you do not specify the language in res.render(). Not specifying a language in res.ender() will make PagePress use default fields in the language file to fill html placeholders.

page-press's People

Contributors

kumarasinghe avatar

Watchers

James Cloos avatar  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.