Coder Social home page Coder Social logo

aks- / bundalo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from krakenjs/bundalo

0.0 1.0 0.0 161 KB

Manage localized sets of content files (be they property/json/etc) which may require rendering with data models

License: Other

JavaScript 100.00%

bundalo's Introduction

bundalo

Lead Maintainer: Aria Stewart

Extract/cache/render property files/strings using i18n rules and various rendering engines

Build Status

Use cases

Initialize bundalo

Call bundalo module with a key that matches your template engine, plus locale information. Currently only dust and none are supported as engines.

var bundalo = require('bundalo');

//couple of configs for later
var config = {
	"contentPath": "locales/", //required
	"fallback": "en-US",       //optional
	"engine": "dust",          //required
	"cache": false             //optional, default is true
};
var config2 = {
	"contentPath": "globals/",
	"fallback": "",
	"engine": "none"
};

//create two bundalo instances. Each has its own cache
var bundle = bundalo(config);
var bundle2 = bundalo(config);

Use bundalo

User wants key/values from some bundle file, corrected for locality, and possibly rendered with some data model

bundle.get({'bundle': 'errors/server','locality': 'en-US', 'model': {'name': 'Will Robinson'}}, function bundaloReturn(err, data) {
	console.log("what'd we get from bundalo.get?", data, err);
	cb({
		'err': data.error
	});
});

User wants multiple bundles in a single call, to avoid calling bundalo multiple times

bundle.get({'bundle': ['errors/server', 'errors/client'], 'locality': 'en-US',  'model': {'name': 'Will Robinson'}}, function bundaloReturn(err, data) {
	console.log("what'd we get from bundalo.get?", data, err);
	cb({
		'clienterr': data['errors/client'].error,
		'servererr': data['errors/server'].error
	});
});

User wants multiple bundles in a single call, and wants to alias the bundles for easier management upon return

bundle.get('bundle': {
	'server': 'errors/server',
	'client': 'errors/client'
}, 'locality': 'en-US', 'model': {'name': 'Will Robinson'}}, function bundaloReturn(err, data) {
	console.log("what'd we get from bundalo.get?", data, err);
	cb({
		'clienterr': data.client.error,
		'servererr': data.server.error
	});
});

Design

When a user first requests a bundle, bundalo will:

  • fetch the correct file from the file system based on locality
  • [dust only] compile the properties file into a dust template
  • cache the [compiled dust] template
  • [dust only] render the template with any provided data model
  • deserialize the rendered properties file via spud
  • return a JSON data object with the rendered values

Upon subsequent requests for a bundle, the previously cached compiled template will be re-rendered and returned. Cache will be based upon the bundle path provided by the user, plus the locality path information. I.e. 'US/en/foo/bar' is a separate cached object from 'DE/de/foo/bar'. Cache is consistent per bundalo instance created.

bundalo's People

Contributors

aredridel avatar grawk avatar jasisk avatar pvenkatakrishnan avatar totherik avatar

Watchers

 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.