mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-20 02:37:55 +08:00
Style.Include and Script.Include register the wrong resource key in debug mode (#8177)
Fixes #8176
This commit is contained in:

committed by
Sébastien Ros

parent
cb0011c307
commit
a02323572d
@@ -2,13 +2,17 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Autofac.Features.Metadata;
|
using Autofac.Features.Metadata;
|
||||||
|
using Orchard.Environment;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Settings;
|
||||||
|
|
||||||
namespace Orchard.UI.Resources {
|
namespace Orchard.UI.Resources {
|
||||||
public class ResourceManager : IResourceManager, IUnitOfWorkDependency {
|
public class ResourceManager : IResourceManager, IUnitOfWorkDependency {
|
||||||
@@ -19,6 +23,8 @@ namespace Orchard.UI.Resources {
|
|||||||
};
|
};
|
||||||
private readonly Dictionary<string, IList<ResourceRequiredContext>> _builtResources = new Dictionary<string, IList<ResourceRequiredContext>>(StringComparer.OrdinalIgnoreCase);
|
private readonly Dictionary<string, IList<ResourceRequiredContext>> _builtResources = new Dictionary<string, IList<ResourceRequiredContext>>(StringComparer.OrdinalIgnoreCase);
|
||||||
private readonly IEnumerable<Meta<IResourceManifestProvider>> _providers;
|
private readonly IEnumerable<Meta<IResourceManifestProvider>> _providers;
|
||||||
|
private readonly Work<WorkContext> _workContext;
|
||||||
|
private readonly Work<IHttpContextAccessor> _httpContextAccessor;
|
||||||
private ResourceManifest _dynamicManifest;
|
private ResourceManifest _dynamicManifest;
|
||||||
private List<String> _headScripts;
|
private List<String> _headScripts;
|
||||||
private List<String> _footScripts;
|
private List<String> _footScripts;
|
||||||
@@ -87,8 +93,13 @@ namespace Orchard.UI.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceManager(IEnumerable<Meta<IResourceManifestProvider>> resourceProviders) {
|
public ResourceManager(IEnumerable<Meta<IResourceManifestProvider>> resourceProviders,
|
||||||
|
Work<WorkContext> workContext,
|
||||||
|
Work<IHttpContextAccessor> httpContextAccessor
|
||||||
|
) {
|
||||||
_providers = resourceProviders;
|
_providers = resourceProviders;
|
||||||
|
_workContext = workContext;
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IResourceManifest> ResourceProviders {
|
public IEnumerable<IResourceManifest> ResourceProviders {
|
||||||
@@ -152,7 +163,7 @@ namespace Orchard.UI.Resources {
|
|||||||
|
|
||||||
resourcePath = FixPath(resourcePath, relativeFromPath);
|
resourcePath = FixPath(resourcePath, relativeFromPath);
|
||||||
resourceDebugPath = FixPath(resourceDebugPath, relativeFromPath);
|
resourceDebugPath = FixPath(resourceDebugPath, relativeFromPath);
|
||||||
return Require(resourceType, ToAppRelativePath(resourcePath)).Define(d => d.SetUrl(resourcePath, resourceDebugPath));
|
return Require(resourceType, ToAppRelativePath(GetResourceKey(resourcePath, resourceDebugPath))).Define(d => d.SetUrl(resourcePath, resourceDebugPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void RegisterHeadScript(string script) {
|
public virtual void RegisterHeadScript(string script) {
|
||||||
@@ -329,5 +340,28 @@ namespace Orchard.UI.Resources {
|
|||||||
_metas[index] = meta;
|
_metas[index] = meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetResourceKey(string releasePath, string debugPath) {
|
||||||
|
bool debugMode;
|
||||||
|
var site = _workContext.Value.CurrentSite;
|
||||||
|
switch (site.ResourceDebugMode) {
|
||||||
|
case ResourceDebugMode.Enabled:
|
||||||
|
debugMode = true;
|
||||||
|
break;
|
||||||
|
case ResourceDebugMode.Disabled:
|
||||||
|
debugMode = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Debug.Assert(site.ResourceDebugMode == ResourceDebugMode.FromAppSetting, "Unknown ResourceDebugMode value.");
|
||||||
|
var context = _httpContextAccessor.Value.Current();
|
||||||
|
debugMode = context != null && context.IsDebuggingEnabled;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (debugMode && !string.IsNullOrWhiteSpace(debugPath)) {
|
||||||
|
return debugPath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return releasePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user