Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nephrite

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nephrite

Nephrite ==============

  • 1.1.1
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

Nephrite

Pre-compiles jade to Coffee/Coco/LiveScript, allowing you to have the syntax of jade with the best perfs (only interpolation is used). It also avoids you the pain of undefined and null by auto-soaking.

To make you understand this a bit better, let's say that your code :

ul#pages
  for page in @pages
    li: a(href="page/#{page}")= page

will get compiled to

'<ul id="pages">' + join((function () {
  var ref$, results$ = [];
  for (key in ref$ = locals.pages) {
    val = ref$[key];
    results$.push('<li><a href="page/' + page + '">' + page + '</a></li>');
  }
  return results$;
}()) || '') + '</ul>'

Jade itself can be slow due to several factors (with, attrs, escape) and this project allows you to avoid that!

(the code is highly unstable and total crap) Tho, it's used in html5chan and wowboardhelpers.

Usage

Compile it and use it later. Attributes are passed as locals, aliased to @. You can pass an extra attributes object as @@

# compile it
nephrite = require 'nephrite'
src = nephrite.compile 'a(b="#{@c}")', 'index.jade'
js = Coco.compile src, {bare: true, filename}
# use it
fn obj, extra

Syntax

The syntax is the same as Jade, with a few gotchas :

  • Don't prefix your tags with -, it's jade interpolation, to allow for even better perfs on static content :
ul#pages
 - for (var i = 0; i <= 10; ++i)
    li: a(page=i)== i

for tags, see just below.

  • The jade output is == (as seen just before). This is executed compile-time (by jade).

  • Tags are automatically recognized. Currently supported tags are : if, unless, while, for, else. Loops are automatically joined.

  • To avoid complexity in the converter, for attribute interpolation you have to explicitely interpolate them : a(href=foo) Foo! will use jade (compile time), a(href="#{@foo}") Foo! will use your locals.foo (runtime).

  • The "silent code interpolation" is ~ (take note that any code interpolation appearing BEFORE content will be moved out of the closure for better perfs.) For example :

~ template = require 'user-template'
~ /*^ this will be moved out of the closure function*/
#users
  ~ /*this will not*/
  ~ "this won't be outputted anyway"

FAQs

Package last updated on 25 Mar 2013

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc