Code Monkey home page Code Monkey logo

meteor-jade's Introduction

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");

meteor-jade's People

Contributors

avalanche1 avatar caglarcem avatar kristerv avatar mquandalle avatar orbyt avatar pem-- avatar sbking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meteor-jade's Issues

upgrade v0.2.2 to v0.2.4.... some rendering issues with new lines

Hey there,

I have a chunk of jade code that looks like this :

            p 
              | something 
              a(href='link', target="_blank") 
                b boldtext, 
              | another line

On v0.2.2, it renders everything in a sentence without line breaks. However, on 0.2.4, somehow line breaks are appearing between "| something", "a(href ..." and "| another line".

jade not playing nice with coffeescript

I'm trying to get the basic meteor create app template running with both coffeescript and jade. I'm using meteor's coffeescript package. I have translated the standard app.js file to an app.coffee and the app.html file to app.jade.

The problem is that with app.coffee and app.jade the coffeescript sees Template.hello as undefined. This runs fine for html+coffee and for jade+js so my code is correct (here it is in a gist though ). It also works if I include both html and jade with the coffeescript file.

The error makes sense if meteor is compiling these in the following order: html, coffee, jade, js . However, I'm new to meteor and do not know how to tweak the order in which it runs everything.

Several If Conditions

Hello,

Is there a way to do something like that?

if retention = 1 or retention = 3 or retention = 21
    p Your retention is equal to 1, 3 or 21

Or maybe would it better to do the logic inside my helper?

if retention = "accepted"
    p Your retention is equal to 1, 3 or 21

Strange whitespace issue

Either of the following:

with address
  span= streetAddress
  br
  span= addressLocality
  span= addressRegion
  span= postalCode
  span= addressCountry

or:

template( name='address' )
  span= streetAddress
  br
  span= addressLocality
  span= addressRegion
  span= postalCode
  span= addressCountry

Produce HTML with no spaces between the <span> tags. However, if you wrap them in an outer span, the line breaks are all preserved:

with address
  span
    span= streetAddress
    br
    span= addressLocality
    span= addressRegion
    span= postalCode
    span= addressCountry

I'm not sure if this is an intentional feature to allow tags with no whitespace between them or a bug, but is there a solution that doesn't require wrapping these tags with an extraneous container?

interpolation and jade tags

i've noticed various cases where jade recommended tag doesn't work

this example is a bit edge casey but have seen in other simpler cases too.

    script. 
        var tr="blah #{ trans this.text }";
# ->  tr: blah #{ trans this.text } 

    script. 
        var tr="blah {{ trans this.text }}";

#-> calls my trans method correctly and gets result

The attribute brackets

For now jade only supports () for the attribute brackets. I would prefer to use [] since it's more coherent with jQuery and CSS selectors.

As of issue pugjs/pug#1307, jade core may consider the change for v2, but not until then. Since this meteor-jade package is quite new, I wonder if you have any objection about the implementation of both () and [] syntax support?

UI.body.contentParts does not exist anymore

I receive the following error:

Uncaught TypeError: Cannot read property 'push' of undefined localhost:3000/NewRelease.jade.js?711b990fdee4a4f3d51b337f8ed4d458bcd67d35:2

Seems like the UI.body isn't found. The code hangs here in the browser:

