Embedded Static Resources

Mar 21, 2010 at 12:27 AM
Edited Mar 21, 2010 at 3:08 PM

 

I could use some help figuring out how to use embedded resources.  I'm able to use embedded haml resources via LoadEmbeddedViews but I also want to include some static paths for stylesheets and javascript. 

My application works fine with embedded views but I can't seem to include static resources.

I'm trying to use the haml below but the following should also work:  http://127.0.0.1:8080/public/stylesheets/application.css

... I'm doing the following to an MvcServer:

 

<font size="2">

 

</font>

 

var embedded = new EmbeddedResources("/public/", thisAssembly, "httpservertest.public");

server.ViewProvider.Add(embedded);

...

 

Any suggestions?

%link{ href = "/stylesheets/application.css", rel = "stylesheet", type = "text/css" }

%script{src = "/javascripts/prototype.js", type="text/javascript"}

%script{src = "/javascripts/settings.js", type="text/javascript"}

Mar 21, 2010 at 3:20 PM

One thing I've found is that rootNameSpace must be declared in lower case instead of the actual case. 

HttpServer.Resources.EmbeddedResources:

<font size="2">

 

</font>

public void Add(string path, Assembly assembly, string rootNameSpace):

The following line changes the resource namespace case on comparison:

if (!resourceName.ToLower().StartsWith(rootNameSpace))

I would call this unexpected behavior.  It's easily fixed on my end by instantiating EmbeddedResources with a rootNameSpace that's been converted to lower case rather than actual case.

I've also noticed that the mapping looks different for an embedded resource I create vice one that's created via LoadEmbeddedViews.  These two call different add methods in HttpServer.Resources.EmbeddedResources.  These two add methods create the mappings differently (different path, extension and UriPath).  Attempting to fudge these values at runtime still doesn't fix my problem with the framework not finding my stylesheet.  Although I can get what appears to be the correct mapping added, the resource loader doesn't seem to look at the EmbeddedResources class which maps to my stylesheet.

 

Coordinator
Mar 21, 2010 at 4:11 PM

A lot of bugfixes have been done in the last two commits. Try the latest trunk.

 

If you need a stable version, download v1.1. Version 2.0 is still not production quality and will not be so for at least another month (although it's becoming more and more stable).

Mar 22, 2010 at 3:59 PM

Thank you for the response.  After many hours of trying to figure this out I've decided to embed the javascript and css.  This eliminates the need to reference them as static files.  So far the new approach is working well.

I had been working with the source code put out last Friday.  I couldn't find where ViewProvider was used during the processing of a request.  Only the usage of a controller to locate and process embedded resources.  I realize the codebase is not an official release and do understand that some functionality not be working 100%.  I look forward to getting an update when a new release happens. 

For the present I'm able to continue working on my project and should be able to complete it with your framework.

Thanks again for your hard work!

 

Coordinator
Mar 22, 2010 at 5:26 PM

The ViewProvider property is used by each View engine to locate views.

The Resources property is used to provide locations to static files.

 

Both exists to prevent users from being able to download views or any other files places in the view folders.