mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-15 14:54:57 +08:00
Changed ResourceManager to reverse everything it returns since multi-pass rendering makes resources get register backwards. This makes it so resources will be rendered in the proper order.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4046085
This commit is contained in:
parent
a737e9bda1
commit
e7d735692a
@ -1,14 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Extensions;
|
using JetBrains.Annotations;
|
||||||
using Orchard.Mvc.Html;
|
using Orchard.Mvc.Html;
|
||||||
using Orchard.Themes;
|
|
||||||
|
|
||||||
namespace Orchard.UI.Resources {
|
namespace Orchard.UI.Resources {
|
||||||
|
[UsedImplicitly]
|
||||||
public class ResourceManager : IResourceManager {
|
public class ResourceManager : IResourceManager {
|
||||||
private readonly IThemeService _themeService;
|
|
||||||
private readonly IExtensionManager _extensionManager;
|
|
||||||
private const string MetaFormat = "\r\n<meta name=\"{0}\" content=\"{1}\" />";
|
private const string MetaFormat = "\r\n<meta name=\"{0}\" content=\"{1}\" />";
|
||||||
private const string StyleFormat = "\r\n<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\" />";
|
private const string StyleFormat = "\r\n<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\" />";
|
||||||
private const string ScriptFormat = "\r\n<script type=\"text/javascript\" src=\"{0}\"></script>";
|
private const string ScriptFormat = "\r\n<script type=\"text/javascript\" src=\"{0}\"></script>";
|
||||||
@ -17,11 +15,7 @@ namespace Orchard.UI.Resources {
|
|||||||
private readonly List<FileRegistrationContext> _headScripts;
|
private readonly List<FileRegistrationContext> _headScripts;
|
||||||
private readonly List<FileRegistrationContext> _footScripts;
|
private readonly List<FileRegistrationContext> _footScripts;
|
||||||
|
|
||||||
public ResourceManager(IThemeService themeService,
|
public ResourceManager() {
|
||||||
IExtensionManager extensionManager) {
|
|
||||||
_themeService = themeService;
|
|
||||||
_extensionManager = extensionManager;
|
|
||||||
//TODO: (erikpo) Not sure if generator should be initialized here or somewhere else
|
|
||||||
_metas = new Dictionary<string, string>(20) {{"generator", "Orchard"}};
|
_metas = new Dictionary<string, string>(20) {{"generator", "Orchard"}};
|
||||||
_styles = new List<FileRegistrationContext>(10);
|
_styles = new List<FileRegistrationContext>(10);
|
||||||
_headScripts = new List<FileRegistrationContext>(10);
|
_headScripts = new List<FileRegistrationContext>(10);
|
||||||
@ -37,7 +31,7 @@ namespace Orchard.UI.Resources {
|
|||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileRegistrationContext context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, fileName);
|
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, fileName);
|
||||||
|
|
||||||
if (!_styles.Contains(context))
|
if (!_styles.Contains(context))
|
||||||
_styles.Add(context);
|
_styles.Add(context);
|
||||||
@ -47,7 +41,7 @@ namespace Orchard.UI.Resources {
|
|||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileRegistrationContext context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, fileName);
|
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, fileName);
|
||||||
|
|
||||||
if (!_headScripts.Contains(context))
|
if (!_headScripts.Contains(context))
|
||||||
_headScripts.Add(context);
|
_headScripts.Add(context);
|
||||||
@ -57,7 +51,7 @@ namespace Orchard.UI.Resources {
|
|||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileRegistrationContext context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, fileName);
|
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, fileName);
|
||||||
|
|
||||||
if (!_footScripts.Contains(context))
|
if (!_footScripts.Contains(context))
|
||||||
_footScripts.Add(context);
|
_footScripts.Add(context);
|
||||||
@ -66,7 +60,7 @@ namespace Orchard.UI.Resources {
|
|||||||
public MvcHtmlString GetMetas() {
|
public MvcHtmlString GetMetas() {
|
||||||
return
|
return
|
||||||
MvcHtmlString.Create(string.Join("\r\n",
|
MvcHtmlString.Create(string.Join("\r\n",
|
||||||
_metas.Select(m => string.Format(MetaFormat, m.Key, m.Value)).ToArray()));
|
_metas.Select(m => string.Format(MetaFormat, m.Key, m.Value)).Reverse().ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MvcHtmlString GetStyles() {
|
public MvcHtmlString GetStyles() {
|
||||||
@ -84,20 +78,7 @@ namespace Orchard.UI.Resources {
|
|||||||
private static MvcHtmlString GetFiles(IEnumerable<FileRegistrationContext> fileRegistrationContexts, string fileFormat, string containerRelativePath) {
|
private static MvcHtmlString GetFiles(IEnumerable<FileRegistrationContext> fileRegistrationContexts, string fileFormat, string containerRelativePath) {
|
||||||
return
|
return
|
||||||
MvcHtmlString.Create(string.Join("\r\n",
|
MvcHtmlString.Create(string.Join("\r\n",
|
||||||
fileRegistrationContexts.Select(c => string.Format(fileFormat, c.GetFilePath(containerRelativePath))).ToArray()));
|
fileRegistrationContexts.Select(c => string.Format(fileFormat, c.GetFilePath(containerRelativePath))).Reverse().ToArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: (erikpo) Old code that may be needed later
|
|
||||||
//private string GetThemePath(string fileName, RequestContext requestContext) {
|
|
||||||
// var requestTheme = _themeService.GetRequestTheme(requestContext); // <- todo: (erikpo) will need context eventually
|
|
||||||
|
|
||||||
// if (requestTheme == null)
|
|
||||||
// return fileName;
|
|
||||||
|
|
||||||
// //todo: (erikpo) this might be the worst code ever so resolve for real
|
|
||||||
// return (_extensionManager.GetThemeLocation(requestTheme) + fileName)
|
|
||||||
// .Replace("~", "")
|
|
||||||
// .Replace("\\", "/");
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user