(function(){
 UI.body.contentParts.push(UI.Component.extend({render: (function() {

Usage with Autoform?

I seem to be having some troubles getting autoform working with Jade, would love to be able to use both. Writing something like this: +autoForm(schema=signupFormSchema,type="method",meteormethod= "signupUser")
+afFieldInput(name="Username")
returns an "Expected space ...ema= signupFormSchema, type= "method"" error. Is using autoform possible with Jade? If so, I guess I'll just have to dig harder then. I'll keep poking at it either way.

constant block tags are not recognized

To prevent reactivity from taking place on certain parts of jade code, I have read you can next the code inside a constant block.

But in jade when trying to use the constant block I get an error:

constant
  #full-editor !{researchThread.draftHTML}

Build errors trying to add meteor-jade with Meteorite

Here's what I see in my current project and in a simple dummy project just to use as a control.

$ mrt add jade
✓ jade
    tag: https://github.com/mquandalle/meteor-jade.git#v0.1.3

Done installing smart packages

Stand back while Meteorite does its thing

Done installing smart packages

Ok, everything's ready. Here comes Meteor!

compileJade: updating npm dependencies -- jade, markdown...
=> Errors while scanning packages:

While building package `jade`:
packages/compileJade/plugin/compiler.js:126: HTML is not defined (compiling tests/tests.jade)
  at _.extend.visitTag (packages/compileJade/plugin/compiler.js:126)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:90)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:74)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:84)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:74)
  at _.extend.compile (packages/compileJade/plugin/compiler.js:21)
  at sourceHandler (packages/compileJade/plugin/handler.js:11)


While building plugin `compileJade` in package `jade`:
error: no such package: 'html-tools'
error: no such package: 'spacebars-compiler'

I don't know if this worked before. It is the first time I'm trying to add it with mrt. I'll now try adding it manually to my project.

HTML attribute using helper with text

neither

div(class='large-##{this.input_size} columns left')

or

div(class='large-#'+this.input_size+' columns left')

works

Please tell me if there is anyway to do it.

each x in y loop

Currently we use each to loop over a list or a cursor. each works by setting the context (this) to the current element inside the block of content. If you want to access a variable outside of this context you have to use the ../ notation.

For some cases this may be a non-intuitive syntax. For instance consider a table where each cell has a x and an y coordinate. Currently we would do:

Template.table.helpers({size: _.range(10)});
template(name="table")
  table
    each size
      tr
        each size
          td #{..} #{.}

It would be more natural to use a for element in list loop to avoid the dot notation:

template(name="table")
  table
    for x in size
      tr
        for y in size
          td #{x} #{y}

Any thought?

Using the dynamic named route helper in Iron Router with Jade

When defining a route with an :_id field using iron-router

  @route 'postPage',
    path: '/posts/:_id'
    data: -> 
      Posts.findOne @params._id

and adding the route into the jade page like so:

    a.discuss.btn(href="{{pathFor 'postPage'}}") Discuss

does not work. What happens is jade just gets rid of the whole href attribute and the button does not link to anywhere. In the html there is no more href attribute. It is supposed to put in the path for the postPage + id of the post appended.

It seems like an issue with the path having an _id field in it. When I remove the _id filed, it puts in the correct route but I need the _id field for dynamic routing

UPDATE:

I found a way to make it work, like this:

a.discuss.btn(href="{{pathFor 'postPage' _id=this._id}}") Discuss 

But I in the book Discover Meteor, it says Iron router should automatically detect that the route specified requires an id field, so it checks the data context in the spot it is located and adds the _id field if neccessary. So
1)

    a.discuss.btn(href="{{pathFor 'postPage'}}") Discuss

is equivalent to
2)

  a.discuss.btn(href="{{pathFor 'postPage' _id=this._id}}") Discuss 

Using the second way works right now but the first method does not.

Cannot read property '1' of null (after update to tag 0.2.3)

Good day!

Today I updated meteor-jade to the latest commit. The application crashed with the errors below. Didn't matter if I commented the contents of the files out.
When I reverted back to tag 0.2.2 everything ran as normal.

While building the application:                                          
<runJavaScript-39>:32:53: Cannot read property '1' of null (compiling cli
ent/views/viewtype/manage/manage-survey/templates/manage-survey-create.ja
de)                                                                      
  at unwrap (<runJavaScript-39>:32:53)                                   
  at Object.Lexer.builtInComponents (<runJavaScript-39>:43:16)           
  at Object.Lexer.next (<runJavaScript-39>:65:15)                        
  at Object.Lexer.lookahead (/home/codio/.meteorite/packages/jade/mquanda
lle/meteor-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.co
mpileJade.os/npm/compileJade/plugin/node_modules/jade/lib/lexer.js:114:46
)                                                                        
  at Parser.lookahead (/home/codio/.meteorite/packages/jade/mquandalle/me
teor-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJ
ade.os/npm/compileJade/plugin/node_modules/jade/lib/parser.js:100:23)    
  at Parser.peek (/home/codio/.meteorite/packages/jade/mquandalle/meteor-
jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJade.o
s/npm/compileJade/plugin/node_modules/jade/lib/parser.js:77:17)          
  at Parser.block (/home/codio/.meteorite/packages/jade/mquandalle/meteor
-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJade.
os/npm/compileJade/plugin/node_modules/jade/lib/parser.js:685:30)        
  at Parser.tag (/home/codio/.meteorite/packages/jade/mquandalle/meteor-j
ade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJade.os
/npm/compileJade/plugin/node_modules/jade/lib/parser.js:806:26)          
  at Parser.parseTag (/home/codio/.meteorite/packages/jade/mquandalle/met
eor-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJa
de.os/npm/compileJade/plugin/node_modules/jade/lib/parser.js:719:17)     
  at Parser.parseExpr (/home/codio/.meteorite/packages/jade/mquandalle/me
teor-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJ
ade.os/npm/compileJade/plugin/node_modules/jade/lib/parser.js:188:21)    
  at Parser.parseExpr (/home/codio/.meteorite/packages/jade/mquandalle/me
teor-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJ
ade.os/npm/compileJade/plugin/node_modules/jade/lib/parser.js:227:21)    
  at Parser.block (/home/codio/.meteorite/packages/jade/mquandalle/meteor
-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJade.
os/npm/compileJade/plugin/node_modules/jade/lib/parser.js:689:25)        
  at Parser.tag (/home/codio/.meteorite/packages/jade/mquandalle/meteor-j
ade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJade.os
/npm/compileJade/plugin/node_modules/jade/lib/parser.js:806:26)          
  at Parser.parseTag (/home/codio/.meteorite/packages/jade/mquandalle/met
eor-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJa
de.os/npm/compileJade/plugin/node_modules/jade/lib/parser.js:719:17)     
  at Parser.parseExpr (/home/codio/.meteorite/packages/jade/mquandalle/me
teor-jade/38220544108cdc30e2e53f40481dce0b594d6f31/.build/plugin.compileJ 

... etc

markdown "automatic links"

Expected end tag error in markdown "automatic links":

% meteor --version
Release 0.8.0
% meteor
...
While building the application:
<runJavaScript-6>:130:11: Expected "[email protected]" end tag
...t <[email protected]>
                        ^ (compiling client/views/contact.jade)
  at [object Object].Scanner.fatal (<runJavaScript-6>:130:11)
  at HTMLTools.Parse.getContent (<runJavaScript-6>:3351:19)
  at Object.HTMLTools.parseFragment (<runJavaScript-6>:3219:14)
  at Object.Spacebars.parse (<runJavaScript-20>:829:24)
  at [object Object]._.extend.parseText (<runJavaScript-21>:293:22)
  at [object Object]._.extend.visitText (<runJavaScript-21>:283:28)
  at [object Object]._.extend.visitNode (<runJavaScript-21>:236:39)
  at [object Object]._.extend.visitBlock (<runJavaScript-21>:220:24)
  at [object Object]._.extend.visitNode (<runJavaScript-21>:230:51)
  at [object Object]._.extend.visitBlock (<runJavaScript-21>:220:24)
  at [object Object]._.extend.visitNode (<runJavaScript-21>:230:51)
  at [object Object]._.extend.visitBlock (<runJavaScript-21>:220:24)
  at [object Object]._.extend.compile (<runJavaScript-21>:168:10)
  at sourceHandler (<runJavaScript-21>:460:46)


=> Your application has errors. Waiting for file change.

Template inclusion helper should accept keyword arguments

+myTemplate arg1=arg1 arg2=arg2

does not work:

While building the application:
<runJavaScript-6>:130:11: Expected space
{{>myTemplate arg1=arg1,}}

Per the Blaze wiki:

"New: (Notably, in Blaze, keyword arguments to inclusion or block helpers are bundled into a single object which becomes the new data context)"

The example given on the Wiki happens to be a dynamic template rendering pattern, which makes this seem more complicated than it actually is, but it's clear that keyword arguments are bundled into the data context and are accessible from the template.

As expected, the following works:

{{> myTemplate arg1=arg1 arg2=arg2}}

Escaping

It would be nice to escape variables in jade style, like this !{ variable } instead of {{{ variable }}}.

Jade stops working with Meteor-0.8.3

Here's the CLI's output:

While building package `jade`:
packages/compileJade/plugin/compiler.js:155: Spacebars is not defined (compiling tests/match.jade)
  at _.extend.parseText (packages/compileJade/plugin/compiler.js:155)
  at packages/compileJade/plugin/compiler.js:212
  at Array.forEach (native)
  at Function._.each._.forEach (packages/underscore/underscore.js:105)
  at _.extend.visitAttributes (packages/compileJade/plugin/compiler.js:205)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:81)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:73)
  at _.extend.compile (packages/compileJade/plugin/compiler.js:21)
  at sourceHandler (packages/compileJade/plugin/handler.js:11)


