Closed ericgorr closed 10 years ago
What I suspect from the error (and my code) is that the handlebars file has a parsing error. The file contents should be wrapped in
SC.TEMPLATES["print_template.handlebars"] = SC.Handlebars.compile([content of handlebars file]);
Can you verify that this wrapping actually takes place, and that the content of the handlebars file is not a string? (but should be one?)
I fixed the possible problem with the handlebars handler, so it will now put the contents of the handlebars file as a string. Please let me know if that solves your problem.
I will check out soon. Thank you!
inside of my project folder, is there anything more I need to do other then issue a 'npm update' command? If not, it still does not work.
The code implementing this looks like:
PrintingTemplate.printController = SC.Object.create({
debug: (SC.buildMode == 'debug'),
header: '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' +
'<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>' +
'<link rel="stylesheet" href="' + sc_static('print_css') + '">' +
'</head>\n<body>\n',
footer: '</body></html>',
view: SC.TemplateView.create(),
renderTemplate: function(content, templateName) {
var view = this.get('view'),
data,
output,
template = SC.TEMPLATES[templateName];
view.set('value', content);
data = { view: view, isRenderData: true };
output = template(content, { data: data });
return output;
},
print: function(pages) {
var data,
output,
iframe,
doc,
body,
debug = this.get('debug');
//console.log(output);
iframe = document.createElement('iframe');
iframe.setAttribute('style'," z-index: 10; position: absolute; left: 0; right: 0; top: 0; bottom: 0; width: 100%; background-color: white; height: 100%;");
body = document.getElementsByTagName('body')[0];
body.appendChild(iframe);
doc = iframe.contentWindow.document;
doc.open();
doc.write( this.get( 'header' ) );
pages.forEach( function( page ) {
doc.write( this.renderTemplate( page.content, page.templateName ) );
}, this);
doc.write(this.get('footer'));
doc.close();
setTimeout( function() {
iframe.contentWindow.print();
//console.log("done printing");
body.removeChild(iframe);
}, 500);
},
printContent: function() {
var titleContent = PrintingTemplate.get( 'titleContent' );
var bodyContent = PrintingTemplate.get( 'bodyContent' );
var bodyTable = $( '<div/>' ).append( bodyContent ).find( 'table' ).get();
var bodyTableString = $( bodyTable[0] ).clone().wrap( '<div>' ).parent().html();
this.print( [ { content: { title_content: titleContent, body_content: bodyTableString }, templateName: 'print_template' } ] );
},
});
sadly npm update does not work (yet). So the best way is to completely remove the node_modules directory and do npm install.
What I am most interested in is the actual content of the .handlebars file as it is included in the browser. You should be able to find it in Chrome's Resources tab.
Ok, I did npm install and it still does not appear to work.
Here is the content, as found in the Resources tab:
<div>
<div>
<h2>
{{title_content}}
</h2>
</div>
<div>
<pre>
{{{body_content}}}
</pre>
</div>
</div>
Because of a complete rewrite of the nodejs buildtools, and this issue being related to the old version, I am closing this issue for now. The current buildtools do not yet support templates yet, but I am still closing this issue for now. Feel free to reopen if you think it is necessary.
The current opinion of the core team is that template views are harmful to the SC community, and are in the process of being deprecated. If that remains the case, support for Handlebars in the new build tools should not be actively prevented, but would have to be implemented, distributed and maintained outside of the core frameworks. Note however that there is some dissension from some stakeholders (@fairbanksg) so this isn't a certainty yet.
https://github.com/ericgorr/myproject.git
Here is the output from the JS Console:
Here is the output from the terminal: