Jade -> Blade conversion help #170

Closed
ghost opened this Issue Apr 30, 2013 · 5 comments

Projects

None yet

3 participants

@ghost

Hi,

I'm converting from Jade to Blade using ExpressJS as the base Node.js HTTP server, and I'm having a bit of trouble.

Below is a "conversion" list of issues I'm running into which don't necessarily seem apparent from the docs after a few pass-throughs and some trial-n'-error runs, any insights would be helpful!

1) Passing JSON from the Express route to a Javascript "window.data" object.
2) Dynamically including templates passed from the Express route to a Blade file.
3) Dynamically referencing assets passed from the Express route to a Blade file.
4) Underscore templates (this is a Marionette.js app).

Notes:

1) With Jade, I could not dynamically "include" the passed data.templates because they obviously don't support that...it's noted in the comments :)

2) I actually haven't gotten to the Underscore templates yet because I'm still trying to convert the rest of the stuff. It really sucked having to delimit Underscore template code with | AND use standard HTML.

3) I was able to get the "data" object printed as a string, but I can't seem to iterate over it in Blade for the life of me. I'm probably thinking "Jade" and not "Blade".

server.coffee:

res.render 'pages/one/layout',
  data:
    page: 'one'
    js: [
      'js/dynamic_js_1.js' # http://localhost:3000/js/...
      'js/dynamic_js_2.js'
    ]
    templates: [
      'pages/one/templates.jade' # http://localhost:3000/views/pages/one/...
    ]

pages/one/layout.jade:

// shit, Jade.
// each template in data.templates
//   include template

// This worked
script
  window.data = !{JSON.stringify(data)};

// This worked
each assetFile in data.js
  script(src=assetFile)

pages/one/templates.jade:

script(id="no-data", type="text/template")  
  p 
    | No data.

script(id="data", type="text/template")  
  | <div id="<%= obj.id %>">
  |   <p> Data: <%= obj.id %> </p>
  | </div>

js/dynamic_js_1.js:

alert(JSON.stringify(data)); // This alerted stuff!
@bminer
Owner

Closing this issue since it already exists on Stackoverflow.

I'll try to respond to your question there. Thanks!

@bminer bminer closed this May 2, 2013
@bminer
Owner

Posted a comment on Stackoverflow. Please feel free to respond at your convenience. I'd be happy to help. Thanks!

@airtonix

so the question was removed from stack overflow.

@joeytwiddle

Happy 2014! Those SO guys are always removing useful stuff... Someone should re-implement their site in Node+Meteor+Blade+Coffeescript just without the "close question" feature... :)

Anyway I recovered some of what was said:

  • Passing JSON from the Express route to a Javascript "window.data" object. -- looks like you have that one handled.

  • Dynamically including templates passed from the Express route to a Blade file. -- use include keyword.

  • Dynamically referencing assets passed from the Express route to a Blade file. -- what do you mean by this?

  • Underscore templates (this is a Marionette.js app). -- what do you want to do with underscore templates? – BMiner

(Found from http://web.archive.org/web/20130504104405/http://stackoverflow.com/questions/16312307/jade-blade-template-conversion )

Now I read it, I see that it is useless. Archived too early!

Also, here is a page with no answers, but it's a good place to put them when they are found. ;) https://github.com/bminer/node-blade/wiki/Migrating-from-jade-to-blade

@bminer
Owner

@joeytwiddle - Thanks. Yeah, if there are any questions, please feel free to shoot me an email or post to StackOverflow with the node-blade tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment