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-795: Upgrade to latest OC preview to test System.Text.Json #123

Merged
merged 17 commits into from
May 15, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Lombiq.VueJs.Samples/Lombiq.VueJs.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.ContentFields" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.ContentFields" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="ZXing.Net.Bindings.ImageSharp.V2" Version="0.16.15" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions Lombiq.VueJs/Lombiq.VueJs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<SourceGeneratorLocation Condition=" '$(Configuration)' != 'Debug' ">
$(SolutionDir)src\Libraries\Lombiq.HelpfulLibraries\Lombiq.HelpfulLibraries.SourceGenerators\bin\Release\netstandard2.0\Lombiq.HelpfulLibraries.SourceGenerators.dll
</SourceGeneratorLocation>
</PropertyGroup>
</PropertyGroup>

<Target Name="CustomBeforeCompile" BeforeTargets="Compile">
<MSBuild Condition="!Exists('$(SourceGeneratorLocation)')" Projects="..\..\..\Libraries\Lombiq.HelpfulLibraries\Lombiq.HelpfulLibraries.SourceGenerators\Lombiq.HelpfulLibraries.SourceGenerators.csproj" />
Expand Down Expand Up @@ -57,9 +57,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0-preview-18200" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand Down
9 changes: 6 additions & 3 deletions Lombiq.VueJs/Models/GetPageFromQueryResult.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Lombiq.VueJs.Models;

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class GetPageFromQueryResult
{
[JsonPropertyName("items")]
public IEnumerable<object> Items { get; set; }

[JsonPropertyName("pageSize")]
public int PageSize { get; set; }

[JsonPropertyName("pageCount")]
public int PageCount { get; set; }
}
7 changes: 4 additions & 3 deletions Lombiq.VueJs/Models/UrlAndText.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Text.Json.Serialization;

namespace Lombiq.VueJs.Models;

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class UrlAndText
{
[JsonPropertyName("url")]
public string Url { get; set; }

[JsonPropertyName("text")]
public string Text { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Microsoft.AspNetCore.Html;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;

namespace Lombiq.VueJs.Services;
Expand All @@ -20,6 +19,12 @@ namespace Lombiq.VueJs.Services;
/// </remarks>
public abstract class ServerSideValuesVueSingleFileComponentShapeAmenderBase : IVueSingleFileComponentShapeAmender
{
private static readonly JsonSerializerOptions _camelCaseJsonSerializerOptions = new()
{
WriteIndented = false,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};

/// <summary>
/// Gets the value used to compare in <see cref="PrependAsync"/>. If this value is <see langword="null"/> then <see
/// cref="PrependAsync"/> will be called on every Vue.js shape, otherwise only if its name is the value of <see
Expand All @@ -40,18 +45,15 @@ public async ValueTask<IEnumerable<IHtmlContent>> PrependAsync(string shapeName)
{
if (ShapeName != null && ShapeName != shapeName) return Enumerable.Empty<IHtmlContent>();

var values = await GetPropertyValueAsync(shapeName);
var json = JsonConvert.SerializeObject(
values,
Formatting.None,
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
var propertyName = JsonSerializer.Serialize(PropertyName);
var json = JsonSerializer.SerializeToNode(await GetPropertyValueAsync(shapeName), _camelCaseJsonSerializerOptions);

return new[]
{
new HtmlString(
"<script>" +
"if (!window.Vue.$orchardCore) window.Vue.$orchardCore = {};" +
$"window.Vue.$orchardCore[{JsonConvert.SerializeObject(PropertyName)}] = {json};" +
$"window.Vue.$orchardCore[{propertyName}] = {json};" +
"</script>"),
};
}
Expand Down