/usr/local/lib/node_modules/meteorite/lib/command.js:41
            throw "Command exited with " + code + "/" + signal;
                                                      ^
Command exited with 1/null

Dynamic Helper

Hey I am sorry if I might me doing this wrong but I have been trying to get dynamic helper to work.

What I am doing is have a helper named attrs return an object {type: 'text', placeholder: 'hello'}

to the template that has input($dyn = attrs)

If this is not the way to use dynamic template, please point me to the right way.

parameters and helper functions

I would like to make a component that will provide translated tooltips
so I have a Template helper of trans(sometext)
but how to pass this to a jade component?

eg using bootstrap tooltip where title=XX is needed

template(name="ttip")
    a(href="#" rel="tooltip" title=trans(this.text) )
        = this.text

gives error:

<runJavaScript-25>:130:11: Expected identifier, number, string, boolean, or null
{{trans(this.text)}}

i tried various other combos

title=this.text # ok
title=trans this.text #no good

even trying a temporary javascript variable:

template(name="ttip")
    script. 
        var tr="blah {{ trans this.text }}";
        console.log("tr:", tr)
    a(href="#" rel="tooltip" title=this.text )
        = this.text

in this case the var tr gets set but i guess its a different this in scope.

eventually i did this hack:

a(href="#" rel="tooltip" title=this.text.trans )

