Closed budu closed 12 years ago
Hello. I'm not sure I understand your original problem. Could you expand upon that, maybe with some code examples?
Say I have an image in a HTML page in a subdirectory of my static site and that all my images are in the /images/
directory, I'd do:
%img{ src: '../images/foo.png' }
But using relative path eveywhere is error prone and become a real mess when I move things around, that why we normally use absolute path in most case with dynamic web applications, like:
%img{ src: '/images/foo.png' }
With a static website though, I'm not using a web server during development so using absolute path doesn't work. One trick I've used in other similar project is to make a helper that automatically generate the relative path from an absolute one, that is the code I'm showing in this ticket. With it I can use:
%img{ src: asset('/images/foo.png') }
and get the best of both worlds.
Ah I see what you mean. Thank you for the explanation. Will give some thought to this.
I decided that the solution to this was to provide a web server in dev mode. Start a web server on port 3000 like so:
stasis -d 3000
I didn't find how to get relative paths for my assets in development mode while retaining the ability to use absolute paths in my code so I came up with my own solution. I'm using a simple helper that I put in the root controller:
This could be a worthy addition to Stasis I think, but it could probably be done in a better way in Stasis internals.