npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

soyer

v0.3.5

Published

Soyer is small lib for serverside use of Google Closure Templates with node.js

Downloads

53

Readme

soyer

Build Status Dependency Status NPM version

Soyer is small lib for serverside use of Google Closure Templates with node.js.

NPM

Thanks to Daniel Pupius for soynode. I used this module as template and added the language support and removed the compile features.

Install

  npm install soyer

Initialize module:

var Soyer = require("soyer");
var mySoyer = new Soyer( config );

mySoyer.load( function( err, success ){
	if( err ){
		throw err
	} else {
		console.log( "templates sucessfully loaded" );
	}
});

####config object description

  • path : ( String required )
    absolute path to the directory where the module can find compiled soy files.
  • soyFileExt : ( String optional: default = ".soy.js" )
    soy file extension to select only the compiled soy files.
  • languagesupport : ( Boolean optional: default = false )
    enable the language support. If true the following options are relevant.
  • defaultlang : ( String optional: default = "en-us" )
    the default language code if the passed code will not fit.
  • availibleLangs : ( Array optional: default = "[ "en-us", "de-de" ]" )
    a list of valid language codes
  • extractLang : ( Function optional )
    a method to extract the language-code out of the filename. The filename will be passed to the method and should return a valid language code.

Example

var Soyer = require( "soyer" );

var mySoyer = new Soyer({
	path: path.resolve( __dirname, "../path/to/templates/" ) 
});

mySoyer.load( function( err, success ){
	if( err ){
		throw err
	}

	var rendered = mySoyer.render( "myNamespace.myTemplate", { param1: "abc" } );
	console.log( rendered );
});

Advanced example

// files in folder: template.soy, template.en.js, template.fr.js, template.de.js

var Soyer = require( "soyer" );

var mySoyer = new Soyer({
	path: path.resolve( __dirname, "../path/to/templates/" ) ,
	soyFileExt: ".js",
	languagesupport: true,
	defaultlang: "de",
	availibleLangs: [ "en", "de", "fr" ],
	extractLang: function( file ){
		var _lang = file.split( "." )[1]
		return _lang
	}
});


mySoyer.load( function( err, success ){
	if( err ){
		throw err
	}

	var renderedDE = mySoyer.render( "myNamespace.myTemplate", "de" { param1: "deutsch" } );
	console.log( renderedDE );

	var renderedEN = mySoyer.render( "myNamespace.myTemplate", "en" { param1: "english" } );
	console.log( renderedEN );

	var renderedFR = mySoyer.render( "myNamespace.myTemplate", "fr" { param1: "français" } );
	console.log( renderedFR );
});

get a template method ( GET )

Get's a method to render a template.

mySoyer.get( name, [ lang ] ) Arguments :

  • name: ( String required )
    soy path of the template.
  • lang: ( String required )
    the language to render if languagesupport is activated.

Example

var fnTemplate = mySoyer.get( "myNamespace.path.to.template" );

console.log( fnTemplate( { param1: "hello world" } ) );

render a template ( RENDER )

render a template immediately

mySoyer.get( name, [ lang ] ) Arguments :

  • name: ( String required )
    soy path of the template.
  • lang: ( String optional )
    the language to render if languagesupport is activated.
  • data: ( String optional: default = {} )
    template data.

Example

var rendered = mySoyer.render( "myNamespace.path.to.template", { param1: "hello world" } );
console.log( rendered );

routing helper

usually you will use soyer within a routing framework like express.
In this case the server has to finish the loading of the templates before the first .render() is called.
So you can use the method routingWait to add a middleware and make sure the templates has been loaded until the first rendering starts.

To use it you just have to add and call the method [ your soyer instance ].routingWait() as middleware.
Buff This is designed to fit to express. But you can use it in other tools, too. You just have to make sure the last argument of your routing framework is the next method ( e.g. in express it's ( request, response, next ) ).

Example

Soyer = require("soyer");

var express = require("express");
var app = express.createServer();

var mySoyer = new Soyer( config );
mySoyer.load( function( err ){
	if( err ){
		throw err
	}
});

app.get( "/myroute/:id", mySoyer.routingWait(), function( req, res ){
	// do your stuff
});

app.listen()

###General info

To define a locale my best practice is a combination of language-code ISO 639 and country-code ISO 3166.
But you can define your own logic with this module.

Release History

|Version|Date|Description| |:--:|:--:|:--| |v0.3.5|2015-04-14|Dropped node 0.6 and 0.8 travis tests, because the dependencies to build the modules are not compatible. But i think the compiled version from npm should already work | |v0.3.4|2015-04-14|Added try catch during vm context create; changed to a more modern development env with grunt; Switched to lodash | |v0.3.3|2014-10-30|Fixed bug in routingWait method| |v0.3.1|2013-12-04|Fixed bug to ignore hidden files ( prefixed with a . )| |v0.3.0|2013-03-04|Updated soyutils to version Dez. 2012|

NPM

Other projects

|Name|Description| |:--|:--| |rsmq|A really simple message queue based on Redis| |rsmq-worker|RSMQ helper to simply implement a worker around the message queue| |redis-notifications|A redis based notification engine. It implements the rsmq-worker to safely create notifications and recurring reports.| |node-cache|Simple and fast NodeJS internal caching. Node internal in memory cache like memcached.| |redis-sessions|An advanced session store for NodeJS and Redis| |obj-schema|Simple module to validate an object by a predefined schema| |connect-redis-sessions|A connect or express middleware to simply use the redis sessions. With redis sessions you can handle multiple sessions per user_id.| |systemhealth|Node module to run simple custom checks for your machine or it's connections. It will use redis-heartbeat to send the current state to redis.| |task-queue-worker|A powerful tool for background processing of tasks that are run by making standard http requests.| |grunt-soy-compile|Compile Goggle Closure Templates ( SOY ) templates inclding the handling of XLIFF language files.| |backlunr|A solution to bring Backbone Collections together with the browser fulltext search engine Lunr.js|

License

(The MIT License)

Copyright (c) 2013 M. Peter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.