From 1e2d919b02685bed0f0492aac2d59836a1413280 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sat, 20 Feb 2016 17:44:31 +0100 Subject: [PATCH 1/3] Improved snippets harvester. Fixes #6432 --- .../Providers/SnippetElementHarvester.cs | 39 ++++++++++++------- .../Views/Elements/Snippet.Design.cshtml | 10 ----- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Providers/SnippetElementHarvester.cs b/src/Orchard.Web/Modules/Orchard.Layouts/Providers/SnippetElementHarvester.cs index 80808f43b..8cab0b828 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Providers/SnippetElementHarvester.cs +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Providers/SnippetElementHarvester.cs @@ -32,12 +32,13 @@ namespace Orchard.Layouts.Providers { private readonly Work _shapeDisplay; private readonly Work _currentThemeShapeBindingResolver; private readonly Work _tokenizer; + private readonly IWorkContextAccessor _wca; public SnippetElementHarvester( IWorkContextAccessor workContextAccessor, Work shapeFactory, Work siteThemeService, - Work shapeTableLocator, + Work shapeTableLocator, Work elementFactory, Work shapeDisplay, Work tokenizer, @@ -50,27 +51,26 @@ namespace Orchard.Layouts.Providers { _shapeDisplay = shapeDisplay; _tokenizer = tokenizer; _currentThemeShapeBindingResolver = currentThemeShapeBindingResolver; - workContextAccessor.GetContext(); + _wca = workContextAccessor; } public IEnumerable HarvestElements(HarvestElementsContext context) { var currentThemeName = _siteThemeService.Value.GetCurrentThemeName(); var shapeTable = _shapeTableLocator.Value.Lookup(currentThemeName); var shapeDescriptors = shapeTable.Bindings.Where(x => !String.Equals(x.Key, "Elements_Snippet", StringComparison.OrdinalIgnoreCase) && x.Key.EndsWith(SnippetShapeSuffix, StringComparison.OrdinalIgnoreCase)).ToDictionary(x => x.Key, x => x.Value.ShapeDescriptor); - var elementType = typeof (Snippet); + var elementType = typeof(Snippet); var snippetElement = (Snippet)_elementFactory.Value.Activate(elementType); foreach (var shapeDescriptor in shapeDescriptors) { var shapeType = shapeDescriptor.Value.ShapeType; - var snippetDescriptor = DescribeSnippet(shapeType, snippetElement); var elementName = GetDisplayName(shapeDescriptor.Value.BindingSource); var closureDescriptor = shapeDescriptor; yield return new ElementDescriptor(elementType, shapeType, T(elementName), T("An element that renders the {0} shape.", shapeType), snippetElement.Category) { - Displaying = displayContext => Displaying(displayContext, closureDescriptor.Value, snippetDescriptor), + Displaying = displayContext => Displaying(displayContext, closureDescriptor.Value), ToolboxIcon = "\uf10c", - EnableEditorDialog = snippetDescriptor.Fields.Any(), - Editor = ctx => Editor(snippetDescriptor, ctx), - UpdateEditor = ctx => UpdateEditor(snippetDescriptor, ctx) + EnableEditorDialog = HasSnippetFields(shapeDescriptor.Value), + Editor = ctx => Editor(DescribeSnippet(shapeType, snippetElement), ctx), + UpdateEditor = ctx => UpdateEditor(DescribeSnippet(shapeType, snippetElement), ctx) }; } } @@ -83,7 +83,7 @@ namespace Orchard.Layouts.Providers { var viewModel = new SnippetViewModel { Descriptor = descriptor }; - + if (context.Updater != null) { foreach (var fieldDescriptor in descriptor.Fields) { var name = fieldDescriptor.Name; @@ -109,20 +109,18 @@ namespace Orchard.Layouts.Providers { var snippetEditorShape = context.ShapeFactory.EditorTemplate(TemplateName: "Elements.Snippet", Model: viewModel, Prefix: context.Prefix); snippetEditorShape.Metadata.Position = "Fields:0"; - + context.EditorResult.Add(snippetEditorShape); } - private void Displaying(ElementDisplayingContext context, ShapeDescriptor shapeDescriptor, SnippetDescriptor snippetDescriptor) { + private void Displaying(ElementDisplayingContext context, ShapeDescriptor shapeDescriptor) { var shapeType = shapeDescriptor.ShapeType; var shape = (dynamic)_shapeFactory.Value.Create(shapeType); shape.Element = context.Element; - shape.SnippetDescriptor = snippetDescriptor; ElementShapes.AddTokenizers(shape, _tokenizer.Value); context.ElementShape.Snippet = shape; - context.ElementShape.SnippetDescriptor = snippetDescriptor; } private string GetDisplayName(string bindingSource) { @@ -140,9 +138,9 @@ namespace Orchard.Layouts.Providers { private SnippetDescriptor DescribeSnippet(dynamic shape) { // Execute the shape and intercept calls to the Html.SnippetField method. var descriptor = new SnippetDescriptor(); - shape.DescriptorRegistrationCallback = (Action) (fieldDescriptor => { + shape.DescriptorRegistrationCallback = (Action)(fieldDescriptor => { var existingDescriptor = descriptor.Fields.SingleOrDefault(x => x.Name == fieldDescriptor.Name); // Not using Dictionary, as that will break rendering the view for some obscure reason. - + if (existingDescriptor == null) descriptor.Fields.Add(fieldDescriptor); @@ -157,5 +155,16 @@ namespace Orchard.Layouts.Providers { shape.SnippetDescriptor = descriptor; return descriptor; } + + private bool HasSnippetFields(ShapeDescriptor shapeDescriptor) { + var bindingSource = shapeDescriptor.BindingSource; + var localFileName = _wca.GetContext().HttpContext.Server.MapPath(bindingSource); + + if (!File.Exists(localFileName)) + return false; + + var markup = File.ReadAllText(localFileName); + return markup.Contains("@Html.SnippetField"); + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Layouts/Views/Elements/Snippet.Design.cshtml b/src/Orchard.Web/Modules/Orchard.Layouts/Views/Elements/Snippet.Design.cshtml index 27123f005..0be7ad8e4 100644 --- a/src/Orchard.Web/Modules/Orchard.Layouts/Views/Elements/Snippet.Design.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Layouts/Views/Elements/Snippet.Design.cshtml @@ -1,17 +1,7 @@ @using Orchard.Layouts.Elements -@using Orchard.Layouts.Helpers -@using Orchard.Layouts.Models @{ var element = (Snippet) Model.Element; - var snippetDescriptor = (SnippetDescriptor)Model.SnippetDescriptor; }
@T("{0} Snippet", element.Descriptor.DisplayText) - @if (snippetDescriptor.Fields.Any()) { -
    - @foreach(var field in snippetDescriptor.Fields) { -
  • @field.DisplayName: @element.Data.Get(field.Name)
  • - } -
- }
\ No newline at end of file From 9666ba129278e1e95c5a709fe9b86281c6087981 Mon Sep 17 00:00:00 2001 From: Gustavo Tandeciarz Date: Sun, 21 Feb 2016 03:22:38 -0500 Subject: [PATCH 2/3] [Fixes #6411] Theme code generation produces an 'out-of-date' project --- .../CodeGenerationTemplates/ModuleCsProj.txt | 9 +- .../ModuleRootWebConfig.txt | 101 +++++++++++------- .../ModuleTestsCsProj.txt | 2 +- 3 files changed, 70 insertions(+), 42 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleCsProj.txt b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleCsProj.txt index b1657027c..12138960a 100644 --- a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleCsProj.txt +++ b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleCsProj.txt @@ -12,7 +12,7 @@ Properties $$ModuleName$$ $$ModuleName$$ - v4.5.1 + v4.5.2 false @@ -46,20 +46,23 @@ AllRules.ruleset false - + 3.5 + + + + False ..\..\..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - diff --git a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleRootWebConfig.txt b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleRootWebConfig.txt index 68664921b..027838a09 100644 --- a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleRootWebConfig.txt +++ b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleRootWebConfig.txt @@ -1,41 +1,66 @@  + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleTestsCsProj.txt b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleTestsCsProj.txt index 8174d8860..cc692b1c7 100644 --- a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleTestsCsProj.txt +++ b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleTestsCsProj.txt @@ -9,7 +9,7 @@ Properties $$ProjectName$$ $$ProjectName$$ - v4.5 + v4.5.2 4.0 From f8f02bb9ef357d3741330aea4f2d1b754a8cdc39 Mon Sep 17 00:00:00 2001 From: Gustavo Tandeciarz Date: Sun, 21 Feb 2016 19:48:31 -0500 Subject: [PATCH 3/3] Updated space formatting in line with #6072 --- .../ModuleRootWebConfig.txt | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleRootWebConfig.txt b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleRootWebConfig.txt index 027838a09..9c722b6de 100644 --- a/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleRootWebConfig.txt +++ b/src/Orchard.Web/Modules/Orchard.CodeGeneration/CodeGenerationTemplates/ModuleRootWebConfig.txt @@ -1,27 +1,27 @@ - + - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +