All Projects → mquandalle → Meteor Jade

mquandalle / Meteor Jade

Licence: mit
The Jade template engine for Meteor/Blaze

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Meteor Jade

meteor-getting-started
Урок для хабры. Разработка первого метеор приложения.
Stars: ✭ 36 (-88.46%)
Mutual labels:  meteor, jade
Meteor Launchpad
A base Docker image for Meteor applications.
Stars: ✭ 276 (-11.54%)
Mutual labels:  meteor
accounts-material-ui
Material-ui integration with std:accounts-ui
Stars: ✭ 17 (-94.55%)
Mutual labels:  meteor
sofie-core
Sofie: The Modern TV News Studio Automation System (Server Core)
Stars: ✭ 70 (-77.56%)
Mutual labels:  meteor
spiderable-middleware
🤖 Prerendering for JavaScript powered websites. Great solution for PWAs (Progressive Web Apps), SPAs (Single Page Applications), and other websites based on top of front-end JavaScript frameworks
Stars: ✭ 29 (-90.71%)
Mutual labels:  meteor
meteor-method-hooks
atmospherejs.com/seba/method-hooks
Stars: ✭ 24 (-92.31%)
Mutual labels:  meteor
accessibility-cloud
👩🏽‍🦯🦮👩🏻‍🦽👩🏿‍🦼 the platform to exchange physical accessibility data in a standardized, future-proof, easy-to-use way.
Stars: ✭ 37 (-88.14%)
Mutual labels:  meteor
Workbase Server
Slack alternative, email integrated, build with Meteor
Stars: ✭ 284 (-8.97%)
Mutual labels:  meteor
Android Ddp
[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Stars: ✭ 271 (-13.14%)
Mutual labels:  meteor
generator-vintage-frontend
Modern front-end workflow
Stars: ✭ 15 (-95.19%)
Mutual labels:  jade
ReaDB
ReaDB is your private digital bookshelf. Read. Review. Remember.
Stars: ✭ 84 (-73.08%)
Mutual labels:  meteor
TorrentsDuck
A multi users bittorrents client with a responsive web UI that quacks 🦆
Stars: ✭ 42 (-86.54%)
Mutual labels:  meteor
Helpq
💁 an extensible real-time queue application, for mentorship @ hackathons and classrooms
Stars: ✭ 256 (-17.95%)
Mutual labels:  meteor
awesome-blaze
🔥A curated list of awesome things related to Blaze
Stars: ✭ 29 (-90.71%)
Mutual labels:  meteor
Glipchat
video chatroom using meteor + webrtc + react + redux
Stars: ✭ 280 (-10.26%)
Mutual labels:  meteor
meteor-autoform-materialize
DEPRECATED - Meteor AutoForm Materialize templates
Stars: ✭ 48 (-84.62%)
Mutual labels:  meteor
meteor-guide-starter-react
A basic starter application based on the Meteor guide
Stars: ✭ 20 (-93.59%)
Mutual labels:  meteor
uglifyjs2
Meteor package that exposes options for UglifyJS2 JS minifier
Stars: ✭ 15 (-95.19%)
Mutual labels:  meteor
Shkjem
基于Vue&ElementUI的企业官网
Stars: ✭ 281 (-9.94%)
Mutual labels:  jade
Drmongo
MongoDB admin app built on MeteorJs.
Stars: ✭ 283 (-9.29%)
Mutual labels:  meteor

Jade for Meteor

Meteor Icon

This Meteor package provides some support for the Jade template engine as a Spacebars alternative.

Spacebars and Jade packages can coexist, Spacebars will continue to compile files ending with .html and Jade will take care of those ending with .jade.

Table of Contents

Installation

Meteor-jade is installable from atmosphere, the meteor package system:

$ meteor add mquandalle:jade

Examples

Meteor comes with some examples such as leaderboard or todos. You'll find jade versions of those examples templates and even more in the examples directory.

Usage

Meteor-jade works somewhat like Jade, so if you never use Jade before you should take a look at the documentation.

There are some specifics rules relative to the Meteor way of handling templates. These rules are mostly the same as the Spacebars ones.

Templates

Every HTML tag must be in a template. You can define a template with the following syntax:

template(name="myTemplate")
  p This paragraph is inside my template

There are two particular templates that are automatically rendered inside the DOM: head and body. If you want to include a template inside another, precede its name by the + symbol:

head
  title Leaderboard

body
  +leaderboard
  //- This is equivalent to {{> leaderboard}}

Inside a text node you can use both {{spacebars}} and #{jade} expressions but the last one is recommended:

template(name="leaderboard")
  p Welcome #{player.name}

If you indent after a div or similar element, you can use | symbol in order jade not to confuse with tags:

template(name='leaderboard')
  #content
   | #{greeting}

You can also use = as a shortcut:

template(name='leaderboard')
  #content
   = greeting

If you want to insert raw HTML you can use the !{jade} syntax which is equivalent to the triple-braced {{{spacebars}}} expression.

HTML Tag attributes

In Jade you define HTML Tag attributes inside parenthesis:

input(name="myName" placeholder="name" autofocus)

If you want to conditionally include a HTML Tag attribute you can use the following syntax:

input(required = isRequired)

Where isRequired is a (potentially reactive) boolean defined in a template helper. If you want to add a list of dynamic attributes use:

input($dyn = attrs)

Spacebars equivalent:

<input {{attrs}}>

Components

As you may already know, Meteor templates are "components" as well. To use a template as a component, you simply have to provide a content block and optionally a elseContent block after the inclusion:

body
  +ifEven(value=2)
    | Hello world
  else
    | Bye world

  //-
    This is the equivalent of:
    {{#ifEven value=2}}
      Hello world
    {{else}}
      Bye world
    {{/ifEven}}
    ifEven is a component defined by the user
    See the complete example in ./examples/components.jade

Like with Spacebars, a component can receive both ordered and keywords arguments. Keywords arguments must be written after the ordered ones:

+myComponent(arg1 arg2 arg3 key1=val1 key2=val2)

Brackets are optional:

+myComponent arg1 arg2 arg3 key1=val1 key2=val2

For the four built-in components (if, unless, each and with) the + is also optional:

ul
  each players
    if isSelected
      li.selected= name
    else
      li= name

Additional features

We have some additional features over Spacebars.

else if

We provide syntaxic sugar so you can write:

if user.isAdmin
  h1 Hello admin
else if user.isConnected
  h1 Hello user
else
  h1 Hello visitor

Instead of:

if user.isAdmin
  h1 Hello admin
else
  if user.isConnected
    h1 Hello user
  else
    h1 Hello visitor

Under the hood, those two codes are compiled to the same abstract tree, so there are no runtime performance hit.

Unwrapped templates

Putting each template in its own separate file and naming the file after the template it contains is becoming a followed pattern among Meteor developers. See for instance this article from Josh Owens.

But as it stands today, this pattern doesn't respect the “don't repeat yourself” (DRY) philosophy. Indeed you have to wrap your template in a <template name="myTemplate> tag and saving it in a myTemplate.html file, effectively writing the name of the template twice. If those two names doesn't match Meteor will consider the name of the <template> tag and will ignore the file name. So if you follow this pattern you have to take care of keeping the file name and the template tag name in sync (manually).

We solve this problem using a new the .tpl.jade file extension. With it you can only define one template per file and you don't need to wrap your template in a tag. The template will be named after the file name. We handle special head.tpl.jade and body.tpl.jade templates as expected.

Anonymous helper

This feature is not yet implemented. However, once implemented it could:

if player.score > 10
  p Well done!

It'll be useful for conditions (if, else if and unless) and inside attributes.

See related issue

Unsupported Features

Currently the following Jade features are not supported by meteor-jade.

  • Code
  • Case
  • Filter

Contributing

Contributions are welcome, whether it is for a bug report, a fix or a new functionnality proposition.

Implementation

This package use the Jade lexer to define the grammar, we just add a few customs rules specifics to the Meteor components model. Then we use the Jade parser which returns a syntax tree that we transform to make it compatible with the Meteor format. We finally rely on the Spacebars compiler to generate the JavaScript code sent to the client.

Everything is executed at bundle time.

License

This code is published under the MIT license.

Tests

Use the following command to run the tests:

$ meteor test-packages packages/*

Tips

If you want to buy me a beer, I proudly accept bitcoin tips: 1Jade7Fscsx2bF13iFVVFvcSUhe7eLJgSy

Known bugs

Using Jade in a package

When using Jade in a package you need to lock the version to the latest version manually. See issue #83.

api.use([
  "templating",
  "mquandalle:[email protected]"
], "client");
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].