Skip to content

Commit

Permalink
Shortcodes refactor (#6561)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanmarcussen authored Jul 7, 2020
1 parent fff5e67 commit 3f23481
Show file tree
Hide file tree
Showing 43 changed files with 296 additions and 287 deletions.
4 changes: 2 additions & 2 deletions OrchardCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Docs", "src\doc
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Markdown.Abstractions", "src\OrchardCore\OrchardCore.Markdown.Abstractions\OrchardCore.Markdown.Abstractions.csproj", "{38EE0258-F010-425B-949F-9ECCE886584B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.ShortCodes", "src\OrchardCore.Modules\OrchardCore.ShortCodes\OrchardCore.ShortCodes.csproj", "{9EEEB83D-85C5-4025-8367-CD7D1ACBBB1A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Shortcodes", "src\OrchardCore.Modules\OrchardCore.Shortcodes\OrchardCore.Shortcodes.csproj", "{9EEEB83D-85C5-4025-8367-CD7D1ACBBB1A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.ShortCodes.Abstractions", "src\OrchardCore\OrchardCore.ShortCodes.Abstractions\OrchardCore.ShortCodes.Abstractions.csproj", "{901DA1A3-E5C7-4965-80EA-A1780BE1B820}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Shortcodes.Abstractions", "src\OrchardCore\OrchardCore.Shortcodes.Abstractions\OrchardCore.Shortcodes.Abstractions.csproj", "{901DA1A3-E5C7-4965-80EA-A1780BE1B820}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ nav:
- Media Azure: docs/reference/modules/Media.Azure/README.md
- ReCaptcha: docs/reference/modules/ReCaptcha/README.md
- Resources: docs/reference/modules/Resources/README.md
- ShortCodes: docs/reference/modules/ShortCodes/README.md
- Shortcodes: docs/reference/modules/Shortcodes/README.md
- Sitemaps: docs/reference/modules/Sitemaps/README.md
- XML-RPC: docs/reference/modules/XmlRpc/README.md
- Menu: docs/reference/modules/Menu/README.md
Expand Down
1 change: 1 addition & 0 deletions src/OrchardCore.Build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<PackageManagement Include="OpenIddict.Core" Version="2.0.1" />
<PackageManagement Include="OrchardCore.Translations.All" Version="1.0.0-rc2-108003" />
<PackageManagement Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageManagement Include="Shortcodes" Version="1.0.0-beta-141475106" />
<PackageManagement Include="SixLabors.ImageSharp.Web" Version="1.0.0-rc0003" />
<PackageManagement Include="xunit.analyzers" Version="0.10.0" />
<PackageManagement Include="xunit" Version="2.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.ShortCodes.Services;
using OrchardCore.Shortcodes.Services;
using OrchardCore.Infrastructure.Html;
using OrchardCore.Liquid;

Expand All @@ -20,19 +20,19 @@ public class HtmlFieldDisplayDriver : ContentFieldDisplayDriver<HtmlField>
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly HtmlEncoder _htmlEncoder;
private readonly IHtmlSanitizerService _htmlSanitizerService;
private readonly IShortCodeService _shortCodeService;
private readonly IShortcodeService _shortcodeService;
private readonly IStringLocalizer S;

public HtmlFieldDisplayDriver(ILiquidTemplateManager liquidTemplateManager,
HtmlEncoder htmlEncoder,
IHtmlSanitizerService htmlSanitizerService,
IShortCodeService shortCodeService,
IShortcodeService shortcodeService,
IStringLocalizer<HtmlFieldDisplayDriver> localizer)
{
_liquidTemplateManager = liquidTemplateManager;
_htmlEncoder = htmlEncoder;
_htmlSanitizerService = htmlSanitizerService;
_shortCodeService = shortCodeService;
_shortcodeService = shortcodeService;
S = localizer;
}

Expand All @@ -52,7 +52,7 @@ public override IDisplayResult Display(HtmlField field, BuildFieldDisplayContext
scope => scope.SetValue("ContentItem", field.ContentItem));
}

model.Html = await _shortCodeService.ProcessAsync(model.Html);
model.Html = await _shortcodeService.ProcessAsync(model.Html);

})
.Location("Detail", "Content")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Name = "Content Fields",
Category = "Content Management",
Description = "Content Fields module adds common content fields to be used with your custom types.",
Dependencies = new[] { "OrchardCore.ContentTypes", "OrchardCore.ShortCodes" }
Dependencies = new[] { "OrchardCore.ContentTypes", "OrchardCore.Shortcodes" }
)]

