bminer / node-blade

Blade - HTML Template Compiler, inspired by Jade & Haml
Other
320 stars 28 forks source link

Jade -> Blade conversion help #170

Closed ghost closed 11 years ago

ghost commented 11 years ago

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 commented 11 years ago

Closing this issue since it already exists on Stackoverflow.

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

bminer commented 11 years ago

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

airtonix commented 10 years ago

so the question was removed from stack overflow.

joeytwiddle commented 10 years ago

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:

(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 commented 10 years ago

@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.