Skip to content

Commit cccf09d

Browse files
author
Warren Buckley
authored
Merge pull request #22 from umbraco-community/feature/plaground-site
Add in a testing/playground site
2 parents d9edf33 + 42270e0 commit cccf09d

18 files changed

+1125
-0
lines changed

Our.Umbraco.TagHelpers.Playground/.gitignore

Lines changed: 487 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<DefaultItemExcludes>$(DefaultItemExcludes);App_Plugins/**;</DefaultItemExcludes>
6+
<DefaultItemExcludes>$(DefaultItemExcludes);umbraco/**;</DefaultItemExcludes>
7+
<DefaultItemExcludes>$(DefaultItemExcludes);wwwroot/media/**;</DefaultItemExcludes>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Umbraco.Cms" Version="9.0.1" />
12+
</ItemGroup>
13+
14+
15+
16+
<ItemGroup>
17+
<Content Include="App_Plugins/**" CopyToOutputDirectory="Always" />
18+
<Content Include="umbraco/**" CopyToOutputDirectory="Always" />
19+
<Content Remove="umbraco/Data/**" />
20+
<Content Remove="umbraco/Logs/**" />
21+
<Content Remove="umbraco/mediacache/**" />
22+
<Content Remove="umbraco/models/**" />
23+
<Compile Include="umbraco/models/**" Exclude="**/*.flag" />
24+
</ItemGroup>
25+
26+
27+
28+
<ItemGroup>
29+
<ProjectReference Include="..\Our.Umbraco.TagHelpers\Our.Umbraco.TagHelpers.csproj" />
30+
</ItemGroup>
31+
32+
<!-- Set this to true if ModelsBuilder mode is not InMemoryAuto-->
33+
<PropertyGroup>
34+
<RazorCompileOnBuild>false</RazorCompileOnBuild>
35+
<RazorCompileOnPublish>false</RazorCompileOnPublish>
36+
</PropertyGroup>
37+
38+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.Hosting;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace Our.Umbraco.TagHelpers.Playground
7+
{
8+
public class Program
9+
{
10+
public static void Main(string[] args)
11+
=> CreateHostBuilder(args)
12+
.Build()
13+
.Run();
14+
15+
public static IHostBuilder CreateHostBuilder(string[] args) =>
16+
Host.CreateDefaultBuilder(args)
17+
.ConfigureLogging(x => x.ClearProviders())
18+
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
19+
}
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:17329",
8+
"sslPort": 44330
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"Our.Umbraco.TagHelpers.Playground [Dev]": {
20+
"commandName": "Project",
21+
"dotnetRunMessages": true,
22+
"launchBrowser": true,
23+
"applicationUrl": "https://localhost:44330;http://localhost:17329",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
}
27+
},
28+
"Our.Umbraco.TagHelpers.Playground [Prod]": {
29+
"commandName": "Project",
30+
"dotnetRunMessages": true,
31+
"launchBrowser": true,
32+
"applicationUrl": "https://localhost:44330;http://localhost:17329",
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Production"
35+
}
36+
}
37+
}
38+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.Extensions.Configuration;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Hosting;
7+
using Umbraco.Cms.Core.DependencyInjection;
8+
using Umbraco.Extensions;
9+
10+
namespace Our.Umbraco.TagHelpers.Playground
11+
{
12+
public class Startup
13+
{
14+
private readonly IWebHostEnvironment _env;
15+
private readonly IConfiguration _config;
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="Startup" /> class.
19+
/// </summary>
20+
/// <param name="webHostEnvironment">The web hosting environment.</param>
21+
/// <param name="config">The configuration.</param>
22+
/// <remarks>
23+
/// Only a few services are possible to be injected here https://github.com/dotnet/aspnetcore/issues/9337
24+
/// </remarks>
25+
public Startup(IWebHostEnvironment webHostEnvironment, IConfiguration config)
26+
{
27+
_env = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
28+
_config = config ?? throw new ArgumentNullException(nameof(config));
29+
}
30+
31+
/// <summary>
32+
/// Configures the services.
33+
/// </summary>
34+
/// <param name="services">The services.</param>
35+
/// <remarks>
36+
/// This method gets called by the runtime. Use this method to add services to the container.
37+
/// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
38+
/// </remarks>
39+
public void ConfigureServices(IServiceCollection services)
40+
{
41+
#pragma warning disable IDE0022 // Use expression body for methods
42+
services.AddUmbraco(_env, _config)
43+
.AddBackOffice()
44+
.AddWebsite()
45+
.AddComposers()
46+
.Build();
47+
#pragma warning restore IDE0022 // Use expression body for methods
48+
49+
}
50+
51+
/// <summary>
52+
/// Configures the application.
53+
/// </summary>
54+
/// <param name="app">The application builder.</param>
55+
/// <param name="env">The web hosting environment.</param>
56+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
57+
{
58+
if (env.IsDevelopment())
59+
{
60+
app.UseDeveloperExceptionPage();
61+
}
62+
63+
app.UseUmbraco()
64+
.WithMiddleware(u =>
65+
{
66+
u.UseBackOffice();
67+
u.UseWebsite();
68+
})
69+
.WithEndpoints(u =>
70+
{
71+
u.UseInstallerEndpoints();
72+
u.UseBackOfficeEndpoints();
73+
u.UseWebsiteEndpoints();
74+
});
75+
}
76+
}
77+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListModel>
2+
@{
3+
if (!Model.Any()) { return; }
4+
}
5+
<div class="umb-block-list">
6+
@foreach (var block in Model)
7+
{
8+
if (block?.ContentUdi == null) { continue; }
9+
var data = block.Content;
10+
11+
@await Html.PartialAsync("BlockList/Components/" + data.ContentType.Alias, block)
12+
}
13+
</div>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
@using System.Web
2+
@using Microsoft.AspNetCore.Html
3+
@using Newtonsoft.Json.Linq
4+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<dynamic>
5+
6+
@*
7+
Razor helpers located at the bottom of this file
8+
*@
9+
10+
@if (Model != null && Model.GetType() == typeof(JObject) && Model.sections != null)
11+
{
12+
var oneColumn = ((System.Collections.ICollection)Model.sections).Count == 1;
13+
14+
<div class="umb-grid">
15+
@if (oneColumn)
16+
{
17+
foreach (var section in Model.sections)
18+
{
19+
<div class="grid-section">
20+
@foreach (var row in section.rows)
21+
{
22+
renderRow(row);
23+
}
24+
</div>
25+
}
26+
}
27+
else
28+
{
29+
<div class="row clearfix">
30+
@foreach (var sec in Model.sections)
31+
{
32+
<div class="grid-section">
33+
<div class="[email protected] column">
34+
@foreach (var row in sec.rows)
35+
{
36+
renderRow(row);
37+
}
38+
</div>
39+
</div>
40+
}
41+
</div>
42+
}
43+
</div>
44+
}
45+
46+
@functions{
47+
48+
private async Task renderRow(dynamic row)
49+
{
50+
<div @RenderElementAttributes(row)>
51+
<div class="row clearfix">
52+
@foreach (var area in row.areas)
53+
{
54+
<div class="[email protected] column">
55+
<div @RenderElementAttributes(area)>
56+
@foreach (var control in area.controls)
57+
{
58+
if (control != null && control.editor != null && control.editor.view != null)
59+
{
60+
<text>@await Html.PartialAsync("grid/editors/base", (object)control)</text>
61+
}
62+
}
63+
</div>
64+
</div>
65+
}
66+
</div>
67+
</div>
68+
}
69+
}
70+
71+
@functions{
72+
73+
public static HtmlString RenderElementAttributes(dynamic contentItem)
74+
{
75+
var attrs = new List<string>();
76+
JObject cfg = contentItem.config;
77+
78+
if (cfg != null)
79+
{
80+
foreach (JProperty property in cfg.Properties())
81+
{
82+
var propertyValue = HttpUtility.HtmlAttributeEncode(property.Value.ToString());
83+
attrs.Add(property.Name + "=\"" + propertyValue + "\"");
84+
}
85+
}
86+
87+
JObject style = contentItem.styles;
88+
89+
if (style != null) {
90+
var cssVals = new List<string>();
91+
foreach (JProperty property in style.Properties())
92+
{
93+
var propertyValue = property.Value.ToString();
94+
if (string.IsNullOrWhiteSpace(propertyValue) == false)
95+
{
96+
cssVals.Add(property.Name + ":" + propertyValue + ";");
97+
}
98+
}
99+
100+
if (cssVals.Any())
101+
attrs.Add("style='" + HttpUtility.HtmlAttributeEncode(string.Join(" ", cssVals)) + "'");
102+
}
103+
104+
return new HtmlString(string.Join(" ", attrs));
105+
}
106+
}

0 commit comments

Comments
 (0)