sproutcore / build-tools

SproutCore Build Tools
12 stars 7 forks source link

Build Tool not working with SC.TemplateView #5

Closed ericgorr closed 10 years ago

ericgorr commented 11 years ago

https://github.com/ericgorr/myproject.git

Here is the output from the JS Console:

Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8000/printing_template/printing_template/templates/print_template.handlebars". printing_template:32

Uncaught SyntaxError: Unexpected token < print_template.handlebars:1

print action ready_state.js:12

Uncaught TypeError: undefined is not a function printController.js:22
    PrintingTemplate.printController.SC.Object.create.renderTemplate printController.js:22
    (anonymous function) printController.js:49
    PrintingTemplate.printController.SC.Object.create.print printController.js:48
    PrintingTemplate.printController.SC.Object.create.printContent printController.js:69
    PrintingTemplate.ReadyState.SC.State.extend.actionPrint ready_state.js:14
    SC.State.SC.Object.extend.tryToHandleEvent statechart.js:1740
    SC.StatechartManager.sendEvent statechart.js:3333
    SC.RootResponder.SC.Object.extend.sendAction core_foundation.js:13501
    SC.ButtonView.SC.View.extend._runAction desktop.js:2935
    SC.ButtonView.SC.View.extend._action desktop.js:2917
    SC.ButtonView.SC.View.extend.mouseUp desktop.js:2803
    SC.Object.tryToPerform runtime.js:7719
    SC.Pane.SC.View.extend.sendEvent core_foundation.js:10635
    (anonymous function) core_foundation.js:13644
    SC.run runtime.js:13318
    SC.RootResponder.SC.Object.extend.sendEvent core_foundation.js:13638
    SC.RootResponder.SC.Object.extend.mouseup core_foundation.js:14875
    SC.mixin.handle core_foundation.js:4288
    listener core_foundation.js:4445

GET http://localhost:8000/printing_template/printing_template/print_css 404 (Not Found) printController.js:46
    PrintingTemplate.printController.SC.Object.create.print printController.js:46
    PrintingTemplate.printController.SC.Object.create.printContent printController.js:69
    PrintingTemplate.ReadyState.SC.State.extend.actionPrint ready_state.js:14
    SC.State.SC.Object.extend.tryToHandleEvent statechart.js:1740
    SC.StatechartManager.sendEvent statechart.js:3333
    SC.RootResponder.SC.Object.extend.sendAction core_foundation.js:13501
    SC.ButtonView.SC.View.extend._runAction desktop.js:2935
    SC.ButtonView.SC.View.extend._action desktop.js:2917
    SC.ButtonView.SC.View.extend.mouseUp desktop.js:2803
    SC.Object.tryToPerform runtime.js:7719
    SC.Pane.SC.View.extend.sendEvent core_foundation.js:10635
    (anonymous function) core_foundation.js:13644
    SC.run runtime.js:13318
    SC.RootResponder.SC.Object.extend.sendEvent core_foundation.js:13638
    SC.RootResponder.SC.Object.extend.mouseup core_foundation.js:14875
    SC.mixin.handle core_foundation.js:4288
    listener core_foundation.js:4445

Here is the output from the terminal:

ericgorr@Glamdring ~/d/s/myproject> node myproject_node.js
3 Jun 18:54:24 - Building app: printing_template
Server started on http://localhost:8000
3 Jun 18:54:26 - dirname for file frameworks/sproutcore/frameworks/desktop/resources/menu_item_view.css: printing_template/sproutcore/desktop
3 Jun 18:54:26 - isSaving? undefined
WARNING: printing_template/sproutcore/desktop/foundation:blank.gif referenced in frameworks/sproutcore/frameworks/desktop/resources/menu_item_view.css but was not found.
3 Jun 18:54:26 - returning rewritten staticurl: url('printing_template/sproutcore/desktop/foundation:blank.gif')
3 Jun 18:54:26 - dirname for file frameworks/sproutcore/frameworks/desktop/resources/menu_item_view.css: printing_template/sproutcore/desktop
3 Jun 18:54:26 - isSaving? undefined
WARNING: printing_template/sproutcore/desktop/foundation:blank.gif referenced in frameworks/sproutcore/frameworks/desktop/resources/menu_item_view.css but was not found.
3 Jun 18:54:26 - returning rewritten staticurl: url('printing_template/sproutcore/desktop/foundation:blank.gif')
3 Jun 18:54:27 - dirname for file frameworks/sproutcore/themes/ace/resources/progress/ace/progress.css: printing_template/sproutcore/themes/ace
3 Jun 18:54:27 - isSaving? undefined
WARNING: printing_template/sproutcore/themes/ace/progress_view_indeterminate_content.png referenced in frameworks/sproutcore/themes/ace/resources/progress/ace/progress.css but was not found.
3 Jun 18:54:27 - returning rewritten staticurl: url('printing_template/sproutcore/themes/ace/progress_view_indeterminate_content.png')
3 Jun 18:54:27 - dirname for file frameworks/sproutcore/frameworks/foundation.js: printing_template/sproutcore/foundation
3 Jun 18:54:27 - isSaving? undefined
3 Jun 18:54:27 - returning rewritten staticurl: 'printing_template/sproutcore/foundation/blank.gif'
3 Jun 18:54:28 - dirname for file apps/printing_template/controllers/printController.js: printing_template/printing_template
3 Jun 18:54:28 - isSaving? undefined
WARNING: printing_template/printing_template/print_css referenced in apps/printing_template/controllers/printController.js but was not found.
3 Jun 18:54:28 - returning rewritten staticurl: 'printing_template/printing_template/print_css'
Proxying /favicon.ico
3 Jun 18:54:28 - done reading data from request, calling onEnd
3 Jun 18:54:28 - sending proxy request...
ERROR: "connect ECONNREFUSED" for proxy request on localhost:5984
Proxying /printing_template/printing_template/print_css
3 Jun 18:54:31 - done reading data from request, calling onEnd
3 Jun 18:54:31 - sending proxy request...
ERROR: "connect ECONNREFUSED" for proxy request on localhost:5984
Proxying /favicon.ico
3 Jun 18:54:31 - done reading data from request, calling onEnd
3 Jun 18:54:31 - sending proxy request...
ERROR: "connect ECONNREFUSED" for proxy request on localhost:5984
mauritslamers commented 11 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?)

mauritslamers commented 11 years ago

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.

ericgorr commented 11 years ago

I will check out soon. Thank you!

ericgorr commented 11 years ago

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' } ] );
  },
});
mauritslamers commented 11 years ago

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.

ericgorr commented 11 years ago

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

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.

dcporter commented 10 years ago

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.