[assembly: Feature(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Indexing.Abstractions\OrchardCore.Indexing.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Liquid.Abstractions\OrchardCore.Liquid.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Module.Targets\OrchardCore.Module.Targets.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ShortCodes.Abstractions\OrchardCore.ShortCodes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Shortcodes.Abstractions\OrchardCore.Shortcodes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using OrchardCore.Html.Models;
using OrchardCore.Html.Settings;
using OrchardCore.Html.ViewModels;
using OrchardCore.ShortCodes.Services;
using OrchardCore.Shortcodes.Services;
using OrchardCore.Infrastructure.Html;
using OrchardCore.Liquid;

Expand All @@ -20,19 +20,19 @@ public class HtmlBodyPartDisplayDriver : ContentPartDisplayDriver<HtmlBodyPart>
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly IHtmlSanitizerService _htmlSanitizerService;
private readonly HtmlEncoder _htmlEncoder;
private readonly IShortCodeService _shortCodeService;
private readonly IShortcodeService _shortcodeService;
private readonly IStringLocalizer S;

public HtmlBodyPartDisplayDriver(ILiquidTemplateManager liquidTemplateManager,
IHtmlSanitizerService htmlSanitizerService,
HtmlEncoder htmlEncoder,
IShortCodeService shortCodeService,
IShortcodeService shortcodeService,
IStringLocalizer<HtmlBodyPartDisplayDriver> localizer)
{
_liquidTemplateManager = liquidTemplateManager;
_htmlSanitizerService = htmlSanitizerService;
_htmlEncoder = htmlEncoder;
_shortCodeService = shortCodeService;
_shortcodeService = shortcodeService;
S = localizer;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ private async ValueTask BuildViewModelAsync(HtmlBodyPartViewModel model, HtmlBod
scope => scope.SetValue("ContentItem", model.ContentItem));
}

model.Html = await _shortCodeService.ProcessAsync(model.Html);
model.Html = await _shortcodeService.ProcessAsync(model.Html);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using OrchardCore.Html.Models;
using OrchardCore.Html.Settings;
using OrchardCore.Html.ViewModels;
using OrchardCore.ShortCodes.Services;
using OrchardCore.Shortcodes.Services;
using OrchardCore.Liquid;

namespace OrchardCore.Html.GraphQL
Expand All @@ -30,7 +30,7 @@ public HtmlBodyQueryObjectType(IStringLocalizer<HtmlBodyQueryObjectType> S)
private static async Task<object> RenderHtml(ResolveFieldContext<HtmlBodyPart> ctx)
{
var serviceProvider = ctx.ResolveServiceProvider();
var shortCodeService = serviceProvider.GetRequiredService<IShortCodeService>();
var shortcodeService = serviceProvider.GetRequiredService<IShortcodeService>();
var contentDefinitionManager = serviceProvider.GetRequiredService<IContentDefinitionManager>();

var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(ctx.Source.ContentItem.ContentType);
Expand All @@ -54,7 +54,7 @@ private static async Task<object> RenderHtml(ResolveFieldContext<HtmlBodyPart> c
scope => scope.SetValue("ContentItem", model.ContentItem));
}

return await shortCodeService.ProcessAsync(html);
return await shortcodeService.ProcessAsync(html);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
using OrchardCore.Html.Models;
using OrchardCore.Html.Settings;
using OrchardCore.Html.ViewModels;
using OrchardCore.ShortCodes.Services;
using OrchardCore.Shortcodes.Services;
using OrchardCore.Liquid;

namespace OrchardCore.Html.Handlers
{
public class HtmlBodyPartHandler : ContentPartHandler<HtmlBodyPart>
{
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly IShortCodeService _shortCodeService;
private readonly IShortcodeService _shortcodeService;
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly HtmlEncoder _htmlEncoder;
private HtmlString _bodyAspect;
private int _contentItemId;

public HtmlBodyPartHandler(IContentDefinitionManager contentDefinitionManager,
IShortCodeService shortCodeService,
IShortcodeService shortcodeService,
ILiquidTemplateManager liquidTemplateManager,
HtmlEncoder htmlEncoder)
{
_contentDefinitionManager = contentDefinitionManager;
_shortCodeService = shortCodeService;
_shortcodeService = shortcodeService;
_liquidTemplateManager = liquidTemplateManager;
_htmlEncoder = htmlEncoder;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context,
scope => scope.SetValue("ContentItem", model.ContentItem));
}

html = await _shortCodeService.ProcessAsync(html);
html = await _shortcodeService.ProcessAsync(html);

bodyAspect.Body = _bodyAspect = new HtmlString(html);
_contentItemId = part.ContentItem.Id;
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Html/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
Website = ManifestConstants.OrchardCoreWebsite,
Version = ManifestConstants.OrchardCoreVersion,
Description = "The Html module enables content items to have Html bodies.",
Dependencies = new[] { "OrchardCore.ContentTypes", "OrchardCore.ShortCodes" },
Dependencies = new[] { "OrchardCore.ContentTypes", "OrchardCore.Shortcodes" },
Category = "Content Management"
)]
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Indexing.Abstractions\OrchardCore.Indexing.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.MetaWeblog.Abstractions\OrchardCore.MetaWeblog.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ShortCodes.Abstractions\OrchardCore.ShortCodes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Shortcodes.Abstractions\OrchardCore.Shortcodes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
using Fluid;
using Fluid.Values;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.ShortCodes.Services;
using OrchardCore.Shortcodes.Services;

namespace OrchardCore.Liquid.Filters
{
public class ShortCodeFilter : ILiquidFilter
public class ShortcodeFilter : ILiquidFilter
{
public async ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, TemplateContext ctx)
{
Expand All @@ -16,9 +16,9 @@ public async ValueTask<FluidValue> ProcessAsync(FluidValue input, FilterArgument
throw new ArgumentException("Services missing while invoking 'shortcode'");
}

var shortCodeService = ((IServiceProvider)services).GetRequiredService<IShortCodeService>();
var shortcodeService = ((IServiceProvider)services).GetRequiredService<IShortcodeService>();

return new StringValue(await shortCodeService.ProcessAsync(input.ToStringValue()));
return new StringValue(await shortcodeService.ProcessAsync(input.ToStringValue()));
}
}
}
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Liquid/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
Website = ManifestConstants.OrchardCoreWebsite,
Version = ManifestConstants.OrchardCoreVersion,
Description = "The liquid module enables content items to have liquid syntax.",
Dependencies = new[] { "OrchardCore.Contents", "OrchardCore.ShortCodes" },
Dependencies = new[] { "OrchardCore.Contents", "OrchardCore.Shortcodes" },
Category = "Content Management"
)]
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement\OrchardCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.DisplayManagement.Liquid\OrchardCore.DisplayManagement.Liquid.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Indexing.Abstractions\OrchardCore.Indexing.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ShortCodes.Abstractions\OrchardCore.ShortCodes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Shortcodes.Abstractions\OrchardCore.Shortcodes.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ResourceManagement\OrchardCore.ResourceManagement.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Liquid/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddLiquidFilter<LiquidFilter>("liquid");
services.AddLiquidFilter<JsonFilter>("json");
services.AddLiquidFilter<JsonParseFilter>("jsonparse");
services.AddLiquidFilter<ShortCodeFilter>("shortcode");
services.AddLiquidFilter<ShortcodeFilter>("shortcode");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.ShortCodes.Services;
using OrchardCore.Shortcodes.Services;
using OrchardCore.Infrastructure.Html;
using OrchardCore.Liquid;
using OrchardCore.Markdown.Models;
Expand All @@ -21,21 +21,21 @@ public class MarkdownBodyPartDisplay : ContentPartDisplayDriver<MarkdownBodyPart
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly HtmlEncoder _htmlEncoder;
private readonly IHtmlSanitizerService _htmlSanitizerService;
private readonly IShortCodeService _shortCodeService;
private readonly IShortcodeService _shortcodeService;
private readonly IMarkdownService _markdownService;
private readonly IStringLocalizer S;

