Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require('file.vash') from within a template? #7

Closed
kirbysayshi opened this issue May 9, 2014 · 7 comments
Closed

require('file.vash') from within a template? #7

kirbysayshi opened this issue May 9, 2014 · 7 comments

Comments

@kirbysayshi
Copy link
Collaborator

How hard do you think it would be to add support for:

@* list.vash *@
@{ var item = require('./list-item.vash'); }
<ul>@model.forEach(item)</ul>

Otherwise, are you constructing templates from the inside out and then passing them in, fully rendered?

I tried the above snippet, but since it's a physical temp file on disk it doesn't resolve:

Error: module "./list-item.vash" not found from "   /algoview/node_modules/vashify/.temp/0_list.vash.js"
    at notFound (   /algoview/node_modules/browserify/index.js:790:15)
    at  /algoview/node_modules/browserify/index.js:741:23
    at  /algoview/node_modules/browserify/node_modules/browser-resolve/index.js:185:24
    at  /algoview/node_modules/browserify/node_modules/resolve/lib/async.js:36:22
    at load (   /algoview/node_modules/browserify/node_modules/resolve/lib/async.js:54:43)
    at  /algoview/node_modules/browserify/node_modules/resolve/lib/async.js:60:22
    at  /algoview/node_modules/browserify/node_modules/resolve/lib/async.js:16:47
    at Object.oncomplete (fs.js:107:15)
@chevett
Copy link
Owner

chevett commented May 9, 2014

oh interesting! Once I find the require statement then it is easy. However, I'm not sure how I'd go about getting all the code blocks from a vash file. Does vash have something I can use to examine the code blocks from a template?

@kirbysayshi
Copy link
Collaborator Author

Not easily, since vash's ast is very generic (mostly code vs markup). What
might be easier is if you pass the compiled file to browserify, since that
will of course be valid javascript. Is that possible?

~ Drew

On May 9, 2014, at 8:17 AM, Mike Chevett notifications@github.com wrote:

oh interesting! Once I find the require statement then it is easy. However,
I'm sure how I'd go about getting all the code blocks from a vash file.
Does vash have something I can use to examine the code blocks from a
template?


Reply to this email directly or view it on
GitHubhttps://github.com//issues/7#issuecomment-42659662
.

@chevett
Copy link
Owner

chevett commented May 9, 2014

oic. I believe that's what I'm already doing and I think I can see what needs to change. I'll take a stab at it this weekend and let you know!

@kirbysayshi
Copy link
Collaborator Author

Cool!

Yip yip,
~ Drew*

On Fri, May 9, 2014 at 10:33 AM, Mike Chevett notifications@github.comwrote:

oic. I'm believe that's what I'm already doing and I think I can see what
needs to change. I'll take a stab at it this weekend and let you know!


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-42672440
.

chevett added a commit that referenced this issue May 14, 2014
#7 require('file.vash') from within a template
@chevett
Copy link
Owner

chevett commented Jun 10, 2014

Any idea if this has been working? Can this be closed?

@kirbysayshi
Copy link
Collaborator Author

Sorry it took me so long. Yes, it appears to be working! It also revealed a miscalculation on my part. This is what's required to make it work, since now the templates do not share a rendering context:

@* list.vash *@
@{ var item = require('./list-item.vash'); }
<ul>@html.raw(model.map(item))</ul>

As you can see, the return value of the rendering template is needed to be output (via map) and told to not be html escaped. While this makes sense technically, it's a little weird. Still, it works for now.

But either way, your patch looks great!

@chevett
Copy link
Owner

chevett commented Jun 11, 2014

nice! Keep these kind of things coming. closing.

@chevett chevett closed this as completed Jun 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants