From d9229a224f6b87d1d354218a28d53fe8bea18aea Mon Sep 17 00:00:00 2001 From: Mark Drake Date: Sat, 2 Sep 2023 00:51:03 -0400 Subject: [PATCH] rcl, various tag helpers --- .../Umbraco_10/Properties/launchSettings.json | 6 +- .testing/Umbraco_10/Umbraco_10.csproj | 1 + .../Umbraco_12/Properties/launchSettings.json | 6 +- .testing/Umbraco_12/Umbraco_12.csproj | 1 + .testing/readme.md | 11 +++ .../Humble.RCL/Humble.RCL.csproj | 27 -------- Humble.Umbraco.Packages/Humble.RCL/readme.md | 11 +++ .../App_Plugins/Humble/package.manifest | 5 -- .../wwwroot/App_Plugins/Humble/test.cshtml | 4 -- .../Humble.RCL/wwwroot/test.js | 1 + .../TagHelpers/HelloWorldTagHelper.cs | 12 ++++ .../TagHelpers/ParserTagHelper.cs | 68 +++++++++++++++++++ .../TagHelpers/ParserTagHelper.md | 4 ++ .../TagHelpers/PictureTagHelper.cs | 38 +++++++++++ .../TagHelpers/PictureTagHelper.md | 4 ++ Humble.Umbraco.sln | 12 ++-- Humble.Umbraco/Humble.Umbraco.csproj | 2 + Humble.Umbraco/Parsers/RteParser.cs | 4 +- Humble.Umbraco/Properties/launchSettings.json | 6 +- Humble.Umbraco/Startup.cs | 4 +- .../components/humble_ui_richText.cshtml | 5 +- 21 files changed, 176 insertions(+), 56 deletions(-) delete mode 100644 Humble.Umbraco.Packages/Humble.RCL/Humble.RCL.csproj create mode 100644 Humble.Umbraco.Packages/Humble.RCL/readme.md delete mode 100644 Humble.Umbraco.Packages/Humble.RCL/wwwroot/App_Plugins/Humble/package.manifest delete mode 100644 Humble.Umbraco.Packages/Humble.RCL/wwwroot/App_Plugins/Humble/test.cshtml create mode 100644 Humble.Umbraco.Packages/Humble.RCL/wwwroot/test.js create mode 100644 Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/HelloWorldTagHelper.cs create mode 100644 Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/ParserTagHelper.cs create mode 100644 Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/ParserTagHelper.md create mode 100644 Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/PictureTagHelper.cs create mode 100644 Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/PictureTagHelper.md diff --git a/.testing/Umbraco_10/Properties/launchSettings.json b/.testing/Umbraco_10/Properties/launchSettings.json index 4e783dc..56e0c9a 100644 --- a/.testing/Umbraco_10/Properties/launchSettings.json +++ b/.testing/Umbraco_10/Properties/launchSettings.json @@ -18,12 +18,12 @@ }, "Umbraco.Web.UI": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:44390;http://localhost:37643", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true } } -} +} \ No newline at end of file diff --git a/.testing/Umbraco_10/Umbraco_10.csproj b/.testing/Umbraco_10/Umbraco_10.csproj index 0309398..b8b1d1f 100644 --- a/.testing/Umbraco_10/Umbraco_10.csproj +++ b/.testing/Umbraco_10/Umbraco_10.csproj @@ -29,4 +29,5 @@ false false + diff --git a/.testing/Umbraco_12/Properties/launchSettings.json b/.testing/Umbraco_12/Properties/launchSettings.json index c766e26..87c5122 100644 --- a/.testing/Umbraco_12/Properties/launchSettings.json +++ b/.testing/Umbraco_12/Properties/launchSettings.json @@ -18,12 +18,12 @@ }, "Umbraco.Web.UI": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "https://localhost:44308;http://localhost:39618", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "dotnetRunMessages": true } } -} +} \ No newline at end of file diff --git a/.testing/Umbraco_12/Umbraco_12.csproj b/.testing/Umbraco_12/Umbraco_12.csproj index 3ba8532..b8725e9 100644 --- a/.testing/Umbraco_12/Umbraco_12.csproj +++ b/.testing/Umbraco_12/Umbraco_12.csproj @@ -26,4 +26,5 @@ false + diff --git a/.testing/readme.md b/.testing/readme.md index e69de29..12fb5b1 100644 --- a/.testing/readme.md +++ b/.testing/readme.md @@ -0,0 +1,11 @@ +# Setup a Test Umbraco Instance + +1. Install a _specific version_ of `Umbraco.Templates` +2. Scaffold a new project based on these templates. + +> The example below references the current LTS version of Umbraco, version 10. + +``` +dotnet new install Umbraco.Templates::10.0.0 +dotnet new umbraco --name Umbraco_10 +``` \ No newline at end of file diff --git a/Humble.Umbraco.Packages/Humble.RCL/Humble.RCL.csproj b/Humble.Umbraco.Packages/Humble.RCL/Humble.RCL.csproj deleted file mode 100644 index 360eea8..0000000 --- a/Humble.Umbraco.Packages/Humble.RCL/Humble.RCL.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - net6.0 - enable - enable - / - - - - Humble.RCL - Humble.RCL - Humble.RCL - ... - umbraco plugin package - - - - - - - - - - Never - - - diff --git a/Humble.Umbraco.Packages/Humble.RCL/readme.md b/Humble.Umbraco.Packages/Humble.RCL/readme.md new file mode 100644 index 0000000..1fd0cd7 --- /dev/null +++ b/Humble.Umbraco.Packages/Humble.RCL/readme.md @@ -0,0 +1,11 @@ +By default, static assets are made available in the following path: + +``` +/_content/_NAMESPACE_/_PATH_/_FILE_ +``` + +By setting the following value in your `.csproj`, you can ensure that the path above matches the path in your project: + +``` +/ +``` \ No newline at end of file diff --git a/Humble.Umbraco.Packages/Humble.RCL/wwwroot/App_Plugins/Humble/package.manifest b/Humble.Umbraco.Packages/Humble.RCL/wwwroot/App_Plugins/Humble/package.manifest deleted file mode 100644 index 1c11bab..0000000 --- a/Humble.Umbraco.Packages/Humble.RCL/wwwroot/App_Plugins/Humble/package.manifest +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "Humble.RCL", - "name": "Humble.RCL", - "allowPackageTelemetry": true -} diff --git a/Humble.Umbraco.Packages/Humble.RCL/wwwroot/App_Plugins/Humble/test.cshtml b/Humble.Umbraco.Packages/Humble.RCL/wwwroot/App_Plugins/Humble/test.cshtml deleted file mode 100644 index 4d7438b..0000000 --- a/Humble.Umbraco.Packages/Humble.RCL/wwwroot/App_Plugins/Humble/test.cshtml +++ /dev/null @@ -1,4 +0,0 @@ -