public MarkdownBodyPartDisplay(ILiquidTemplateManager liquidTemplateManager,
HtmlEncoder htmlEncoder,
IHtmlSanitizerService htmlSanitizerService,
IShortCodeService shortCodeService,
IShortcodeService shortcodeService,
IMarkdownService markdownService,
IStringLocalizer<MarkdownBodyPartDisplay> localizer)
{
_liquidTemplateManager = liquidTemplateManager;
_htmlEncoder = htmlEncoder;
_htmlSanitizerService = htmlSanitizerService;
_shortCodeService = shortCodeService;
_shortcodeService = shortcodeService;
_markdownService = markdownService;
S = localizer;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ private async ValueTask BuildViewModel(MarkdownBodyPartViewModel model, Markdown
scope => scope.SetValue("ContentItem", model.ContentItem));
}

model.Html = await _shortCodeService.ProcessAsync(model.Html ?? "");
model.Html = await _shortcodeService.ProcessAsync(model.Html ?? "");

if (settings.SanitizeHtml)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.ShortCodes.Services;
using OrchardCore.Shortcodes.Services;
using OrchardCore.Infrastructure.Html;
using OrchardCore.Liquid;
using OrchardCore.Markdown.Fields;
Expand All @@ -21,21 +21,21 @@ public class MarkdownFieldDisplayDriver : ContentFieldDisplayDriver<MarkdownFiel
private readonly ILiquidTemplateManager _liquidTemplateManager;
private readonly HtmlEncoder _htmlEncoder;
private readonly IHtmlSanitizerService _htmlSanitizerService;
private readonly IShortCodeService _shortCodeService;
private readonly IShortcodeService _shortcodeService;
private readonly IMarkdownService _markdownService;
private readonly IStringLocalizer S;

