-
Notifications
You must be signed in to change notification settings - Fork 60
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
Running Vash on non-Node environments #39
Comments
So, vash itself will run in any environment that provides ES5 compatibility. But what you're running into is that the layout helpers need a way to load a file. And to do that they assume that either:
So if you want to use another environment, you'll need to either:
|
Thanks, Andrew. Since I actually do provide replacements for Can it be that vash creates kind of "context" when processing a template that makes my global replacements for |
How are you providing the replacements? Vash calls Yip yip, On Tue, Apr 29, 2014 at 12:30 AM, Uwe Keim notifications@github.com wrote:
|
That did it! 😄 I'm now putting the following snippet at the very first line before loading the "vash.js" content:
With
And in turn implementing
I'm not yet through this completely, hope it's OK to ask a further question below. |
Last thing (hopefully): I had to modify your sources. At 2 occurrances, I had to replace:
with
That I defined before loading the "vash.js" content as:
Then I could call Vash with:
The reason I had to do this was that the environment checks for AMD, NODSJS and BROWSER used the BROWSER case as a fallback which does not apply to my case. My question Is there a way to use Vash somehow like above without modifying your sources? |
Really interesting runtime, I'd not seen ClearScript before. I'll add my 2c to this, the hoops you are jumping through at the moment are that ClearScript allows you to execute JavaScript and bind between .NET, but ClearScript doesn't support CommonJS (which is probably a good choice to make at a low level). Vash determines the exporting type by trying to feature detect functionality of each distinct module syntax, for Node.js style (CommonJS) vash checks to see if 'module' is an object and that is has an exports property (see https://github.com/kirbysayshi/vash/blob/master/build/vash.js#L17). You have a few options, the easiest is probably to define 'window' as a global, vash will then fallback and export itself to window. Alternatively you can aim to make ClearScript support CommonJS, this may have already been done before, but if not you'll want to define a global called 'module' that has an exports property that is an object. After vash is has executed, the module.exports property will be populated. Another thing that may help from the vash source side is not to assume the global object is 'window', but to export to 'this' from a function being invoked at the global level: http://stackoverflow.com/questions/7290086/javascript-use-strict-and-nicks-find-global-function |
Thanks, @meandmycode I first tried to mock a In addition the |
So my final question remains: Is there a way to use Vash inside ClearScript (as described above) without modifying the sources of Vash? |
@UweKeim, @meandmycode is right, the easiest thing for you to do is to just define a _engine.Execute("window = this"); That should at least let vash export itself properly. |
After a whole day of trying to get Vash up and running in V8 within a .NET ClearScript application, I do have the following results:
path.normalize
call when using template includes through@html.include
.Even after debugging the Vash sources (through the Install Google Chrome Developer Tools for Java plug-in in Eclipse), I still cannot find a way to see what's going on here.
ClearScript
ClearScript is an implementation of V8 that runs "inside" a .NET application and makes binding to .NET objects from JavaScript easy and fast.
What I did
Since ClearScript is neither Node.js nor a browser, I created some .NET mockup classes for simulating e.g. the
path
or thefs
variables.Still, the above error.
I also tried to temporarily modify my local "vash.js" file but without any reasonable result.
My question
Do you think it is possible at all to use Vash in an environment that is neither browser nor Node.js?
The text was updated successfully, but these errors were encountered: