Skip to content

Commit

Permalink
Some code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanPetersson committed Nov 22, 2023
1 parent b67c604 commit 757c4f2
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using EPiServer.ServiceLocation;
using EPiServer.Web;
using EPiServer.Web.Mvc;
using EPiServer.Web.Mvc.Html;

namespace Alloy.Mvc._1.Business.Initialization;

Expand Down
6 changes: 2 additions & 4 deletions templates/Alloy.Mvc/Business/PageContextActionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Alloy.Mvc._1.Business;
public class PageContextActionFilter : IResultFilter
{
private readonly PageViewContextFactory _contextFactory;

public PageContextActionFilter(PageViewContextFactory contextFactory)
{
_contextFactory = contextFactory;
Expand All @@ -41,10 +42,7 @@ public void OnResultExecuting(ResultExecutingContext context)

model.Layout = layoutModel;

if (model.Section == null)
{
model.Section = _contextFactory.GetSection(currentContentLink);
}
model.Section ??= _contextFactory.GetSection(currentContentLink);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace Alloy.Mvc._1.Business.Rendering;

public class SiteViewEngineLocationExpander : IViewLocationExpander
{
private static readonly string[] AdditionalPartialViewFormats = new[]
{
private static readonly string[] AdditionalPartialViewFormats =
[
TemplateCoordinator.BlockFolder + "{0}.cshtml",
TemplateCoordinator.PagePartialsFolder + "{0}.cshtml"
};
];

public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
Expand Down
8 changes: 4 additions & 4 deletions templates/Alloy.Mvc/Business/Rendering/TemplateCoordinator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using EPiServer.ServiceLocation;
using Alloy.Mvc._1.Controllers;
using Alloy.Mvc._1.Models.Blocks;
using Alloy.Mvc._1.Models.Pages;
using EPiServer.ServiceLocation;
using EPiServer.Web;
using EPiServer.Web.Mvc;

Expand Down Expand Up @@ -40,7 +40,7 @@ public void Register(TemplateModelCollection viewTemplateModelRegistrator)
viewTemplateModelRegistrator.Add(typeof(TeaserBlock), new TemplateModel
{
Name = "TeaserBlockWide",
Tags = new[] { Globals.ContentAreaTags.WideWidth, Globals.ContentAreaTags.FullWidth },
Tags = [Globals.ContentAreaTags.WideWidth, Globals.ContentAreaTags.FullWidth],
AvailableWithoutTag = false,
});

Expand All @@ -56,7 +56,7 @@ public void Register(TemplateModelCollection viewTemplateModelRegistrator)
{
Name = "PageWide",
Inherit = true,
Tags = new[] { Globals.ContentAreaTags.WideWidth, Globals.ContentAreaTags.FullWidth },
Tags = [Globals.ContentAreaTags.WideWidth, Globals.ContentAreaTags.FullWidth],
AvailableWithoutTag = false,
Path = PagePartialPath("PageWide.cshtml")
});
Expand All @@ -65,7 +65,7 @@ public void Register(TemplateModelCollection viewTemplateModelRegistrator)
{
Name = "NoRenderer",
Inherit = true,
Tags = new[] { Globals.ContentAreaTags.NoRenderer },
Tags = [Globals.ContentAreaTags.NoRenderer],
AvailableWithoutTag = false,
Path = BlockPath("NoRenderer.cshtml")
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using EPiServer.Shell;
using Alloy.Mvc._1.Models.Pages;
using EPiServer.Shell;

namespace Alloy.Mvc._1.Business.UIDescriptors;

Expand Down
2 changes: 1 addition & 1 deletion templates/Alloy.Mvc/Controllers/DefaultPageController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EPiServer.Framework.DataAnnotations;
using Alloy.Mvc._1.Models.Pages;
using Alloy.Mvc._1.Models.ViewModels;
using EPiServer.Framework.DataAnnotations;
using Microsoft.AspNetCore.Mvc;

namespace Alloy.Mvc._1.Controllers;
Expand Down
2 changes: 1 addition & 1 deletion templates/Alloy.Mvc/Controllers/PreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Alloy.Mvc._1.Controllers;
[TemplateDescriptor(
Inherited = true,
TemplateTypeCategory = TemplateTypeCategories.MvcController, //Required as controllers for blocks are registered as MvcPartialController by default
Tags = new[] { RenderingTags.Preview, RenderingTags.Edit },
Tags = [RenderingTags.Preview, RenderingTags.Edit],
AvailableWithoutTag = false)]
[VisitorGroupImpersonation]
[RequireClientResources]
Expand Down
2 changes: 1 addition & 1 deletion templates/Alloy.Mvc/Extensions/ViewContextExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class ViewContextExtension
/// <param name="viewContext"></param>
/// <returns></returns>
public static bool IsPreviewMode(this ViewContext viewContext)
=> viewContext.IsInEditMode() && (viewContext.ActionDescriptor as ControllerActionDescriptor)?.ControllerName == "Preview";
=> viewContext.IsInEditMode() && viewContext.ActionDescriptor is ControllerActionDescriptor { ControllerName: "Preview" };

/// <summary>
/// Determines if the request context is in edit mode.
Expand Down
4 changes: 2 additions & 2 deletions templates/Alloy.Mvc/Helpers/CategorizableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static string[] GetThemeCssClassNames(this ICategorizable content)
{
if (content.Category == null)
{
return Array.Empty<string>();
return [];
}

// Although with some overhead, a HashSet allows us to ensure we never add a CSS class more than once
Expand All @@ -43,6 +43,6 @@ public static string[] GetThemeCssClassNames(this ICategorizable content)
}
}

return cssClasses.ToArray();
return [.. cssClasses];
}
}
1 change: 0 additions & 1 deletion templates/Alloy.Mvc/Helpers/UrlHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EPiServer.ServiceLocation;
using EPiServer.Shell.Navigation;
using EPiServer.Web.Routing;
using Microsoft.AspNetCore.Mvc;

Expand Down
4 changes: 2 additions & 2 deletions templates/Alloy.Mvc/Models/Pages/ProductPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Alloy.Mvc._1.Models.Pages;
[SiteImageUrl(Globals.StaticGraphicsFolderPath + "page-type-thumbnail-product.png")]
[AvailableContentTypes(
Availability = Availability.Specific,
IncludeOn = new[] { typeof(StartPage) })]
IncludeOn = [typeof(StartPage)])]
public class ProductPage : StandardPage, IHasRelatedContent
{
[Required]
Expand All @@ -25,6 +25,6 @@ public class ProductPage : StandardPage, IHasRelatedContent
GroupName = SystemTabNames.Content,
Order = 330)]
[CultureSpecific]
[AllowedTypes(new[] { typeof(IContentData) }, new[] { typeof(JumbotronBlock) })]
[AllowedTypes([typeof(IContentData)], [typeof(JumbotronBlock)])]
public virtual ContentArea RelatedContentArea { get; set; }
}
2 changes: 1 addition & 1 deletion templates/Alloy.Mvc/Models/Pages/SearchPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class SearchPage : SitePageData, IHasRelatedContent, ISearchPage
GroupName = SystemTabNames.Content,
Order = 310)]
[CultureSpecific]
[AllowedTypes(new[] { typeof(IContentData) }, new[] { typeof(JumbotronBlock) })]
[AllowedTypes([typeof(IContentData)], [typeof(JumbotronBlock)])]
public virtual ContentArea RelatedContentArea { get; set; }
}
13 changes: 7 additions & 6 deletions templates/Alloy.Mvc/Models/Pages/StartPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ namespace Alloy.Mvc._1.Models.Pages;
[SiteImageUrl]
[AvailableContentTypes(
Availability.Specific,
Include = new[]
{
Include =
[
typeof(ContainerPage),
typeof(ProductPage),
typeof(StandardPage),
typeof(ISearchPage),
typeof(LandingPage),
typeof(ContentFolder) }, // Pages we can create under the start page...
ExcludeOn = new[]
{
typeof(ContentFolder)
], // Pages we can create under the start page...
ExcludeOn =
[
typeof(ContainerPage),
typeof(ProductPage),
typeof(StandardPage),
typeof(ISearchPage),
typeof(LandingPage)
})] // ...and underneath those we can't create additional start pages
])] // ...and underneath those we can't create additional start pages
public class StartPage : SitePageData
{
[Display(
Expand Down
2 changes: 1 addition & 1 deletion templates/Alloy.Mvc/Models/ViewModels/PreviewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public PreviewModel(SitePageData currentPage, IContent previewContent)

public IContent PreviewContent { get; set; }

public List<PreviewArea> Areas { get; set; }
public List<PreviewArea> Areas { get; set; } = [];

public class PreviewArea
{
Expand Down

0 comments on commit 757c4f2

Please sign in to comment.