and monkeypatching a trans method onto my string class. I guess it works, and isn't too ugly, but would like to know a more jade way to do this.

With statement

I just upgraded to Meteor 0.8. Previously I was doing that:

{{#with alert}}
div.alert(class="alert-{{type}}")
    div.grid
        div.g-row
            div.g-c12
                span.icon
                {{message}}
                span.close
{{/with}}

Is there a way to do this with meteor-jade?

meteor-jade doesn't work with latest meteor 0.8.3

While building package jade:

packages/compileJade/plugin/compiler.js:155: Spacebars is not defined (compiling tests/match.jade)
  at _.extend.parseText (packages/compileJade/plugin/compiler.js:155)
  at packages/compileJade/plugin/compiler.js:212
  at Array.forEach (native)
  at Function._.each._.forEach (packages/underscore/underscore.js:105)
  at _.extend.visitAttributes (packages/compileJade/plugin/compiler.js:205)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:81)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:73)
  at _.extend.compile (packages/compileJade/plugin/compiler.js:21)
  at sourceHandler (packages/compileJade/plugin/handler.js:11)

blaze-refactor with meteor 8.1.3

When using blaze refactor with meteor 8.1.3 there is an error preventing startup.

Cannot call method 'apply' of undefined (compiling tests/match.jade)

