kirbysayshi/vash

Tilde-slash

Closed this issue · 3 comments

I was getting spoiled by ASP.NET MVC 5's automatic detection of tilde-slash at the beginining of src and href attributes.

<link rel="stylesheet" type="text/css" href="~/Content/css/theme.css">

Now I realize that Vash doesn't do this but I was wondering what the best path should be in the mean time. I was at first going to take the template-transformed output and do a .replace() to find all instances equals-double-quote-tilde-slash with the virtual path of the root of the node application, but being still green to NodeJS and ExpressJS I'm still green on knowing the cleanest path to accomplishing that.

I suppose in the mean time I can create a vash helper equivalent to @Url.Content("..") in my own environment.

FYI the purpose of this is to be able to set at the point of configuration where the absolute root of the application is in URI. In ASP.NET, this is determined by IIS config. In NodeJS, this would perhaps be an explicit JS variable established during bootstrapping. The goal would be such that one could create templates that use resources with a virtual root path without beginning URI paths with "/" which may not be appropriate if upon deployment the application should actually be rooted at "/nested/URI/path/". It is also difficult to manage templates knowing relative paths such that "../../static/css/x.css" gets used everywhere; in a restructuring, where static files remain but a nested path changes, changing those relative paths can be avoided by using "~/static/css/x.css".

I suppose one argument can be made that the discussion is moot since a node app is not shared but has exclusive ownership of a ip+port. I'm not sure how true this is though or how much longer it will remain true.

@stimpy77 Yes, things are very different in node land, and over the years since Vash's layout system was first introduced I've definitely wished I'd done things a bit differently.

A helper, as you said, is probably the best way to go, since I believe the ~/whatever syntax is not actually part of Razor View Engine, but rather a part of IIS + MVC.

When parsing a template, vash has no knowledge of anything that is not "code-like", meaning it ignores all content that isn't somehow related to an expression @something, explicit expression @(something) or within a block @{}. So there really isn't a hook for you to be able to catch the ~/ in plain HTML and transform it into something else.

I'm going to close this, but reopen if you want to discuss more.