Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-49: Enforce Windows newlines for C# files to avoid false positives with IDE0055 warning. #68

Merged
merged 6 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
* text=auto

# Enforce Windows newlines for C# files to avoid false positives with IDE0055 warning.
# See https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions/issues/106 for more information.
*.cs text eol=crlf
14 changes: 7 additions & 7 deletions Extensions/Widgets/Constants/RouteValueNames.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Lombiq.HelpfulExtensions.Extensions.Widgets.Constants;
public static class RouteValueNames
{
private const string MenuWidgetRoot = "Lombiq.MenuWidget.";
public const string MenuWidgetPost = MenuWidgetRoot + "Post";
}
namespace Lombiq.HelpfulExtensions.Extensions.Widgets.Constants;

public static class RouteValueNames
{
private const string MenuWidgetRoot = "Lombiq.MenuWidget.";
public const string MenuWidgetPost = MenuWidgetRoot + "Post";
}
278 changes: 139 additions & 139 deletions Views/MenuWidget.cshtml
Original file line number Diff line number Diff line change
@@ -1,139 +1,139 @@
@using Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels
@using Microsoft.AspNetCore.Http.Extensions
@using OrchardCore.Navigation
<style asp-name="font-awesome"></style>
@{
var viewModel = new MenuWidgetViewModel(Model);
const string blockName = "menuWidget";
const string contentElementName = blockName + "__content";
const string togglerElementName = blockName + "__toggler";
const string dropdownElementName = blockName + "__dropdown";
const string dropdownItemElementName = blockName + "__dropdownItem";
var contentIdName = FormattableString.Invariant($"{contentElementName}_{Guid.NewGuid()}");
var baseUri = new Uri(Context.Request.GetDisplayUrl());
var menuItems = viewModel
.MenuItems
.OrderBy(item => double.TryParse(item.Position, out var number) ? number : double.MaxValue)
.ThenBy(item => item.Position);
// We use LocalizedString.Name instead of Value intentionally, as this shouldn't be affected by localization.
bool IsDivider(MenuItem menuItem) =>
menuItem.Text.Name.Length >= 3 && menuItem.Text.Name.All(character => character == '-');
bool IsFormPost(Uri uri) => uri
.Query
.TrimStart('?')
.Split('&')
.Contains("Lombiq.MenuWidget.Post=true", StringComparer.OrdinalIgnoreCase);
}
@if (!viewModel.NoWrapper)
{
@:<nav class="navbar navbar-expand-md">
}
<div class="container-fluid">
<button class="navbar-toggler @togglerElementName"
type="button"
data-bs-toggle="collapse"
data-bs-target="#@contentIdName"
aria-controls="@contentIdName"
aria-expanded="false"
aria-label="@T["Toggle Navigation"]">
<span class="navbar-toggler-icon fas fa-bars"></span>
</button>
<div id="@contentIdName" class="collapse navbar-collapse @contentElementName">
<ul class="navbar-nav me-auto mb-lg-0">
@foreach (var menuItem in menuItems)
{
var dropdownIdName = FormattableString.Invariant($"{dropdownElementName}_{Guid.NewGuid()}");
@if (menuItem.Items.Any())
{
var submenuItems = menuItem
.Items
.OrderBy(item => double.TryParse(item.Position, out var number) ? number : double.MaxValue)
.ThenBy(item => item.Position);
<li class="nav-item dropdown">
<a id="@dropdownIdName"
class="nav-link dropdown-toggle @dropdownElementName"
href="#"
data-bs-toggle="dropdown"
aria-expanded="false">@menuItem.Text</a>
<ul class="dropdown-menu" aria-labelledby="@dropdownIdName">
@foreach (var submenu in submenuItems)
{
var uri = new Uri(baseUri, submenu.Href);
var isActive = baseUri.AbsolutePath.EqualsOrdinalIgnoreCase(uri.AbsolutePath);
var dropdownClasses = $"dropdown-item {(isActive ? "active" : string.Empty)} " +
$"{submenu.Classes.Join()} {dropdownItemElementName}";
if (IsDivider(submenu))
{
<li><hr class="dropdown-divider"></li>
}
else if (IsFormPost(uri))
{
<li>
<form method="post" action="@submenu.Href">
@Html.AntiForgeryToken()
<button class="@dropdownClasses" type="submit">@submenu.Text</button>
</form>
</li>
}
else
{
<li>
<a id="@submenu.Id"
class="@dropdownClasses"
@if (!submenu.LocalNav)
{
<text>target="_blank"</text>
}
href="@submenu.Href">@submenu.Text</a>
</li>
}
}
</ul>
</li>
}
else if (IsDivider(menuItem))
{
<li><hr class="dropdown-divider"></li>
}
else
{
var uri = new Uri(baseUri, menuItem.Href);
var isActive = baseUri.AbsolutePath.EqualsOrdinalIgnoreCase(uri.AbsolutePath);
var linkClasses = $"nav-link {(isActive ? "active" : string.Empty)} {menuItem.Classes.Join()}";
<li class="nav-item menuWidget__topLevel @(isActive ? "nav-item-link-active" : string.Empty)">
@if (IsFormPost(uri))
{
<form method="post" action="@menuItem.Href">
@Html.AntiForgeryToken()
<button class="@linkClasses" type="submit">@menuItem.Text</button>
</form>
}
else
{
<a id="@menuItem.Id"
class="@linkClasses"
@if (!menuItem.LocalNav)
{
<text>target="_blank"</text>
}
href="@(menuItem.Href ?? string.Empty)">@menuItem.Text</a>
}
</li>
}
}
</ul>
</div>
</div>
@if (!viewModel.NoWrapper)
{
@:</nav>
}
@using Lombiq.HelpfulExtensions.Extensions.Widgets.ViewModels
@using Microsoft.AspNetCore.Http.Extensions
@using OrchardCore.Navigation
<style asp-name="font-awesome"></style>

