Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
templatizer
Advanced tools
Simple solution for compiling jade templates into vanilla JS functions for blazin' fast client-side use.
Simple solution for compiling jade templates into vanilla JS functions for blazin' fast client-side use.
Client-side templating is overly complicated, ultimately what you actually want is a function you can call from your JS that puts your data in a template. Why should I have to send a bunch of strings with Mustaches {{}}
or other silly stuff for the client to parse? Ultimately, all I want is a function that I can call with some variable to render the string I want.
So, the question is, what's a sane way to get to that point? Enter jade. Simple, intuitive templating, and happens to be what I use on the server anyway. So... Jade has some awesome stuff for compiling templates into functions. I just built templatizer to make it easy to turn a folder full of jade templates into a CommonJS module that exports all the template functions by whatever their file name.
From my tests it's 6 to 10 times faster than mustache.js with ICanHaz.
npm install templatizer
var templatizer = require('templatizer');
// pass in the template directory and what you want to
// save the output file as. That's it!
templatizer(__dirname + '/templates', __dirname + '/demo_output.js');
So a folder like this
/clienttemplates
user.jade
app.jade
/myfolder
nestedTemplate.jade
Complies down to a JS file that looks something like this:
// here's about 2k worth of utils that jade uses to DRY up the template code a bit.
// Includes some basic shims for Object.keys, etc.
var jade=function(exports){ ... }
// a function built from the `user.jade` file
// that takes your data and returns a string.
exports.user = function () {}
// built from the `app.jade` file
exports.app = function () {} // the function
// folders become nested objects so
// myfolder/nestedTemplate.jade becomes
exports.myfolder.nestedTemplate = function () {} // the template function
// etc. etc
The awesome thing is... there are no external dependencies because they're just functions at this point. Crazy fast, SO MUCH WIN!!!!
Jade has a feature called mixins
which when compiled get treated as function declarations within the compiled function. Templatizer pulls these out of the compiled function and places them on the namespace of the parent function. For example:
// users.jade
ul
each user in users
mixin user(user)
mixin user(user)
// Jade mixin content
Templatizer will compile this as
// Compiled fn from file
exports.users = function () {}
// Compiled mixin fn
exports.users.user = function (user) {}
This is helpful as it allows you to call users()
to create your list and then users.user()
to render just a single item in the list.
Check out the demo_output.js
file for... err... demo output built from the templates
directory in this project.
MIT
If you think this is cool, you should follow me on twitter: @HenrikJoreteg
FAQs
Simple solution for compiling jade templates into vanilla JS functions for blazin' fast client-side use.
The npm package templatizer receives a total of 17 weekly downloads. As such, templatizer popularity was classified as not popular.
We found that templatizer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.