public MarkdownFieldDisplayDriver(ILiquidTemplateManager liquidTemplateManager,
HtmlEncoder htmlEncoder,
IHtmlSanitizerService htmlSanitizerService,
IShortCodeService shortCodeService,
IShortcodeService shortcodeService,
IMarkdownService markdownService,
IStringLocalizer<MarkdownFieldDisplayDriver> localizer)
{
_liquidTemplateManager = liquidTemplateManager;
_htmlEncoder = htmlEncoder;
_htmlSanitizerService = htmlSanitizerService;
_shortCodeService = shortCodeService;
_shortcodeService = shortcodeService;
_markdownService = markdownService;
S = localizer;
}
Expand All @@ -62,7 +62,7 @@ public override IDisplayResult Display(MarkdownField field, BuildFieldDisplayCon
scope => scope.SetValue("ContentItem", field.ContentItem));
}

model.Html = await _shortCodeService.ProcessAsync(model.Html ?? "");
model.Html = await _shortcodeService.ProcessAsync(model.Html ?? "");

if (settings.SanitizeHtml)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Extensions.Localization;
using OrchardCore.Apis.GraphQL;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ShortCodes.Services;
using OrchardCore.Shortcodes.Services;
using OrchardCore.Infrastructure.Html;
using OrchardCore.Liquid;
using OrchardCore.Markdown.Models;
Expand All @@ -25,7 +25,6 @@ public MarkdownBodyQueryObjectType(IStringLocalizer<MarkdownBodyQueryObjectType>

Field("markdown", x => x.Markdown, nullable: true)
.Description(S["the markdown value"]);

Field<StringGraphType>()
.Name("html")
.Description(S["the HTML representation of the markdown content"])
Expand All @@ -41,7 +40,7 @@ private static async Task<object> ToHtml(ResolveFieldContext<MarkdownBodyPart> c

var serviceProvider = ctx.ResolveServiceProvider();
var markdownService = serviceProvider.GetRequiredService<IMarkdownService>();
var shortCodeService = serviceProvider.GetRequiredService<IShortCodeService>();
var shortcodeService = serviceProvider.GetRequiredService<IShortcodeService>();
var contentDefinitionManager = serviceProvider.GetRequiredService<IContentDefinitionManager>();

var contentTypeDefinition = contentDefinitionManager.GetTypeDefinition(ctx.Source.ContentItem.ContentType);
Expand Down Expand Up @@ -70,7 +69,7 @@ private static async Task<object> ToHtml(ResolveFieldContext<MarkdownBodyPart> c
scope => scope.SetValue("ContentItem", model.ContentItem));
}

html = await shortCodeService.ProcessAsync(html);
html = await shortcodeService.ProcessAsync(html);

if (settings.SanitizeHtml)
{
Expand Down
Loading

0 comments on commit 3f23481

Please sign in to comment.