I need to make dynamic attribute work in my app. Please help.

Helpers didnt work.

When I try call helper, it causes an error.

Your app is crashing. Here's the latest log.
=> Errors prevented startup:
While building the application:
packages/html-tools/scanner.js:45: Expected identifier, number, string, boolean, or null
{{getTime(date)}}
     ^ (compiling client/views/blocks/chat/chat.jade.html)
UI.registerHelper('getTime', function(time) {
    return time ? moment(time).format('L / HH:mm') : null;
});
each messages
    p
        a(href='/users/#{username}')
            strong.text-info #{username}
                | :  
                =message
            p.text-right.text-muted= getTime(date)

Error parsing of iframe in v0.2.2

v0.2.2 somehow thinks iframe is {{>if rame ...}}

Sample Code:

iframe(width="530" height="352" src="https://www.youtube.com/embed/M35XqOLDKZY" frameborder="0" allowfullscreen="")

Error:

packages/html-tools/scanner.js:45: Expected space
{{>if rame(width="530", height...
          ^ (compiling client/views/shared/modals.jade)
  at Scanner.fatal (packages/html-tools/scanner.js:45)
  at error (packages/spacebars-compiler/templatetag.js:218)
  at expected (packages/spacebars-compiler/templatetag.js:222)
  at Function.TemplateTag.parse (packages/spacebars-compiler/templatetag.js:286)
  at _.extend.visitMixin (packages/compileJade/plugin/compiler.js:110)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:89)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:73)

UI.elseBlock

at the moment +UI.elseBlock doesn't work.

Although {{>UI.elseBlock}} is working fine

Inline JavaScript expressions

It would be useful to be able to define some kind of "anonymous helpers" like this:

if player.score > 10
  p Well done!

As far as I know, it's not yet possible to define this kind of things in the Spacebars abstract tree. So maybe it's more a Spacebars feature? @dgreensp?

array values

is there a way to access array items in meteor/jade ?

there seem to be some handlebars/spacebars access syntax that isn't supported by jade
array elements in handlebars can be used like:

items.[0]

see this SO question

so within jade files i can use the handlebars escape to use this syntax like:

{{ items.[0] }}

however, when passing a value to a jade helper like an tag...

a(href=item.[0]) blah

the same syntax fails.

is there another way to access array items, or use the raw handlebars syntax in helpers?

Support for case statment

It would be good if you would implement jade's case statment support

template(name='main')
  case friends
    when 0
      p you have no friends
    when 1
      p you have a friend
    default
      p you have #{friends} friends

Can't compile buffered code

I'm trying to output some info using buffered code:

.info= JSON.stringify(this)

But I'm getting:

<runJavaScript-26>:130:11: Expected identifier, number, string, boolean, or null
{{JSON.stringify(this)}}
                ^ (compiling chat.jade)

Uncaught Error: Expected null or template in return value from inclusion function, found:

I'm getting a weird error when using meteor-jade.

Uncaught Error: Expected null or template in return value from inclusion function, found:

I have the following in my chat.jade file:

head
  title Chat

body
  +chats

template(name="messages")
  ul.messages
    each message in messages
      li= message.body

template(name="chats")
  .chats
    +messages

  form
    input(placeholder="Type to chat...")
    button Send

The error occurs when I have +messages called from inside my chats template.

If I remove that line I don't get an error.

Other template names work.

I also have a template attribute named messages, but that was working fine using Handlebars, so not sure why it would fail in Jade.

Args across multiple lines

Hi! Can component args be set across multiple lines?

This code works:

+autoForm(collection="Goals" id="updateGoalForm" type="update" template="bootstrap3-horizontal"  role="form")

But this causes "Unexpected identifier" error:

+autoForm(collection="Goals" id="updateGoalForm" type="update"
  template="bootstrap3-horizontal"  role="form")

Iron Router Support?

Is Iron Router supported for this? I've been trying to use it and have been unsuccessful in getting the layouts to work so far, using both the shark and cmather branches of Iron Router. I'm running Meteor from the shark branch as well.

Unknow tag: template

I'm getting the following error message:

While building the application: packages/compileJade/plugin/compiler.js:296:
Unknow tag: template on line 5 (compiling test.jade)

Jade FIle

head
    title test
    body asdf

        template(name='hello')
            input(type='button', value='Click')

More Logs

  at _.extend.throwError (packages/compileJade/plugin/compiler.js:296)
  at _.extend.visitTag (packages/compileJade/plugin/compiler.js:131)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:89)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:73)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:83)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:73)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:83)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:73)
  at _.extend.compile (packages/compileJade/plugin/compiler.js:21)
  at sourceHandler (packages/compileJade/plugin/handler.js:11)

