Skip to content

Commit

Permalink
Refactoring prefix generation (OrchardCMS#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros authored Nov 2, 2017
1 parent 098940b commit 9e7a600
Show file tree
Hide file tree
Showing 57 changed files with 620 additions and 387 deletions.
1 change: 1 addition & 0 deletions src/OrchardCore.Build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<XunitAnalyzers>0.3.0</XunitAnalyzers>
<XunitVersion>2.3.0-beta2-build3683</XunitVersion>
<XunitRunnerVisualStudioVersion>2.3.0-beta2-build1317</XunitRunnerVisualStudioVersion>
<FluidCoreVersion>1.0.0-beta-9389</FluidCoreVersion>
<YesSqlVersion>2.0.0-beta-1090</YesSqlVersion>
<YesSqlProvidersVersion>1.0.0-beta-1090</YesSqlProvidersVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OrchardCore.Alias.Settings
{
public class AliasPartSettingsDisplayDriver : ContentTypePartDisplayDriver
public class AliasPartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver
{
public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace OrchardCore.Autoroute.Settings
{
public class AutoroutePartSettingsDisplayDriver : ContentTypePartDisplayDriver
public class AutoroutePartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver
{
public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater)
{
Expand Down
42 changes: 20 additions & 22 deletions src/OrchardCore.Modules/OrchardCore.Body/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@

## Theming

These shapes are available for theming
### Shapes

### BodyPart
The following shapes are rendered when the **BodyPart** is attached to a content type

| Name | Display Type | Default Location | Model Type |
| ------| ------------ |----------------- | ---------- |
| `BodyPart` | `Detail` | `Content:5` | `BodyPartViewModel` |
| `BodyPart_Summary` | `Summary` | `Content:10` | `BodyPartViewModel` |

This shape is rendered when a `BodyPart` is attached to a content item.
The shape based class is of type `BodyPartViewModel`.
### BodyPartViewModel

The following properties are available on the `BodyPartViewModel` class.

| Property | Type | Description |
| --------- | ---- |------------ |
| `Body` | `string` | The HTML content once all tokens have been processed |
| `Body` | `string` | The content that was edited. It might contain tokens. |
| `Html` | `string` | The HTML content once all tokens have been processed |
| `ContentItem` | `ContentItem` | The content item of the part |
| `BodyPart` | `BodyPart` | The `BodyPart` instance|
| `TypePartSettings` | `BodyPartSettings` | The settings of the part |

### BodyPart

The following properties are available on `BodyPart`

| Name | Type | Description |
| -----| ---- |------------ |
| `Body` | `string` | The HTML content in the body. It can contain Liquid tags so using it directly might result in unexpected results. Prefer rendering the `BodyPart` shape instead |
| `Content` | The raw content of the part |
| `ContentItem` | The content item containing this part |

## Editors

The __Body Part__ editor can be different for each content type. In the __Body Part__ settings of a
Expand Down Expand Up @@ -75,23 +90,6 @@ You can override the HTML editor for the `Default` editor by creating a shape fi
`Body.Editor.cshtml`. The Wysiwyg editor is defined by using the file named
`Body-Wysiwyg.Editor.cshtml`.

## Theming

The following shapes are rendered when the **BodyPart** is attached to a content type

| Name | Display Type | Default Location | Model Type |
| ------| ------------ |----------------- | ---------- |
| `BodyPart` | `Detail` | `Content:5` | `BodyPartViewModel` |
| `BodyPart_Summary` | `Summary` | `Content:10` | `BodyPartViewModel` |

### BodyPartViewModel

The following properties are available on `BodyPartViewModel`

| Name | Type | Description |
| -----| ---- |------------ |
| `Body` | `string` | The HTML content in the body. It can contain Liquid tags so using it directly might result in unexpected results. Prefer rendering the `BodyPart` shape instead |

## CREDITS

### Trumbowyg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OrchardCore.Body.Settings
{
public class BodyPartSettingsDisplayDriver : ContentTypePartDisplayDriver
public class BodyPartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver
{
public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace OrchardCore.ContentFields.Settings
{

public class BooleanFieldSettingsDriver : ContentPartFieldDisplayDriver<BooleanField>
public class BooleanFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver<BooleanField>
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace OrchardCore.ContentFields.Settings
{

public class HtmlFieldSettingsDriver : ContentPartFieldDisplayDriver<HtmlField>
public class HtmlFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver<HtmlField>
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace OrchardCore.ContentFields.Settings
{
public class LinkFieldSettingsDriver : ContentPartFieldDisplayDriver<LinkField>
public class LinkFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver<LinkField>
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace OrchardCore.ContentFields.Settings
{

public class NumericFieldSettingsDriver : ContentPartFieldDisplayDriver<NumericField>
public class NumericFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver<NumericField>
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace OrchardCore.ContentFields.Settings
{

public class TextFieldSettingsDriver : ContentPartFieldDisplayDriver<TextField>
public class TextFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver<TextField>
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace OrchardCore.ContentTypes.Editors
{
public class ContentPartSettingsDisplayDriver : ContentPartDisplayDriver
public class ContentPartSettingsDisplayDriver : ContentPartDefinitionDisplayDriver
{

public override IDisplayResult Edit(ContentPartDefinition contentPartDefinition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OrchardCore.ContentTypes.Editors
{
public class ContentTypePartSettingsDisplayDriver : ContentTypePartDisplayDriver
public class ContentTypePartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver
{
public override IDisplayResult Edit(ContentTypePartDefinition model, IUpdateModel updater)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace OrchardCore.ContentTypes.Editors
{
public class ContentTypeSettingsDisplayDriver : ContentTypeDisplayDriver
public class ContentTypeSettingsDisplayDriver : ContentTypeDefinitionDisplayDriver
{
public override IDisplayResult Edit(ContentTypeDefinition contentTypeDefinition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OrchardCore.ContentTypes.Editors
{
public class DefaultContentTypeDisplayDriver : ContentTypeDisplayDriver
public class DefaultContentTypeDisplayDriver : ContentTypeDefinitionDisplayDriver
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace OrchardCore.Lists.Settings
{
public class CommonPartSettingsDisplayDriver : ContentTypePartDisplayDriver
public class CommonPartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace OrchardCore.Flows.Settings
{
public class BagPartSettingsDisplayDriver : ContentTypePartDisplayDriver
public class BagPartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fluid.Core" Version="1.0.0-beta-9327" />
<PackageReference Include="Fluid.Core" Version="$(FluidCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(AspNetCoreVersion)" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/OrchardCore.Modules/OrchardCore.Liquid/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Startup : StartupBase
static Startup()
{
TemplateContext.GlobalMemberAccessStrategy.Register<ContentItem>();
TemplateContext.GlobalMemberAccessStrategy.Register<ContentElement>();

// When accessing a property of a JObject instance
TemplateContext.GlobalMemberAccessStrategy.Register<JObject>((obj, name) => obj[name]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentManagement.Records;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Lists.Indexes;
using OrchardCore.Lists.Models;
using OrchardCore.Lists.ViewModels;
using OrchardCore.Navigation;
using YesSql;

Expand Down Expand Up @@ -43,55 +41,18 @@ IServiceProvider serviceProvider

public override IDisplayResult Display(ListPart listPart, BuildPartDisplayContext context)
{
return Combine(
Shape("ListPart_DetailAdmin", async shape =>
{
var pager = await GetPagerAsync(context.Updater, listPart);

var contentItemDisplayManager = _serviceProvider.GetService<IContentItemDisplayManager>();
var containedItems = await QueryListItemsAsync(listPart, pager, false);
var containedItemsSummaries = new List<dynamic>();

foreach (var contentItem in containedItems)
{
containedItemsSummaries.Add(await contentItemDisplayManager.BuildDisplayAsync(contentItem, context.Updater, "SummaryAdmin"));
}

shape.ContentItems = containedItemsSummaries;
shape.ContentItem = listPart.ContentItem;
shape.ContainedContentTypeDefinitions = GetContainedContentTypes(listPart);
shape.Pager = await context.New.PagerSlim(pager);
})
.Location("DetailAdmin", "Content:10"),

Shape("ListPart", async shape =>
{
var pager = await GetPagerAsync(context.Updater, listPart);

var contentItemDisplayManager = _serviceProvider.GetService<IContentItemDisplayManager>();
var containedItems = await QueryListItemsAsync(listPart, pager, true);
var containedItemsSummaries = new List<dynamic>();
var listContentType = listPart.ContentItem.ContentType;

foreach (var contentItem in containedItems)
{
var itemShape = await contentItemDisplayManager.BuildDisplayAsync(contentItem, context.Updater, "Summary") as IShape;
itemShape.Metadata.Alternates.Add($"ListPart_Summary__{listContentType}");
containedItemsSummaries.Add(itemShape);
}

shape.ContentItems = containedItemsSummaries;
shape.ContentItem = listPart.ContentItem;
shape.ContainedContentTypeDefinitions = GetContainedContentTypes(listPart);
shape.Pager = await context.New.PagerSlim(pager);
})
.Displaying(displaying =>
{
var listContentType = listPart.ContentItem.ContentType;
displaying.Shape.Metadata.Alternates.Add($"ListPart__{listContentType}");
})
.Location("Detail", "Content:10")
);
return Shape<ListPartViewModel>("ListPart", async model =>
{
var pager = await GetPagerAsync(context.Updater, listPart);

model.ListPart = listPart;
model.ContentItems = (await QueryListItemsAsync(listPart, pager, true)).ToArray();
model.ContainedContentTypeDefinitions = GetContainedContentTypes(listPart);
model.Context = context;
model.Pager = await context.New.PagerSlim(pager);
})
.Location("Detail", "Content:10")
.Location("DetailAdmin", "Content:10");
}

private async Task<PagerSlim> GetPagerAsync(IUpdateModel updater, ListPart part)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ListPartFeedDisplayDriver : ContentPartDisplayDriver<ListPart>
{
public override IDisplayResult Display(ListPart listPart, BuildPartDisplayContext context)
{
return Shape("ListPart_Feed", shape =>
return Shape("ListPartFeed", shape =>
{
shape.ContentItem = listPart.ContentItem;
})
Expand Down
6 changes: 1 addition & 5 deletions src/OrchardCore.Modules/OrchardCore.Lists/Models/ListPart.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using OrchardCore.ContentManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OrchardCore.ContentManagement;

namespace OrchardCore.Lists.Models
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(AspNetCoreVersion)" />
</ItemGroup>

<ItemGroup>
<None Update="README.md">
<PackagePath>assets\$(PackageId)\</PackagePath>
</None>
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Lists/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Lists (OrchardCore.Lists)

## Theming

### Shapes

These shapes are available for theming when a `ListPart` is attached to a content item.

| Name | Display Type | Default Location | Model Type |
| ------| ------------ |----------------- | ---------- |
| `ListPart` | `Detail`, `DetailAdmin` | `Content:10` | `ListPartViewModel` |

### ListPartViewModel

The following properties are available on the `ListPartViewModel` class.

| Property | Type | Description |
| --------- | ---- |------------ |
| `ListPart` | `ListPart` | The `ListPart` instance |
| `ContentItems` | `IEnumerable<ContentItem>` | The content items the part is made of |
| `ContainedContentTypeDefinitions` | IEnumerable<ContentTypeDefinition> | The content types the list accepts |
| `Context` | `BuildPartDisplayContext` | The current display context |
| `Pager` | `dynamic` | The pager for the list |

### ListPart

The following properties are available on the `ListPart` class.

| Name | Type | Description |
| -----| ---- |------------ |
| `Content` | The raw content of the part |
| `ContentItem` | The content item containing this part |

## CREDITS

### Trumbowyg
<https://github.com/Alex-D/Trumbowyg>
Copyright (c) 2012-2016 Alexandre Demode (Alex-D)
License: MIT
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace OrchardCore.Lists.Settings
{
public class ListPartSettingsDisplayDriver : ContentTypePartDisplayDriver
public class ListPartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
Loading

0 comments on commit 9e7a600

Please sign in to comment.