bminer / node-blade

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

use D3.js within Express and Blade Middleware #168

Closed nkhine closed 11 years ago

nkhine commented 11 years ago

Hello,

I am trying to render a blade template on the server as i have to generate quite a complex SVG and wanted to do this on the server first, here is what I have so far:

svg.blade

include "../layout/layout.blade"
replace block page
    #map

then in my ./routes/svg.js

var d3 = require('d3')
 ,blade = require('blade');

exports.blade = function(req, res, next){
  var self = this

  self.svg = d3.select("#svg").append("svg")
    .attr("width", "100%")
    .attr("height", "89%")

  // Add a rect
  self.svg.append("rect")
    .attr("class", "background")
    .attr("width", width)
    .attr("height", height)

  res.render('svg.blade');
  //blade.compile(self.svg, function(err, tmpl) {
    //    tmpl('svg.blade', function(err, html) {
      //        console.log(html);
      //    });
      //});
};

i am following this example https://groups.google.com/d/msg/d3-js/JyldAkWkTvI/n8thanJeGvAJ of using D3.js with Node.js

any advice on how i can do this much appreciated.

bminer commented 11 years ago

It looks like this is a client-side library. According to the example on Google Groups, the HTML generated by D3 is stored in window.document.innerHTML. You can then pass that into your Blade template.

Closing this issue. You may have better luck posting this question on StackOverflow. Integrating other libraries with Blade is slightly outside the scope of the Github issue tracker.

Thanks.