Thank!

Upgrading to Meteor 0.8.3

After upgrading to Meteor 0.8.3 I get the following error

While building package `jade`:
packages/compileJade/plugin/compiler.js:155: Spacebars is not defined (compiling tests/match.jade)
  at _.extend.parseText (packages/compileJade/plugin/compiler.js:155)
  at packages/compileJade/plugin/compiler.js:212
  at Array.forEach (native)
  at Function._.each._.forEach (packages/underscore/underscore.js:105)
  at _.extend.visitAttributes (packages/compileJade/plugin/compiler.js:205)
  at _.extend.visitNode (packages/compileJade/plugin/compiler.js:81)
  at _.extend.visitBlock (packages/compileJade/plugin/compiler.js:73)
  at _.extend.compile (packages/compileJade/plugin/compiler.js:21)
  at sourceHandler (packages/compileJade/plugin/handler.js:11)

Can i use jade case statement in meteor?

template(name='home')
  - var friends = 10
  case friends
    when 0
      p you have no friends
    when 1
      p you have a friend
    default
      p you have #{friends} friends
=> Errors prevented startup:

While building the application:
<runJavaScript-42>:245:39: Property 'visitWhen' of object [object Object] is not a function

Template inside each loop not working

I have something like this:

<template name="postList">
  <div class="post-list">
    {{#each posts}}
      {{> postItem}}
    {{/each}}
  </div>
</template>

when turned into:

template(name='postList')
  .post-list
    each posts
      +postItem

The list items don't display anymore.

Am I doing something wrong?

multiple lines of piped text

p
  | foo
  | bar

Produces:

<p>foobar</p>

Which I don't think is correct. The native jade compiler produces:

<p>
  foo
  bar
</p>

It would be nice if a space or a newline could be added automatically. Currently, the workaround is to add extra indentation after the second pipe which is a little annoying. Can this be fixed?

When parsing warning reported, the filename is null

=> Started proxy.
=> Started MongoDB.
Warning: missing space before text for line 9 of jade file "null"
=> Meteor 0.7.1.2 is available. Update this project with 'meteor update'.
=> Started your app.

The jade file name is 'main.jade.html'

using yield ?

with handlebars you can use

   {{> yield}}

to have a layout wrap a component, i was wondering if theres a similar syntax for meteor-jade.

unnamed parameters to components

i noticed you can call a component with non-named params

+ttip arg1, arg2, arg3, key1=val1, key2=val2

but how do i pick up those params inside my component?

template(name="ttip" arg1 arg2 )
# will fail on compilation
While building the application:
<runJavaScript-40>:452:11: Templates must only have a "name" attribute 
on line 4 (compiling client/komik/panels/kcap.jade)

i tried this.args[0] but not sure what else to look at!

Expected space error

i've come across this error on a couple of places, and now just in trying to include the accounts-ui in a page.

in this case the error is caused by

+loginButtons(align='right')
While building the application:
<runJavaScript-5>:130:11: Expected space
...Buttons align='right')}}
                        ^ (compiling client/layouts/layout.jade)
  at [object Object].Scanner.fatal (<runJavaScript-5>:130:11)
  at error (<runJavaScript-19>:569:13)
  at expected (<runJavaScript-19>:573:5)
  at Function.TemplateTag.parse (<runJavaScript-19>:631:9)
  at [object Object]._.extend.visitMixin (<runJavaScript-20>:257:37)
  at [object Object]._.extend.visitNode (<runJavaScript-20>:236:39)
  at [object Object]._.extend.visitBlock (<runJavaScript-20>:220:24)
  at [object Object]._.extend.visitNode (<runJavaScript-20>:230:51)
  at [object Object]._.extend.visitBlock (<runJavaScript-20>:220:24)
  at [object Object]._.extend.visitNode (<runJavaScript-20>:230:51)
  at [object Object]._.extend.visitBlock (<runJavaScript-20>:220:24)
  at [object Object]._.extend.visitNode (<runJavaScript-20>:230:51)
  at [object Object]._.extend.visitBlock (<runJavaScript-20>:220:24)
  at [object Object]._.extend.visitNode (<runJavaScript-20>:230:51)
  at [object Object]._.extend.visitBlock (<runJavaScript-20>:220:24)
  at [object Object]._.extend.visitNode (<runJavaScript-20>:230:51)
  at [object Object]._.extend.visitBlock (<runJavaScript-20>:220:24)
  at [object Object]._.extend.compile (<runJavaScript-20>:168:10)
  at sourceHandler (<runJavaScript-20>:478:46)