@{
var viewModel = new MenuWidgetViewModel(Model);

const string blockName = "menuWidget";
const string contentElementName = blockName + "__content";
const string togglerElementName = blockName + "__toggler";
const string dropdownElementName = blockName + "__dropdown";
const string dropdownItemElementName = blockName + "__dropdownItem";

var contentIdName = FormattableString.Invariant($"{contentElementName}_{Guid.NewGuid()}");

var baseUri = new Uri(Context.Request.GetDisplayUrl());

var menuItems = viewModel
.MenuItems
.OrderBy(item => double.TryParse(item.Position, out var number) ? number : double.MaxValue)
.ThenBy(item => item.Position);

// We use LocalizedString.Name instead of Value intentionally, as this shouldn't be affected by localization.
bool IsDivider(MenuItem menuItem) =>
menuItem.Text.Name.Length >= 3 && menuItem.Text.Name.All(character => character == '-');

bool IsFormPost(Uri uri) => uri
.Query
.TrimStart('?')
.Split('&')
.Contains("Lombiq.MenuWidget.Post=true", StringComparer.OrdinalIgnoreCase);
}

@if (!viewModel.NoWrapper)
{
@:<nav class="navbar navbar-expand-md">
}
<div class="container-fluid">
<button class="navbar-toggler @togglerElementName"
type="button"
data-bs-toggle="collapse"
data-bs-target="#@contentIdName"
aria-controls="@contentIdName"
aria-expanded="false"
aria-label="@T["Toggle Navigation"]">
<span class="navbar-toggler-icon fas fa-bars"></span>
</button>
<div id="@contentIdName" class="collapse navbar-collapse @contentElementName">
<ul class="navbar-nav me-auto mb-lg-0">
@foreach (var menuItem in menuItems)
{
var dropdownIdName = FormattableString.Invariant($"{dropdownElementName}_{Guid.NewGuid()}");
@if (menuItem.Items.Any())
{
var submenuItems = menuItem
.Items
.OrderBy(item => double.TryParse(item.Position, out var number) ? number : double.MaxValue)
.ThenBy(item => item.Position);
<li class="nav-item dropdown">
<a id="@dropdownIdName"
class="nav-link dropdown-toggle @dropdownElementName"
href="#"
data-bs-toggle="dropdown"
aria-expanded="false">@menuItem.Text</a>
<ul class="dropdown-menu" aria-labelledby="@dropdownIdName">
@foreach (var submenu in submenuItems)
{
var uri = new Uri(baseUri, submenu.Href);
var isActive = baseUri.AbsolutePath.EqualsOrdinalIgnoreCase(uri.AbsolutePath);
var dropdownClasses = $"dropdown-item {(isActive ? "active" : string.Empty)} " +
$"{submenu.Classes.Join()} {dropdownItemElementName}";
if (IsDivider(submenu))
{
<li><hr class="dropdown-divider"></li>
}
else if (IsFormPost(uri))
{
<li>
<form method="post" action="@submenu.Href">
@Html.AntiForgeryToken()
<button class="@dropdownClasses" type="submit">@submenu.Text</button>
</form>
</li>
}
else
{
<li>
<a id="@submenu.Id"
class="@dropdownClasses"
@if (!submenu.LocalNav)
{
<text>target="_blank"</text>
}
href="@submenu.Href">@submenu.Text</a>
</li>
}
}
</ul>
</li>
}
else if (IsDivider(menuItem))
{
<li><hr class="dropdown-divider"></li>
}
else
{
var uri = new Uri(baseUri, menuItem.Href);
var isActive = baseUri.AbsolutePath.EqualsOrdinalIgnoreCase(uri.AbsolutePath);
var linkClasses = $"nav-link {(isActive ? "active" : string.Empty)} {menuItem.Classes.Join()}";
<li class="nav-item menuWidget__topLevel @(isActive ? "nav-item-link-active" : string.Empty)">
@if (IsFormPost(uri))
{
<form method="post" action="@menuItem.Href">
@Html.AntiForgeryToken()
<button class="@linkClasses" type="submit">@menuItem.Text</button>
</form>
}
else
{
<a id="@menuItem.Id"
class="@linkClasses"
@if (!menuItem.LocalNav)
{
<text>target="_blank"</text>
}
href="@(menuItem.Href ?? string.Empty)">@menuItem.Text</a>
}
</li>
}
}
</ul>
</div>
</div>

@if (!viewModel.NoWrapper)
{
@:</nav>
}