I'm a test page, from an RCL Library

-

- You can overwrite me by creating a "test.cshtml" anywhere in your ~/Views folder. -

\ No newline at end of file diff --git a/Humble.Umbraco.Packages/Humble.RCL/wwwroot/test.js b/Humble.Umbraco.Packages/Humble.RCL/wwwroot/test.js new file mode 100644 index 0000000..a5946d9 --- /dev/null +++ b/Humble.Umbraco.Packages/Humble.RCL/wwwroot/test.js @@ -0,0 +1 @@ +alert("RCL is working!"); \ No newline at end of file diff --git a/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/HelloWorldTagHelper.cs b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/HelloWorldTagHelper.cs new file mode 100644 index 0000000..f2a334c --- /dev/null +++ b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/HelloWorldTagHelper.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Razor.TagHelpers; + +namespace Humble.Umbraco.UI.TagHelpers; + +public class HelloWorldTagHelper : TagHelper +{ + public override void Process(TagHelperContext context, TagHelperOutput output) + { + output.TagName = "p"; + output.Content.SetContent("Hello, World!"); + } +} \ No newline at end of file diff --git a/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/ParserTagHelper.cs b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/ParserTagHelper.cs new file mode 100644 index 0000000..c0338a3 --- /dev/null +++ b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/ParserTagHelper.cs @@ -0,0 +1,68 @@ +using System.Reflection; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.Extensions.DependencyInjection; +using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Cms.Core.Strings; +using Umbraco.Cms.Core.Web; +using Umbraco.Cms.Web.Common; +using Umbraco.Extensions; + +namespace Humble.Umbraco.UI.TagHelpers; + +[HtmlTargetElement("humble-parser", TagStructure = TagStructure.NormalOrSelfClosing)] +public class HumbleParserTagHelper : TagHelper +{ + private readonly IUmbracoContextAccessor _umbracoContextAccessor; + private readonly UmbracoHelper _umbracoHelper; + + public HumbleParserTagHelper(IUmbracoContextAccessor umbracoContextAccessor, UmbracoHelper umbracoHelper) + { + _umbracoContextAccessor = umbracoContextAccessor; + _umbracoHelper = umbracoHelper; + } + + public IHtmlEncodedString Content { get; set; } + + public override void Process(TagHelperContext context, TagHelperOutput output) + { + output.TagName = null; + var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext(); + var contentService = umbracoContext.Content; + + if (contentService == null) + { + return; + } + + IPublishedContent content = _umbracoHelper.AssignedContentItem; // Set this based on your requirements + + var replacePattern = new Regex(@"{{([a-zA-Z]+)}}", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); + var newContents = Content.ToString(); + + var matches = replacePattern.Matches(newContents); + + foreach (Match match in matches) + { + string key = match.Groups[1].Value; + var typeProperty = content.GetType().GetProperty(key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public); + + if (typeProperty != null) + { + newContents = newContents.Replace(match.Value, typeProperty.GetValue(content, null).ToString()); + continue; + } + + var contentProperty = content.GetProperty(key); + if (contentProperty == null) continue; + + var value = contentProperty.GetValue(); + if (value == null) continue; + + newContents = newContents.Replace(match.Value, value.ToString()); + } + + output.Content.SetHtmlContent(newContents); + } +} \ No newline at end of file diff --git a/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/ParserTagHelper.md b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/ParserTagHelper.md new file mode 100644 index 0000000..67bb99e --- /dev/null +++ b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/ParserTagHelper.md @@ -0,0 +1,4 @@ +``` + +``` \ No newline at end of file diff --git a/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/PictureTagHelper.cs b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/PictureTagHelper.cs new file mode 100644 index 0000000..7fb4d99 --- /dev/null +++ b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/PictureTagHelper.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Umbraco.Cms.Core.Models; +using Umbraco.Extensions; + +namespace Humble.Umbraco.UI.TagHelpers; + +[HtmlTargetElement("humble-picture", TagStructure = TagStructure.NormalOrSelfClosing)] +public class PictureTagHelper : TagHelper +{ + public List MediaWithCropsList { get; set; } + + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + var content = await output.GetChildContentAsync(); + var mediaSources = new List(); + + foreach (var mediaWithCrops in MediaWithCropsList) + { + // Determine which breakpoint to use based on the width of the image + string breakpoint = "s"; + + // Get the URL for the specific breakpoint from the LocalCrops + var cropData = mediaWithCrops.LocalCrops.GetCrop(breakpoint); + var mediaUrl = mediaWithCrops.Url(); + + // Create a element for each media source + var mediaSource = $""; + mediaSources.Add(mediaSource); + } + + // Generate the element + var pictureElement = $"{string.Join("", mediaSources)}"; + output.TagName = null; + output.Content.SetHtmlContent(pictureElement); + } +} \ No newline at end of file diff --git a/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/PictureTagHelper.md b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/PictureTagHelper.md new file mode 100644 index 0000000..2cf411f --- /dev/null +++ b/Humble.Umbraco.Packages/Humble.Umbraco.UI/TagHelpers/PictureTagHelper.md @@ -0,0 +1,4 @@ +``` + +``` \ No newline at end of file diff --git a/Humble.Umbraco.sln b/Humble.Umbraco.sln index 36f0df6..dd3cd18 100644 --- a/Humble.Umbraco.sln +++ b/Humble.Umbraco.sln @@ -45,7 +45,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Umbraco_12", ".testing\Umbr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Humble.Umbraco.NamingConventions", "Humble.Umbraco.Packages\Humble.Umbraco.NamingConventions\Humble.Umbraco.NamingConventions.csproj", "{7A12A70D-4167-406F-B89E-D496B00ACADE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Humble.RCL", "Humble.Umbraco.Packages\Humble.RCL\Humble.RCL.csproj", "{1B7D7EAA-8632-491B-9588-F430B20BDC24}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Humble.RCL", "Humble.Umbraco.Packages\Humble.RCL\Humble.RCL.csproj", "{D005DB84-F65B-4655-8813-CC1CA4C9E485}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -105,10 +105,10 @@ Global {7A12A70D-4167-406F-B89E-D496B00ACADE}.Debug|Any CPU.Build.0 = Debug|Any CPU {7A12A70D-4167-406F-B89E-D496B00ACADE}.Release|Any CPU.ActiveCfg = Release|Any CPU {7A12A70D-4167-406F-B89E-D496B00ACADE}.Release|Any CPU.Build.0 = Release|Any CPU - {1B7D7EAA-8632-491B-9588-F430B20BDC24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1B7D7EAA-8632-491B-9588-F430B20BDC24}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1B7D7EAA-8632-491B-9588-F430B20BDC24}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1B7D7EAA-8632-491B-9588-F430B20BDC24}.Release|Any CPU.Build.0 = Release|Any CPU + {D005DB84-F65B-4655-8813-CC1CA4C9E485}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D005DB84-F65B-4655-8813-CC1CA4C9E485}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D005DB84-F65B-4655-8813-CC1CA4C9E485}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D005DB84-F65B-4655-8813-CC1CA4C9E485}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -126,7 +126,7 @@ Global {A3F697D6-0EFF-4E28-BF5B-8257A4E397D0} = {B0AC1BBF-9853-40FA-8A89-90174EA13EA5} {5B36BA76-E0EF-4520-978F-55E3C13ED916} = {B0AC1BBF-9853-40FA-8A89-90174EA13EA5} {7A12A70D-4167-406F-B89E-D496B00ACADE} = {46774B56-D02A-4E25-972B-BC0B5443FC14} - {1B7D7EAA-8632-491B-9588-F430B20BDC24} = {46774B56-D02A-4E25-972B-BC0B5443FC14} + {D005DB84-F65B-4655-8813-CC1CA4C9E485} = {46774B56-D02A-4E25-972B-BC0B5443FC14} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F0A5EF84-2D31-4F02-9A33-4FC3B05F11D9} diff --git a/Humble.Umbraco/Humble.Umbraco.csproj b/Humble.Umbraco/Humble.Umbraco.csproj index 8ee35e1..7d7bee2 100644 --- a/Humble.Umbraco/Humble.Umbraco.csproj +++ b/Humble.Umbraco/Humble.Umbraco.csproj @@ -13,6 +13,7 @@ + @@ -84,4 +85,5 @@ false + \ No newline at end of file diff --git a/Humble.Umbraco/Parsers/RteParser.cs b/Humble.Umbraco/Parsers/RteParser.cs index fd9a0e4..f987baf 100644 --- a/Humble.Umbraco/Parsers/RteParser.cs +++ b/Humble.Umbraco/Parsers/RteParser.cs @@ -19,7 +19,7 @@ public static IHtmlEncodedString Parse(this IHtmlEncodedString Html, IPublishedC // Exit: string contents are null or empty if (Html == null) return Html; - // Exit: no current asigned content item + // Exit: no assigned content item if (Content == null) return Html; // Find matches @@ -57,4 +57,4 @@ public static IHtmlEncodedString Parse(this IHtmlEncodedString Html, IPublishedC return new HtmlEncodedString(newContents); } } -} +} \ No newline at end of file diff --git a/Humble.Umbraco/Properties/launchSettings.json b/Humble.Umbraco/Properties/launchSettings.json index e007fc9..b466bd0 100644 --- a/Humble.Umbraco/Properties/launchSettings.json +++ b/Humble.Umbraco/Properties/launchSettings.json @@ -17,10 +17,10 @@ }, "Umbraco.Web.UI.NetCore": { "commandName": "Project", + "applicationUrl": "https://localhost:44307;http://localhost:47012", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:44307;http://localhost:47012" + } } } -} +} \ No newline at end of file diff --git a/Humble.Umbraco/Startup.cs b/Humble.Umbraco/Startup.cs index a8bb057..14affab 100644 --- a/Humble.Umbraco/Startup.cs +++ b/Humble.Umbraco/Startup.cs @@ -53,7 +53,7 @@ public void ConfigureServices(IServiceCollection services) .AddHtmlMinification() .AddXmlMinification() .AddHttpCompression(); - + services .AddUmbraco(_env, _config) .AddBackOffice() @@ -109,4 +109,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) } } -} +} \ No newline at end of file diff --git a/Humble.Umbraco/Views/Partials/blocklist/components/humble_ui_richText.cshtml b/Humble.Umbraco/Views/Partials/blocklist/components/humble_ui_richText.cshtml index 3867283..fdb9d9a 100644 --- a/Humble.Umbraco/Views/Partials/blocklist/components/humble_ui_richText.cshtml +++ b/Humble.Umbraco/Views/Partials/blocklist/components/humble_ui_richText.cshtml @@ -9,4 +9,7 @@ var settings = Model.Settings; } -@Html.Raw(content.Copy.Parse(Umbraco.AssignedContentItem)) \ No newline at end of file +@Html.Raw(content.Copy.Parse(Umbraco.AssignedContentItem)) +@* + +*@ \ No newline at end of file