also came across the issue here where RAIX points the issue to being a jade problem.
gadicc/meteor-famous-views#6

blaze-refactor branch - error with dynamic attributes.

When trying to use dynamic attributes, I get the following error:

Exception from Deps recompute function: Error: The basic HTML.TransformingVisitor does not support foreign objects in attributes.  Define a custom visitAttributes for this case.
    at HTML.TransformingVisitor.def.visitAttributes (http://localhost:3000/packages/htmljs.js?fcf2660be84fbc0c33b97ee8932dbd46612f3566:212:13)
    at Blaze.HTMLJSExpander.def.visitAttributes (http://localhost:3000/packages/blaze.js?ce45a8e727ecde8642e599cbb8eb3f52cea9ba4b:1897:63)
    at Object.Blaze._expandAttributes (http://localhost:3000/packages/blaze.js?ce45a8e727ecde8642e599cbb8eb3f52cea9ba4b:1919:32)
    at updateAttributes (http://localhost:3000/packages/blaze.js?ce45a8e727ecde8642e599cbb8eb3f52cea9ba4b:1369:35)
    at http://localhost:3000/packages/blaze.js?ce45a8e727ecde8642e599cbb8eb3f52cea9ba4b:1738:16
    at Object.Blaze.withCurrentView (http://localhost:3000/packages/blaze.js?ce45a8e727ecde8642e599cbb8eb3f52cea9ba4b:1963:12)
    at viewAutorun (http://localhost:3000/packages/blaze.js?ce45a8e727ecde8642e599cbb8eb3f52cea9ba4b:1737:18)
    at Deps.Computation._compute (http://localhost:3000/packages/deps.js?d9b2b2601bdab0f57291b38e7974a7190b8aac01:214:36)
    at new Deps.Computation (http://localhost:3000/packages/deps.js?d9b2b2601bdab0f57291b38e7974a7190b8aac01:148:10)
    at Object.Deps.autorun (http://localhost:3000/packages/deps.js?d9b2b2601bdab0f57291b38e7974a7190b8aac01:362:11) 

Here is my smart.json:

{
  "meteor": {
    "git": "https://github.com/meteor/meteor.git",
    "branch": "blaze-refactor"
  },
  "packages": {
    "jade": {
      "git": "https://github.com/mquandalle/meteor-jade",
      "branch": "blaze-refactor"
    },
    "iron-layout": {
      "git": "https://github.com/EventedMind/iron-layout.git",
      "branch": "master"
    },
    "iron-router": {
      "git": "https://github.com/EventedMind/iron-router.git",
      "branch": "feature/iron-layout"
    },
    "underscore-string-latest": {}
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.