Relative image urls

Nov 1, 2011 at 2:28 PM

I have image files in the same directory as my stylesheets so I write CSS as follows:

    background-image:url("my-logo.png");

Now I know I could fix this by specifying an absolute path to the image, but that breaks if e.g. my development server uses a path prefix. Are you planning any kind of processing to correctly remap Urls like this?

Nov 1, 2011 at 4:12 PM

Similar functionality exists, relative image paths are converted if they begin with a "../". This means, I've never thought someone would place images in the same dir as the css files :-).

Nov 1, 2011 at 4:32 PM

Ah I see; I saw the changelog mentioned relative paths so I was surprised when it didn't work, but then on a quick look through your code I couldn't see where it would be happening. I tend to lump all my style-related images in the same folder (or subfolders of) my css files. Actually there are some core Orchard styles that do the same (see Orchard.Core/Shapes/Styles/jquery.switchable.css).

Nov 1, 2011 at 9:31 PM

I also fixed this in the latest changesest, could you please try it out?

Nov 2, 2011 at 11:17 AM

I've left some debug code in the source which caused malfunction, sorry. Could you please try the now latest changeset?

Nov 2, 2011 at 11:47 AM

I'll try it at some point over the course of today (my dev instance is currently non-functional while I'm working thru some optimisations!)

Nov 9, 2011 at 2:32 PM

Finally got round to trying this again. I'm now getting a different problem. The website attempts to load a CSS file that doesn't exist (it's trying to load http://localhost:61849/Modules/Piedone.Combinator/Styles/CombinedCache/-2090018491-1.css - there is a CSS file that exists but it's 1483983767-1.css). I've tried deleting cache / restarting Orchard etc. but no change.

I've got the following in my error log:

2011-11-09 14:24:07,044 [10] Piedone.Combinator.Services.CombinatorService - Processing of resource ~/Themes/TheAdmin/styles/menu.themes-admin.css failed
System.ApplicationException: Local resource file not found under ~/Themes/TheAdmin/styles/menu.themes-admin.css
   at Piedone.Combinator.Services.ResourceFileService.GetLocalResourceContent(String path) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\Services\ResourceFileService.cs:line 21
   at Piedone.Combinator.Services.CombinatorService.Combine(IList`1 resources, Int32 hashCode, ResourceType resourceType, Boolean combineCDNResources) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\Services\CombinatorService.cs:line 157
2011-11-09 14:24:07,047 [10] Piedone.Combinator.CombinedResourceManager - Error when combining Style files
System.ApplicationException: Processing of resource ~/Themes/TheAdmin/styles/menu.themes-admin.css failed ---> System.ApplicationException: Local resource file not found under ~/Themes/TheAdmin/styles/menu.themes-admin.css
   at Piedone.Combinator.Services.ResourceFileService.GetLocalResourceContent(String path) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\Services\ResourceFileService.cs:line 21
   at Piedone.Combinator.Services.CombinatorService.Combine(IList`1 resources, Int32 hashCode, ResourceType resourceType, Boolean combineCDNResources) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\Services\CombinatorService.cs:line 157
   --- End of inner exception stack trace ---
   at Piedone.Combinator.Services.CombinatorService.Combine(IList`1 resources, Int32 hashCode, ResourceType resourceType, Boolean combineCDNResources) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\Services\CombinatorService.cs:line 212
   at Piedone.Combinator.Services.CombinatorService.CombineStylesheets(IList`1 resources, Boolean combineCDNResources) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\Services\CombinatorService.cs:line 54
   at Piedone.Combinator.CombinedResourceManager.BuildRequiredResources(String stringResourceType) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\CombinedResourceManager.cs:line 78
Note: I've tried both the latest source from today's commit, and changeset: http://combinator.codeplex.com/SourceControl/changeset/changes/4d67bab8d724

Nov 9, 2011 at 2:49 PM

Aha! I wiped the table Piedone_Combinator_CombinedFileRecord as well as deleting the cache and restarting Orchard and this time the styles seem to be fine.

Now, there are a couple of things still not working:

