All Projects β†’ tdumitrescu β†’ virtual-jade

tdumitrescu / virtual-jade

Licence: other
Compile Jade templates to Hyperscript for Virtual DOM libraries

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to virtual-jade

preview-vscode
A previewer of Markdown and HTML for Visual Studio Code
Stars: ✭ 25 (-19.35%)
Mutual labels:  pug, jade
pretty-harp-jade-skeleton
πŸ’€ Harp & Jade/Pug skeleton theme for a personal blog
Stars: ✭ 15 (-51.61%)
Mutual labels:  pug, jade
Bootstrap3 Pug Former jade Node Express Grunt
Bootstrap 3 templated by Jade
Stars: ✭ 242 (+680.65%)
Mutual labels:  pug, jade
lsxc
Compile Livescript + Pug + React + SASS as a single component
Stars: ✭ 17 (-45.16%)
Mutual labels:  pug, jade
emitty
A platform for finding dependencies between files and building tools for incremental compilation or build.
Stars: ✭ 69 (+122.58%)
Mutual labels:  pug, jade
Pug As Jsx Loader
Stars: ✭ 168 (+441.94%)
Mutual labels:  pug, jade
tale-pug
Tale Pug is the popular JavaScript Template Engine Pug, formerly Jade, for PHP!
Stars: ✭ 32 (+3.23%)
Mutual labels:  pug, jade
Wordless
All the power of Pug, Sass, Coffeescript and WebPack in your WordPress theme. Stop writing themes like it's 1998.
Stars: ✭ 1,374 (+4332.26%)
Mutual labels:  pug, jade
pypugjs
PugJS syntax adapter for Django, Jinja2 and Mako templates
Stars: ✭ 237 (+664.52%)
Mutual labels:  pug, jade
tung
A javascript library for rendering html
Stars: ✭ 29 (-6.45%)
Mutual labels:  virtual-dom, snabbdom
Laravel Pug
Pug view adapter for Laravel and Lumen
Stars: ✭ 130 (+319.35%)
Mutual labels:  pug, jade
pug-symfony
Pug (Jade) template engine for Symfony
Stars: ✭ 40 (+29.03%)
Mutual labels:  pug, jade
Jade Html5 Boilerplate
HTML5 Boilerplate ported to Jade. Great as a drop and go markup skeleton for Express apps.
Stars: ✭ 111 (+258.06%)
Mutual labels:  pug, jade
Compile Hero
πŸ”°Visual Studio Code Extension For Compiling Language
Stars: ✭ 169 (+445.16%)
Mutual labels:  pug, jade
Node.js Bootstrap Starter Template
Node.js, Express, Pug, Twitter Bootstrap, Starter Template
Stars: ✭ 107 (+245.16%)
Mutual labels:  pug, jade
Jade
Jade.go - pug template engine for Go (golang)
Stars: ✭ 251 (+709.68%)
Mutual labels:  pug, jade
Gulp Pug Sass Seed
🍹 A Pug and Sass starter project using gulp for task automation.
Stars: ✭ 84 (+170.97%)
Mutual labels:  pug, jade
Pug Sass Boilerplate Starter Kit
A Front-end template for building web apps or sites using Pug(Jade) and Sass
Stars: ✭ 92 (+196.77%)
Mutual labels:  pug, jade
idiots.win
Google Autocomplete Guessing Game
Stars: ✭ 26 (-16.13%)
Mutual labels:  pug, jade
bit-css
η”¨εŽŸε­η±»θ΅‹δΊˆε…ƒη΄ ε±žζ€§οΌŒε‡ε°‘η”šθ‡³δΈε†™css
Stars: ✭ 19 (-38.71%)
Mutual labels:  pug, jade

virtual-jade

NPM version Build status Test coverage

Compile your jade templates into Virtual DOM functions. Works with multiple Virtual DOM libraries, including:

For people who like declarative reactive templating, but don't like writing HTML or JSX.

Create a template:

.items
  each item in items
    .item(
      class={active: item.active}
      data-id=item.id
    )
      .item-title= item.title
      .item-description= item.description

require() your template as a function and use a rendering system like main-loop:

const mainLoop = require('main-loop');

const template = require('./items.jade');

const initState = {
  items: [],
};

const loop = mainLoop(initState, template, {
    create: require("virtual-dom/create-element"),
    diff: require("virtual-dom/diff"),
    patch: require("virtual-dom/patch"),
});
document.body.appendChild(loop.target);

Then update whenever you'd like!

loop.update({
  items: [
    {
      id: 'asdf',
      title: 'some title',
      description: 'some description',
      active: false,
    },
  ],
});

Notes

  • For easy configuration with Webpack, use virtual-jade-loader.
  • To translate with Babel, use babel-plugin-virtual-jade.
  • Can be used with any CommonJS environment with client-side require()s.
  • All templates must return a single root element.
  • Requires you to install the appropriate virtual-dom library in your top-level app.

API

fnStr = render(str, options)

str is the jade source as a string. fnStr is output JS that you should include as a CommonJS module.

Options are:

  • filename: path and name of Jade source file for str. Required if you use include or extends in templates.
  • marshalDataset=true: whether to convert data- attributes to dataset members. Set to false to treat as props with the same name as the attributes (if your target Virtual DOM renderer does not support the dataset API).
  • pretty=false: whether to beautify the resulting JS. Requires you to install js-beautify yourself.
  • propsWrapper: optional object to wrap Jade attributes in; for example, with propsWrapper = 'props', the template div(foo="bar") will translate to something like h('div', {props: {foo: 'bar'}}) rather than h('div', {foo: 'bar'})
  • rawProps: whether to skip Jade attribute -> HTML property conversion; this is set to true in the default Snabbdom configuration
  • serializeAttrsObjects: special behavior for the Snabbdom-style attrs attribute object. If true, object values within an attrs attribute will be automatically stringified (since HTML element attributes are always strings); for example, in div(attrs={foo: {hello: 'world'}}) the foo attr will end up in HTML as "{"hello":"world"}" (rather than "[object Object]").
  • runtime: optional override to include any arbitrary Virtual DOM library that defines the h() hyperscript function. E.g. var h = require('my-special-lib/h');
  • vdom: name of the Virtual DOM library configuration to load (currently either virtual-dom or snabbdom).

Returns a string that looks like:

function render(locals) {
  var result_of_with = /* stuff */
  if (result_of_with) return result_of_with.value;;
}

You are expected to eval() the string if you want the source as a function. Otherwise, just create a module in the following format:

const js = `module.exports = ${fnStr}`;

Within code blocks in your template code, you can access Jade mixin functions via the $mixins variable. In virtual-jade, mixins boil down to functions that take arguments and return a tree of h(name, attrs, children). They are like React stateless components. Accessing them via $mixins is useful for special cases where you want to pass around handles to blocks of Jade code as callback functions (see example below).

mixin item(x)
  .item
    .more-tree= x + 1

list-virtual-scroll(props={itemRenderer: $mixins.item})
// in list-virtual-scroll.jade
each val in allItems.slice(startIdx, endIdx)
  = props.itemRenderer(val)

Development notes

  • Install deps: npm install
  • Run tests: npm test
  • Run linter: npm run lint
  • Generate coverage report: npm run test-cov
  • Run all the verifications together: npm run test-ci
  • Run tests with verbose debugging output (compiled functions as well as rendered HTML): DEBUG=test npm test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].