Giter Club home page Giter Club logo

express-blocks's Introduction

express-blocks

Middleware for Express that adds basic block support to views.

This was initially prototyped by Laurie Harper. Thanks Laurie!

Installation

Easy peasy:

npm install express-blocks

Please note the version you install and only specify that exact version as your dependency while this is in development. Breaking changes are likely!

Usage

In your app.js, register this middleware:

app.use(require('express-blocks'));

Then in your (top-level) layout, name and add placeholders for your desired blocks (e.g. in EJS syntax):

<%- blocks.foo %>
...
<%- blocks.bar %>

And from your views (or intermediate layouts), add arbitrary HTML to those blocks via the block() function:

<%- block('foo', '<p>Hello world!</p>') %>

You can use the helper script() and stylesheet() functions to generate generate staple <script> and <link rel="stylesheet"> references for you:

<%- script('/path/to/script.js') %>
<%- stylesheet('/path/to/stylesheet.js') %>

Which are exposed to (top-level) layouts as blocks named scripts and stylesheets, also aliased globally just like body:

<%- scripts %>
<%- stylesheets %>

As Borat would say, niiice!

Example

Run the included Express example:

node example/app.js

Then open your browser to http://localhost:8080/ to see it in action.

Testing

You can verify that everything works as expected via:

npm test

If you want to submit a pull request, be sure to add a test case, too!

License

MIT License. Copyright © 2011 Aseem Kishore and Laurie Harper.

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.