- Scripts are going wrong. There's a .js file being generated but it doesn't seem to include all the scripts, in particular I have a custom script defined in a ResourceManifest (in a feature of a separate module) and it's not running. In fact it looks like only html5.js is there, can't see any jQuery or anything else ("Combined CDN Resources is disabled and I shouldn't have anything coming from CDN anyway)

- When my site switches to an alternative "Facebook" theme (using Vandelay Theme Switcher), combinator doesn't run and I just see all the individual stylesheets. This theme is simply based on my normal theme, with one additional stylesheet included to perform some customisations.

Anyway, looking great up to here!

Nov 9, 2011 at 3:26 PM

Thanks for investigating and that despite the various difficulties you still take time to try the module!

The first problem is quite surprising and I don't know what could cause this. It looks that somehow the cache files and cache entries got out of sync, but after emptying the cache it should have gone away. Anyway, great that the problem went away!

The log entries BTW should have nothing to do with this problem. This was another bug, that the new admin check routine failed to detect that the cache emptying action in the module's admin controller is part of the admin area (and then tried to combine admin stylesheets, which is known not to work because of the limitation with overridden stylesheets). This is fixed in the latest changeset.

Now on to the other problems:

For the first currently I don't have an idea, since everything Include()-d or Require()-d should be combined, together with all the dependencies. Could you please show the ResourceManifest in question?

The second problem hints that there was some problem with combining one or more files therefore the original list of resources was returned. You already helped a lot, but could you please look at the log to see whether there were any exceptions or make the debugger break at exceptions to see whether one occurs? I think however, that this has to do with the mentioned limitation of overridden stylesheets (please look at the top of the docs).

Nov 9, 2011 at 4:02 PM

Ah yes, I see the error - it's not exactly what you think. In this case I'm *not* overriding the stylesheet - so Combinator is attempting to combine Site.css from the overridden theme, but it actually only exists in the base template. I'd guess there's a way to fix this by traversing thru BaseTheme until you find a file that exists? (I checked and this problem also exists in my CKEditor modifications to load Site.css in the editor area...)

So just to clarify;

- Both my themes contain a Layout.cshtml with Style.Include("Site.css");

- But Site.css only exists in the base theme, so combinator is throwing an error because the file doesn't exist in the theme it's looking in

Back to the first problem. These are the script includes in my Layout:

 

    Script.Require("jQuery");
    // Needs jQuery UI for color animation
    Script.Require("jQueryEffects_Core");
    Script.Require("jQueryUI_Draggable");
    Script.Require("MyScriptResource");

 

And this is the resource manifest:

 

namespace MyDomain.Layout.MyFeature
{
    [OrchardFeature("MyDomain.Layout.MyFeature")]
    public class ResourceManifest : IResourceManifestProvider
    {
        public void BuildManifests(ResourceManifestBuilder builder)
        {
            builder.Add().DefineScript("MyScriptResource").SetUrl("MyScript.js");
        }
    }
}

I wonder if the problem is in the namespace; the module is "MyDomain.Layout" but I have the resource manifest in a different namespace because it's part of a sub feature?

 

Nov 9, 2011 at 6:38 PM

Thanks for the details!

For the css problem: it's tough. The current mechanism works as the following: it looks at all the included resources and takes the distinct ones (check solely by the file name). If two there are more resources with the same file name, the last one wins. The purpose of this is to circumvent the problem of overridden stylesheets. The workaround described in the docs does exactly the opposite what it's in your situation. That's why Combinator thinks the real stylesheet is in the child theme. I've added a file existence check to solve this in the latest changeset, could you please try it?

The js issue is well a bug. It was caused by the fact that head and foot scripts were combined, but those with unspecified location not. In the latest changeset this was fixed too (now all three "locations" are combined separately, what will produce two foot scripts; however, since it is only a current implementation detail that unspecified location resolves to foot, I think it's better this way).

Nov 9, 2011 at 7:30 PM

The scripts are fixed in the new version but it's still trying to process the non-existent Site.css:

2011-11-09 19:27:44,925 [19] Piedone.Combinator.Services.CombinatorService - Processing of resource ~/Themes/StreamMedia.Themes.Vector.Facebook/styles/Site.css failed
System.ApplicationException: Local resource file not found under ~/Themes/StreamMedia.Themes.Vector.Facebook/styles/Site.css
   at Piedone.Combinator.Services.ResourceFileService.GetLocalResourceContent(String path) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\Services\ResourceFileService.cs:line 21
   at Piedone.Combinator.Services.CombinatorService.Combine(IList`1 resources, Int32 hashCode, ResourceType resourceType, Boolean combineCDNResources, Boolean minifyResources, String minificationExcludeRegex) in g:\Orchard\Default\src\Orchard.Web\Modules\Piedone.Combinator\Services\CombinatorService.cs:line 171

Nov 9, 2011 at 8:10 PM

It dawned on me that the file existence check was actually not something that could solve this, and currently without some heavy theme processing there is no solution AFAIK. The problem is the same as with overridden stylesheets: the inclusion adds a resource that points to the child theme and the path is only resolved to the real one just before writing the css links to the output.

However there is a simple solution: please include the stylesheets with its full virtual path and it will work (in the latest changeset I removed the previously added pointless check).

Nov 10, 2011 at 10:38 AM

I might have a fix - there was a similar situation arising in the CKEditor module where I look for a config-defined stylesheet to use in the editor area, and indeed it wasn't working for this kind of base theme scenario.

I've just pushed a fix so it first checks in the CurrentTheme and if it doesn't find the file, it recurses through sub themes (which it accesses using IExtensionManager). It's fairly simple and it works!

The changes are here: http://orchardckeditor.codeplex.com/SourceControl/changeset/changes/72042b658132#Providers%2fDefaultConfigProvider.cs

I realise the situation is slightly different in your module but I'd guess the same principle can be applied?

Nov 11, 2011 at 1:18 PM

Thanks, I'll look into that. However Orchard 1.4 is soon here where I hope to see a fix for all this overriding issue (see http://orchard.codeplex.com/discussions/276210).

Did you try the workaround I mentioned above?