mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
- Themes: Adding core themes package, CurrentTheme property injection, base theme/theme service interface/implementations...
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043641
This commit is contained in:
@@ -83,6 +83,13 @@
|
|||||||
<Compile Include="Settings\Records\SiteSettingsRecord.cs" />
|
<Compile Include="Settings\Records\SiteSettingsRecord.cs" />
|
||||||
<Compile Include="Settings\Services\SiteService.cs" />
|
<Compile Include="Settings\Services\SiteService.cs" />
|
||||||
<Compile Include="Settings\ViewModels\SettingsIndexViewModel.cs" />
|
<Compile Include="Settings\ViewModels\SettingsIndexViewModel.cs" />
|
||||||
|
<Compile Include="Themes\AdminMenu.cs" />
|
||||||
|
<Compile Include="Themes\Controllers\AdminController.cs" />
|
||||||
|
<Compile Include="Themes\Models\ThemeSiteSettings.cs" />
|
||||||
|
<Compile Include="Themes\Models\ThemeSiteSettingsHandler.cs" />
|
||||||
|
<Compile Include="Themes\Records\ThemeSiteSettingsRecord.cs" />
|
||||||
|
<Compile Include="Themes\Services\ThemeService.cs" />
|
||||||
|
<Compile Include="Themes\ViewModels\ThemesIndexViewModel.cs" />
|
||||||
<Compile Include="XmlRpc\Controllers\HomeController.cs" />
|
<Compile Include="XmlRpc\Controllers\HomeController.cs" />
|
||||||
<Compile Include="XmlRpc\Controllers\LiveWriterController.cs" />
|
<Compile Include="XmlRpc\Controllers\LiveWriterController.cs" />
|
||||||
<Compile Include="XmlRpc\IXmlRpcHandler.cs" />
|
<Compile Include="XmlRpc\IXmlRpcHandler.cs" />
|
||||||
@@ -122,6 +129,12 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Common\Views\Models\EditorTemplates\OwnerEditorViewModel.ascx" />
|
<Content Include="Common\Views\Models\EditorTemplates\OwnerEditorViewModel.ascx" />
|
||||||
<Content Include="Common\Views\Web.config" />
|
<Content Include="Common\Views\Web.config" />
|
||||||
|
<Content Include="Themes\Package.txt" />
|
||||||
|
<Content Include="Themes\Views\Admin\Index.aspx" />
|
||||||
|
<Content Include="Themes\Views\Models\EditorTemplates\ThemeSiteSettingsRecord.ascx" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Themes\Views\Web.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using Orchard.Core.Settings.Records;
|
using System;
|
||||||
|
using Orchard.Core.Settings.Records;
|
||||||
using Orchard.Models;
|
using Orchard.Models;
|
||||||
using Orchard.Settings;
|
using Orchard.Settings;
|
||||||
|
|
||||||
|
14
src/Orchard.Web/Core/Themes/AdminMenu.cs
Normal file
14
src/Orchard.Web/Core/Themes/AdminMenu.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Orchard.UI.Navigation;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Themes {
|
||||||
|
public class AdminMenu : INavigationProvider {
|
||||||
|
public string MenuName { get { return "admin"; } }
|
||||||
|
|
||||||
|
public void GetNavigation(NavigationBuilder builder) {
|
||||||
|
builder.Add("Themes", "11",
|
||||||
|
menu => menu
|
||||||
|
.Add("Manage Themes", "2.0", item => item.Action("Index", "Admin", new { area = "Themes" }))
|
||||||
|
.Add("Upload a Theme", "2.1", item => item.Action("Index", "Admin",new { area = "Themes" })));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
src/Orchard.Web/Core/Themes/Controllers/AdminController.cs
Normal file
25
src/Orchard.Web/Core/Themes/Controllers/AdminController.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Web.Mvc;
|
||||||
|
using Orchard.Core.Themes.ViewModels;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Themes;
|
||||||
|
using Orchard.UI.Notify;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Themes.Controllers {
|
||||||
|
[ValidateInput(false)]
|
||||||
|
public class AdminController : Controller {
|
||||||
|
private readonly IThemeService _themeService;
|
||||||
|
private readonly INotifier _notifier;
|
||||||
|
|
||||||
|
public AdminController(IThemeService themeService, INotifier notifier) {
|
||||||
|
_themeService = themeService;
|
||||||
|
_notifier = notifier;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
public ActionResult Index() {
|
||||||
|
return View(new ThemesIndexViewModel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
src/Orchard.Web/Core/Themes/Models/ThemeSiteSettings.cs
Normal file
11
src/Orchard.Web/Core/Themes/Models/ThemeSiteSettings.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using Orchard.Core.Themes.Records;
|
||||||
|
using Orchard.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Themes.Models {
|
||||||
|
public class ThemeSiteSettings : ContentPart<ThemeSiteSettingsRecord> {
|
||||||
|
public string CurrentThemeName {
|
||||||
|
get { return Record.CurrentThemeName; }
|
||||||
|
set { Record.CurrentThemeName = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,16 @@
|
|||||||
|
using Orchard.Core.Themes.Records;
|
||||||
|
using Orchard.Data;
|
||||||
|
using Orchard.Models.Driver;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Themes.Models {
|
||||||
|
public class ThemeSiteSettingsHandler : ContentHandler {
|
||||||
|
private readonly IRepository<ThemeSiteSettingsRecord> _themeSiteSettingsRepository;
|
||||||
|
|
||||||
|
public ThemeSiteSettingsHandler(IRepository<ThemeSiteSettingsRecord> repository) {
|
||||||
|
_themeSiteSettingsRepository = repository;
|
||||||
|
Filters.Add(new ActivatingFilter<ThemeSiteSettings>("site"));
|
||||||
|
Filters.Add(new StorageFilter<ThemeSiteSettingsRecord>(_themeSiteSettingsRepository) { AutomaticallyCreateMissingRecord = true });
|
||||||
|
Filters.Add(new TemplateFilterForRecord<ThemeSiteSettingsRecord>("ThemeSiteSettings"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
src/Orchard.Web/Core/Themes/Package.txt
Normal file
1
src/Orchard.Web/Core/Themes/Package.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
name: Themes
|
@@ -0,0 +1,7 @@
|
|||||||
|
using Orchard.Models.Records;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Themes.Records {
|
||||||
|
public class ThemeSiteSettingsRecord : ContentPartRecord {
|
||||||
|
public virtual string CurrentThemeName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
40
src/Orchard.Web/Core/Themes/Services/ThemeService.cs
Normal file
40
src/Orchard.Web/Core/Themes/Services/ThemeService.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Orchard.Logging;
|
||||||
|
using Orchard.Models;
|
||||||
|
using Orchard.Settings;
|
||||||
|
using Orchard.Themes;
|
||||||
|
using Orchard.Core.Themes.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Themes.Services {
|
||||||
|
public class ThemeService : IThemeService {
|
||||||
|
public ThemeService() {
|
||||||
|
Logger = NullLogger.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ILogger Logger { get; set; }
|
||||||
|
public ISite CurrentSite { get; set; }
|
||||||
|
|
||||||
|
#region Implementation of IThemeService
|
||||||
|
|
||||||
|
public ITheme GetCurrentTheme() {
|
||||||
|
string currentThemeName = CurrentSite.As<ThemeSiteSettings>().Record.CurrentThemeName;
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(currentThemeName)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetThemeByName(currentThemeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITheme GetThemeByName(string name) {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<ITheme> GetInstalledThemes() {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,6 @@
|
|||||||
|
using Orchard.Mvc.ViewModels;
|
||||||
|
|
||||||
|
namespace Orchard.Core.Themes.ViewModels {
|
||||||
|
public class ThemesIndexViewModel : AdminViewModel {
|
||||||
|
}
|
||||||
|
}
|
12
src/Orchard.Web/Core/Themes/Views/Admin/Index.aspx
Normal file
12
src/Orchard.Web/Core/Themes/Views/Admin/Index.aspx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<ThemesIndexViewModel>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Core.Themes.ViewModels"%>
|
||||||
|
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||||
|
<% Html.Include("AdminHead"); %>
|
||||||
|
<div class="yui-u">
|
||||||
|
<h2 class="separator">
|
||||||
|
Themes</h2>
|
||||||
|
</div>
|
||||||
|
<div class="yui-u">
|
||||||
|
List of Orchard Themes
|
||||||
|
</div>
|
||||||
|
<% Html.Include("AdminFoot"); %>
|
@@ -0,0 +1,10 @@
|
|||||||
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ThemeSiteSettingsRecord>" %>
|
||||||
|
<%@ Import Namespace="Orchard.Core.Themes.Records"%>
|
||||||
|
<h3>Themes</h3>
|
||||||
|
<ol>
|
||||||
|
<li>
|
||||||
|
<%= Html.LabelFor(x=>x.CurrentThemeName) %>
|
||||||
|
<%= Html.EditorFor(x=>x.CurrentThemeName) %>
|
||||||
|
<%= Html.ValidationMessage("CurrentThemeName", "*")%>
|
||||||
|
</li>
|
||||||
|
</ol>
|
34
src/Orchard.Web/Core/Themes/Views/Web.config
Normal file
34
src/Orchard.Web/Core/Themes/Views/Web.config
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<configuration>
|
||||||
|
<system.web>
|
||||||
|
<httpHandlers>
|
||||||
|
<add path="*" verb="*"
|
||||||
|
type="System.Web.HttpNotFoundHandler"/>
|
||||||
|
</httpHandlers>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Enabling request validation in view pages would cause validation to occur
|
||||||
|
after the input has already been processed by the controller. By default
|
||||||
|
MVC performs request validation before a controller processes the input.
|
||||||
|
To change this behavior apply the ValidateInputAttribute to a
|
||||||
|
controller or action.
|
||||||
|
-->
|
||||||
|
<pages
|
||||||
|
validateRequest="false"
|
||||||
|
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
|
||||||
|
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
|
||||||
|
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||||
|
<controls>
|
||||||
|
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
|
||||||
|
</controls>
|
||||||
|
</pages>
|
||||||
|
</system.web>
|
||||||
|
|
||||||
|
<system.webServer>
|
||||||
|
<validation validateIntegratedModeConfiguration="false"/>
|
||||||
|
<handlers>
|
||||||
|
<remove name="BlockViewHandler"/>
|
||||||
|
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
|
||||||
|
</handlers>
|
||||||
|
</system.webServer>
|
||||||
|
</configuration>
|
@@ -1,9 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Web;
|
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using FluentNHibernate.Automapping;
|
using FluentNHibernate.Automapping;
|
||||||
using FluentNHibernate.Automapping.Alterations;
|
using FluentNHibernate.Automapping.Alterations;
|
||||||
@@ -12,7 +10,6 @@ using FluentNHibernate.Cfg.Db;
|
|||||||
using NHibernate;
|
using NHibernate;
|
||||||
using NHibernate.Tool.hbm2ddl;
|
using NHibernate.Tool.hbm2ddl;
|
||||||
using Orchard.Environment;
|
using Orchard.Environment;
|
||||||
using Orchard.Models;
|
|
||||||
using Orchard.Models.Records;
|
using Orchard.Models.Records;
|
||||||
|
|
||||||
namespace Orchard.Data {
|
namespace Orchard.Data {
|
||||||
|
@@ -2,8 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
using System.Web.Compilation;
|
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Orchard.Models;
|
using Orchard.Models;
|
||||||
using Orchard.Models.Records;
|
using Orchard.Models.Records;
|
||||||
|
@@ -214,6 +214,9 @@
|
|||||||
<Compile Include="Tasks\BackgroundService.cs" />
|
<Compile Include="Tasks\BackgroundService.cs" />
|
||||||
<Compile Include="Tasks\IBackgroundTask.cs" />
|
<Compile Include="Tasks\IBackgroundTask.cs" />
|
||||||
<Compile Include="Tasks\SweepGenerator.cs" />
|
<Compile Include="Tasks\SweepGenerator.cs" />
|
||||||
|
<Compile Include="Themes\ITheme.cs" />
|
||||||
|
<Compile Include="Themes\IThemeService.cs" />
|
||||||
|
<Compile Include="Themes\ThemesModule.cs" />
|
||||||
<Compile Include="UI\Menus\AdminMenuFilter.cs" />
|
<Compile Include="UI\Menus\AdminMenuFilter.cs" />
|
||||||
<Compile Include="UI\Navigation\NavigationBuilder.cs" />
|
<Compile Include="UI\Navigation\NavigationBuilder.cs" />
|
||||||
<Compile Include="UI\Navigation\INavigationProvider.cs" />
|
<Compile Include="UI\Navigation\INavigationProvider.cs" />
|
||||||
|
@@ -1,8 +1,5 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using Orchard.Packages.Loaders;
|
using Orchard.Packages.Loaders;
|
||||||
using Yaml.Grammar;
|
using Yaml.Grammar;
|
||||||
|
|
||||||
|
10
src/Orchard/Themes/ITheme.cs
Normal file
10
src/Orchard/Themes/ITheme.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using Orchard.Models;
|
||||||
|
|
||||||
|
namespace Orchard.Themes {
|
||||||
|
/// <summary>
|
||||||
|
/// Interface provided by the "themes" model.
|
||||||
|
/// </summary>
|
||||||
|
public interface ITheme : IContent {
|
||||||
|
string ThemeName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
9
src/Orchard/Themes/IThemeService.cs
Normal file
9
src/Orchard/Themes/IThemeService.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Orchard.Themes {
|
||||||
|
public interface IThemeService : IDependency {
|
||||||
|
ITheme GetCurrentTheme();
|
||||||
|
ITheme GetThemeByName(string themeName);
|
||||||
|
IEnumerable<ITheme> GetInstalledThemes();
|
||||||
|
}
|
||||||
|
}
|
24
src/Orchard/Themes/ThemesModule.cs
Normal file
24
src/Orchard/Themes/ThemesModule.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using Module = Autofac.Builder.Module;
|
||||||
|
|
||||||
|
namespace Orchard.Themes {
|
||||||
|
public class ThemesModule : Module {
|
||||||
|
protected override void AttachToComponentRegistration(Autofac.IContainer container, Autofac.IComponentRegistration registration) {
|
||||||
|
|
||||||
|
var themeProperty = FindThemeProperty(registration.Descriptor.BestKnownImplementationType);
|
||||||
|
|
||||||
|
if (themeProperty != null) {
|
||||||
|
registration.Activated += (sender, e) => {
|
||||||
|
var themeService = e.Context.Resolve<IThemeService>();
|
||||||
|
var currentTheme = themeService.GetCurrentTheme();
|
||||||
|
themeProperty.SetValue(e.Instance, currentTheme, null);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PropertyInfo FindThemeProperty(Type type) {
|
||||||
|
return type.GetProperty("CurrentTheme", typeof(ITheme));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user