kirbysayshi / vash

Vash, the 60 billion double-dollar template-maker. Razor syntax, for JavaScript templates
Other
522 stars 60 forks source link

Layout helpers cannot handle empty files (and misreport errors) #46

Closed stimpy77 closed 9 years ago

stimpy77 commented 10 years ago

Being as I'm new to vash (and for that matter nodejs development) I might have overlooked something, but while the vash-express-sample demonstrates using @html.include() without issue in a view, it doesn't work when @html.include() is used in the layout file. I ran into this problem first in my own app and sought to validate that the issue is reproducible in the sample. It is. Perhaps this is by design, or perhaps there is a workaround? The referenced partial is a sometimes-used feature that other layout files might reuse.

500 TypeError: object is not a function
    at C:\Users\jdavis\vash\vash-express-example\node_modules\vash\build\vash.js:575:13
    at Object.vash.loadFile (C:\Users\jdavis\vash\vash-express-example\node_modules\vash\build\vash.js:565:10)
    at View.vash.renderFile [as engine] (C:\Users\jdavis\vash\vash-express-example\node_modules\vash\build\vash.js:571:8)
    at View.render (C:\Users\jdavis\vash\vash-express-example\node_modules\express\lib\view.js:75:8)
    at Function.app.render (C:\Users\jdavis\vash\vash-express-example\node_modules\express\lib\application.js:505:10)
    at ServerResponse.res.render (C:\Users\jdavis\vash\vash-express-example\node_modules\express\lib\response.js:718:7)
    at exports.index (C:\Users\jdavis\vash\vash-express-example\routes\index.js:7:7)
    at callbacks (C:\Users\jdavis\vash\vash-express-example\node_modules\express\lib\router\index.js:162:37)
    at param (C:\Users\jdavis\vash\vash-express-example\node_modules\express\lib\router\index.js:136:11)
    at pass (C:\Users\jdavis\vash\vash-express-example\node_modules\express\lib\router\index.js:143:5)
stimpy77 commented 10 years ago

actually in my case it doesn't work when using it inside the view either. but the sample doesn't reflect the problem so I don't know how to fix. I do have a file named env.vash in same dir and I've tried emptying its contents too

  object is not a function.
  Context:
  2 | @html.block('content', function() {
  3 |
> 4 | @html.include('env', model)    // (tried without ", model" too
  5 |
  6 |
  7 |
    at helpers.include.model (c:\dev\prj\dmk\WebClient\node_modules\vash\build\vash.js:2231:4)
    at Object.vash.loadFile (c:\dev\prj\dmk\WebClient\node_modules\vash\build\vash.js:2072:10)
    at helpers.include (c:\dev\prj\dmk\WebClient\node_modules\vash\build\vash.js:2230:8)
kirbysayshi commented 10 years ago

The error message should be more descriptive, but unfortunately the error is not checked (definitely a bug https://github.com/kirbysayshi/vash/blob/master/build/vash.js#L2230).

The actual problem is that it's not finding the env.vash file. Could you show me what your directory tree looks like?

stimpy77 commented 10 years ago

the file is in the same directory as the file that has the @html.include

stimpy77 commented 10 years ago

I have figured out that the contents of the partial matters. An empty partial fails. <div></div> works though. Clearly it's loading the file fine but expecting its transformed result to be a function--well sure, because I had a block in there that invoked a function that wasn't accessible. And in the case of the sample failing when put into the layout, the referenced partial might be invoking things not available in that scope (?)

<ol class="reasons">
    @model.forEach(function(reason){
        <li>@reason</li>
    })
</ol>

@html.prepend('footer', function(model){
    <text>This is a footer. </text>
})

@html.block('footer', function(){
    <text>It's followed by primary content replaced from deep within. </text>
})

@html.append('footer', function(model){
    <text>Aren't blocks fun? It's the last. </text>
})

This is probably a non-issue. You can close or delete. Thx.

kirbysayshi commented 10 years ago

Well, I think one of the big issues here is that the error is not properly bubbling up. You should have seen this error:

https://github.com/kirbysayshi/vash/blob/master/src/vexports.js#L22

I believe I thought that an empty string was most likely a mistake, but clearly it's not that uncommon to make some empty files as you begin a project. Either way, the error should bubble up.

kirbysayshi commented 10 years ago

@stimpy77 hope you don't mind me rewriting the title, just wanted to have it accurately describe the issue now that we've gotten to the source!

kirbysayshi commented 9 years ago

This should be implemented as of >= 0.8.0!