mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Continuing theming work...
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4044193
This commit is contained in:
@@ -4,7 +4,7 @@ using Orchard.Themes;
|
||||
namespace Orchard.Core.Themes {
|
||||
public class SafeModeThemeSelector : IThemeSelector {
|
||||
public ThemeSelectorResult GetTheme(RequestContext context) {
|
||||
return new ThemeSelectorResult {Priority = -100, ThemeName = "SafeMode"};
|
||||
return new ThemeSelectorResult {Priority = -100, ThemeName = "Themes"};
|
||||
}
|
||||
}
|
||||
}
|
@@ -49,14 +49,18 @@ namespace Orchard.Core.Themes.Services {
|
||||
var requestTheme = _themeSelectors
|
||||
.Select(x => x.GetTheme(requestContext))
|
||||
.Where(x => x != null)
|
||||
.OrderByDescending(x => x.Priority)
|
||||
.FirstOrDefault();
|
||||
.OrderByDescending(x => x.Priority);
|
||||
|
||||
if (requestTheme == null) {
|
||||
if (requestTheme.Count() < 1)
|
||||
return null;
|
||||
|
||||
foreach (var theme in requestTheme) {
|
||||
var t = GetThemeByName(theme.ThemeName);
|
||||
if (t != null)
|
||||
return t;
|
||||
}
|
||||
|
||||
return GetThemeByName(requestTheme.ThemeName);
|
||||
return null;
|
||||
}
|
||||
|
||||
public ITheme GetThemeByName(string name) {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
name: SafeMode
|
||||
name: Safe Mode
|
||||
description: This is the default theme for the Themes extension.
|
||||
version: 1.0
|
||||
tags: safe, default
|
||||
|
@@ -5,7 +5,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<title><%=Html.Title() %> - Safe Mode!</title><%
|
||||
<title><%=Html.Title() %> - !!Safe Mode!!</title><%
|
||||
Html.Zone("head", ":metas :styles :scripts"); %>
|
||||
</head>
|
||||
<body><%
|
||||
|
@@ -4,6 +4,11 @@ using Autofac.Integration.Web;
|
||||
|
||||
namespace Orchard.Mvc.Html {
|
||||
public static class ContainerExtensions {
|
||||
/// <summary>
|
||||
/// This method performed by Erik Weisz.
|
||||
/// </summary>
|
||||
/// <see cref="http://en.wikipedia.org/wiki/Harry_Houdini"/>
|
||||
/// <returns>himself</returns>
|
||||
public static TService Resolve<TService>(this HtmlHelper html) {
|
||||
var containerProvider = html.ViewContext.RouteData.DataTokens["IContainerProvider"] as IContainerProvider;
|
||||
if (containerProvider == null)
|
||||
|
@@ -40,11 +40,7 @@ namespace Orchard.Mvc.ViewEngines {
|
||||
// todo: refactor. also this will probably result in the "SafeMode" theme being used so dump some debug info
|
||||
// into the context for the theme to use for displaying why the expected theme isn't being used
|
||||
if (requestTheme != null) {
|
||||
var theme = _extensionManager
|
||||
.AvailableExtensions()
|
||||
.Single(x => x.ExtensionType == "Theme" && x.Name == requestTheme.ThemeName);
|
||||
|
||||
var themeLocation = Path.Combine(theme.Location, theme.Name);
|
||||
var themeLocation = _extensionManager.GetThemeLocation(requestTheme);
|
||||
|
||||
themeViewEngines = _viewEngineProviders
|
||||
.Select(x => x.CreateThemeViewEngine(new CreateThemeViewEngineParams { VirtualPath = themeLocation }));
|
||||
|
@@ -125,6 +125,7 @@
|
||||
<Compile Include="Environment\IOrchardShellEvents.cs" />
|
||||
<Compile Include="Extensions\ExtensionDescriptor.cs" />
|
||||
<Compile Include="Extensions\ExtensionEntry.cs" />
|
||||
<Compile Include="Themes\ExtensionManagerExtensions.cs" />
|
||||
<Compile Include="Extensions\Helpers\PathHelpers.cs" />
|
||||
<Compile Include="Extensions\IExtensionManager.cs" />
|
||||
<Compile Include="Extensions\PackageFolders.cs" />
|
||||
|
14
src/Orchard/Themes/ExtensionManagerExtensions.cs
Normal file
14
src/Orchard/Themes/ExtensionManagerExtensions.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Orchard.Extensions;
|
||||
|
||||
namespace Orchard.Themes {
|
||||
public static class ExtensionManagerExtensions {
|
||||
public static string GetThemeLocation(this IExtensionManager extensionManager, ITheme theme) {
|
||||
var themeDescriptor = extensionManager.AvailableExtensions()
|
||||
.Single(x => x.ExtensionType == "Theme" && x.Name == theme.ThemeName);
|
||||
|
||||
return Path.Combine(themeDescriptor.Location, themeDescriptor.Name);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,16 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Extensions;
|
||||
using Orchard.Themes;
|
||||
|
||||
namespace Orchard.UI.Resources {
|
||||
public class ResourceManager : IResourceManager {
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
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 readonly List<string> _styles;
|
||||
private readonly List<string> _headScripts;
|
||||
private readonly List<string> _footScripts;
|
||||
|
||||
public ResourceManager() {
|
||||
public ResourceManager(IThemeService themeService,
|
||||
IExtensionManager extensionManager) {
|
||||
_themeService = themeService;
|
||||
_extensionManager = extensionManager;
|
||||
_styles = new List<string>();
|
||||
_headScripts = new List<string>();
|
||||
_footScripts = new List<string>();
|
||||
@@ -35,21 +43,33 @@ namespace Orchard.UI.Resources {
|
||||
}
|
||||
|
||||
public MvcHtmlString GetStyles() {
|
||||
return GetFiles(_styles, StyleFormat);
|
||||
return GetFiles(_styles, StyleFormat, s => GetThemePath("/styles/" + s));
|
||||
}
|
||||
|
||||
public MvcHtmlString GetHeadScripts() {
|
||||
return GetFiles(_headScripts, ScriptFormat);
|
||||
return GetFiles(_headScripts, ScriptFormat, s => GetThemePath("/scripts/" + s));
|
||||
}
|
||||
|
||||
public MvcHtmlString GetFootScripts() {
|
||||
return GetFiles(_footScripts, ScriptFormat);
|
||||
return GetFiles(_footScripts, ScriptFormat, s => GetThemePath("/scripts/" + s));
|
||||
}
|
||||
|
||||
private static MvcHtmlString GetFiles(IEnumerable<string> files, string fileFormat) {
|
||||
private static MvcHtmlString GetFiles(IEnumerable<string> files, string fileFormat, Func<string, string> getPath) {
|
||||
return
|
||||
MvcHtmlString.Create(string.Join("\r\n",
|
||||
files.Select(s => string.Format(fileFormat, s)).ToArray()));
|
||||
files.Select(s => string.Format(fileFormat, getPath(s))).ToArray()));
|
||||
}
|
||||
|
||||
private string GetThemePath(string fileName) {
|
||||
var requestTheme = _themeService.GetRequestTheme(null); // <- 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("\\", "/");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user