#20658: Factored out Razor-related services in Templates to separate feature.

Work Item: 20658
This commit is contained in:
Lombiq
2014-05-20 16:03:55 +02:00
committed by Zoltán Lehóczky
parent bca9ca1304
commit 45392f60de
8 changed files with 63 additions and 6 deletions

View File

@@ -14,8 +14,7 @@ namespace Orchard.Templates {
.WithPart("CommonPart")
.WithPart("IdentityPart")
.WithPart("TitlePart")
.WithPart("ShapePart", p => p
.WithSetting("ShapePartSettings.Processor", "Razor"))
.WithPart("ShapePart")
.Draftable());
return 1;
}

View File

@@ -4,10 +4,15 @@ Author: The Orchard Team
Website: http://orchardproject.net
Version: 1.8.1
OrchardVersion: 1.8
Description: Provides a Template type that can be used to store Razor code and used as a shape.
Description: Provides a Template type that can be used to store template code and used as a shape.
Features:
Orchard.Templates:
Name: Templates
Description: Provides a Template type that represents a Razor template, stored as a content item.
Description: Provides a Template type that represents a shape template, stored as a content item.
Category: Content
Dependencies: Contents, Orchard.Tokens
Dependencies: Contents, Orchard.Tokens
Orchard.Templates.Razor:
Name: Razor Templates
Description: Extends Templates with Razor templates.
Category: Content
Dependencies: Orchard.Templates

View File

@@ -167,8 +167,10 @@
<Compile Include="Drivers\ShapePartDriver.cs" />
<Compile Include="Models\ShapePart.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="RazorMigrations.cs" />
<Compile Include="Services\ITemplateProcessor.cs" />
<Compile Include="Services\ITemplateService.cs" />
<Compile Include="Services\NoTemplateProcessorBanner.cs" />
<Compile Include="Services\Razor\IRazorCompiler.cs" />
<Compile Include="Services\Razor\RazorCompiler.cs" />
<Compile Include="Services\Razor\RazorTemplateBase.cs" />

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Data.Migration;
using Orchard.ContentManagement.MetaData;
using Orchard.Environment.Extensions;
namespace Orchard.Templates {
[OrchardFeature("Orchard.Templates.Razor")]
public class RazorMigrations : DataMigrationImpl {
public int Create() {
ContentDefinitionManager.AlterTypeDefinition("Template", type => type
.WithPart("ShapePart", p => p
.WithSetting("ShapePartSettings.Processor", "Razor")));
return 1;
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Localization;
using Orchard.UI.Admin.Notification;
using Orchard.UI.Notify;
namespace Orchard.Templates.Services {
public class NoTemplateProcessorBanner : INotificationProvider {
private readonly IEnumerable<ITemplateProcessor> _processors;
public NoTemplateProcessorBanner(IEnumerable<ITemplateProcessor> processors) {
_processors = processors;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public IEnumerable<NotifyEntry> GetNotifications() {
if (!_processors.Any()) {
yield return new NotifyEntry { Message = T("To be able to use Templates enable a template processor like Razor Templates."), Type = NotifyType.Warning };
}
}
}
}

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic;
namespace Orchard.Templates.Compilation.Razor {
public interface IRazorCompiler : IDependency {
public interface IRazorCompiler : IDependency {
IRazorTemplateBase<TModel> CompileRazor<TModel>(string code, string name, IDictionary<string, object> parameters);
IRazorTemplateBase CompileRazor(string code, string name, IDictionary<string, object> parameters);
}

View File

@@ -10,10 +10,12 @@ using System.Text;
using System.Web.Razor;
using Microsoft.CSharp;
using Orchard.Caching;
using Orchard.Environment.Extensions;
using Orchard.Logging;
using Orchard.Utility.Extensions;
namespace Orchard.Templates.Compilation.Razor {
[OrchardFeature("Orchard.Templates.Razor")]
public class RazorCompiler : IRazorCompiler {
private readonly ICacheManager _cache;
private readonly ISignals _signals;

View File

@@ -7,9 +7,12 @@ using System.Web.Mvc;
using System.Web.UI;
using System.Web.WebPages;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.Extensions;
using Orchard.Logging;
using Orchard.Templates.Compilation.Razor;
namespace Orchard.Templates.Services {
[OrchardFeature("Orchard.Templates.Razor")]
public class RazorTemplateProcessor : TemplateProcessorImpl {
private readonly IRazorCompiler _compiler;
private readonly HttpContextBase _httpContextBase;