Skip to content

A node library to bring PJSON capabilities to your application

Notifications You must be signed in to change notification settings

EikosPartners/pjson-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is the repository for the PJSON loader.

Installation

npm install --save pjson-loader

Usage

API

  var pjsonLoader = require('pjson-loader');
  pjsonLoader.load(app, options, callback);
  pjsonLoader.ensureDirectory(opts);
  pjsonLoader.getJSON(name, opts, callback);

Examples

Default options.
  // Use the default options. Pass an empty object to opts.
  /*
   {
       rootDir: 'server',
       pjsonPath: 'pjson',
       fragmentsPath: 'fragments',
       pagesPath: 'pages',
       middleware: [],
       routes: [{
           url: '/pjson',
           queryParam: true,
           params: []
       }]
    }
   */

  // App is your express application to bind the /pjson route to.

  pjsonLoader.load(app, {}, function (err) {
      // Handle error if there was one.
  });
Specifying directory option

Pages and fragments should always be in the pjson directory.

  var myOpts = {
    rootDir: "myDir",
    pjsonPath: "myPjsonPath",
    fragmentsPath: "myFragmentsPath",
    pagesPath: "myPagesPath",
    middleware: [myMiddleWareFuncs, ...]
  }

  pjsonLoader.load(app, myOpts, function (err) {});
Specifying a custom url
// This will load pjson files from the url /UI/:pjsonname
// To use the custom url you must set queryParam to false and provide the paramName
// property.
pjsonLoader.load(app, {
    routes: [
        {
            url: '/UI/:pjsonname/',
            queryParam: false,
            params: 'pjsonname'
        }
    ]
});

You can also specify a url for subdirectories in your pages path.

// Make sure to specify the params in the order they appear in the url.
pjsonLoader.load(app, {
    routes: [
        {
            url: '/UI/:subdirectory/:pjsonname',
            queryParam: false,
            params: ['subdirectory', 'pjsonname']
        }
    ]
});

Tests

npm run test

About

A node library to bring PJSON capabilities to your application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages