Skip to content

Commit 2d6f5e6

Browse files
author
Warren Buckley
committed
New example site based on Umbraco 10.1.0
1 parent 2b3d685 commit 2d6f5e6

19 files changed

+1084
-0
lines changed

Our.Umbraco.TagHelpers.ExampleSite/.gitignore

Lines changed: 478 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<ImplicitUsings>enable</ImplicitUsings>
5+
<Nullable>enable</Nullable>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Umbraco.Cms" Version="10.1.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<!-- Opt-in to app-local ICU to ensure consistent globalization APIs across different platforms -->
14+
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9" />
15+
<ProjectReference Include="..\Our.Umbraco.TagHelpers\Our.Umbraco.TagHelpers.csproj" />
16+
<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2.0.9" Condition="$(RuntimeIdentifier.StartsWith('linux')) or $(RuntimeIdentifier.StartsWith('win')) or ('$(RuntimeIdentifier)' == '' and !$([MSBuild]::IsOSPlatform('osx')))" />
17+
</ItemGroup>
18+
19+
<PropertyGroup>
20+
<!-- Razor files are needed for the backoffice to work correctly -->
21+
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
22+
</PropertyGroup>
23+
24+
<PropertyGroup>
25+
<!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto -->
26+
<RazorCompileOnBuild>false</RazorCompileOnBuild>
27+
<RazorCompileOnPublish>false</RazorCompileOnPublish>
28+
</PropertyGroup>
29+
30+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace Our.Umbraco.TagHelpers.ExampleSite
2+
{
3+
public class Program
4+
{
5+
public static void Main(string[] args)
6+
=> CreateHostBuilder(args)
7+
.Build()
8+
.Run();
9+
10+
public static IHostBuilder CreateHostBuilder(string[] args) =>
11+
Host.CreateDefaultBuilder(args)
12+
.ConfigureUmbracoDefaults()
13+
.ConfigureWebHostDefaults(webBuilder =>
14+
{
15+
webBuilder.UseStaticWebAssets();
16+
webBuilder.UseStartup<Startup>();
17+
});
18+
}
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:46843",
8+
"sslPort": 44370
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"Umbraco.Web.UI": {
20+
"commandName": "Project",
21+
"dotnetRunMessages": true,
22+
"launchBrowser": true,
23+
"applicationUrl": "https://localhost:44370;http://localhost:46843",
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
}
27+
}
28+
}
29+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace Our.Umbraco.TagHelpers.ExampleSite
2+
{
3+
public class Startup
4+
{
5+
private readonly IWebHostEnvironment _env;
6+
private readonly IConfiguration _config;
7+
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="Startup" /> class.
10+
/// </summary>
11+
/// <param name="webHostEnvironment">The web hosting environment.</param>
12+
/// <param name="config">The configuration.</param>
13+
/// <remarks>
14+
/// Only a few services are possible to be injected here https://github.com/dotnet/aspnetcore/issues/9337.
15+
/// </remarks>
16+
public Startup(IWebHostEnvironment webHostEnvironment, IConfiguration config)
17+
{
18+
_env = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
19+
_config = config ?? throw new ArgumentNullException(nameof(config));
20+
}
21+
22+
/// <summary>
23+
/// Configures the services.
24+
/// </summary>
25+
/// <param name="services">The services.</param>
26+
/// <remarks>
27+
/// This method gets called by the runtime. Use this method to add services to the container.
28+
/// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940.
29+
/// </remarks>
30+
public void ConfigureServices(IServiceCollection services)
31+
{
32+
services.AddUmbraco(_env, _config)
33+
.AddBackOffice()
34+
.AddWebsite()
35+
.AddComposers()
36+
.Build();
37+
}
38+
39+
/// <summary>
40+
/// Configures the application.
41+
/// </summary>
42+
/// <param name="app">The application builder.</param>
43+
/// <param name="env">The web hosting environment.</param>
44+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
45+
{
46+
if (env.IsDevelopment())
47+
{
48+
app.UseDeveloperExceptionPage();
49+
}
50+
51+
app.UseUmbraco()
52+
.WithMiddleware(u =>
53+
{
54+
u.UseBackOffice();
55+
u.UseWebsite();
56+
})
57+
.WithEndpoints(u =>
58+
{
59+
u.UseInstallerEndpoints();
60+
u.UseBackOfficeEndpoints();
61+
u.UseWebsiteEndpoints();
62+
});
63+
}
64+
}
65+
}
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() != true) { 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 is JObject && Model?.sections is not 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?.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+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
@if (Model is JObject && Model?.sections is not null)
7+
{
8+
var oneColumn = ((System.Collections.ICollection)Model.sections).Count == 1;
9+
10+
<div class="umb-grid">
11+
@if (oneColumn)
12+
{
13+
foreach (var section in Model.sections)
14+
{
15+
<div class="grid-section">
16+
@foreach (var row in section.rows)
17+
{
18+
renderRow(row, true);
19+
}
20+
</div>
21+
}
22+
}
23+
else
24+
{
25+
<div class="container">
26+
<div class="row clearfix">
27+
@foreach (var sec in Model.sections)
28+
{
29+
<div class="grid-section">
30+
<div class="[email protected] column">
31+
@foreach (var row in sec.rows)
32+
{
33+
renderRow(row, false);
34+
}
35+
</div>
36+
</div>
37+
}
38+
</div>
39+
</div>
40+
}
41+
</div>
42+
}
43+
44+
@functions{
45+
46+
private async Task renderRow(dynamic row, bool singleColumn)
47+
{
48+
<div @RenderElementAttributes(row)>
49+
@if (singleColumn) {
50+
@:<div class="container">
51+
}
52+
<div class="row clearfix">
53+
@foreach (var area in row.areas)
54+
{
55+
<div class="[email protected] column">
56+
<div @RenderElementAttributes(area)>
57+
@foreach (var control in area.controls)
58+
{
59+
if (control?.editor?.view != null)
60+
{
61+
<text>@await Html.PartialAsync("grid/editors/base", (object)control)</text>
62+
}
63+
}
64+
</div>
65+
</div>
66+
}
67+
</div>
68+
@if (singleColumn) {
69+
@:</div>
70+
}
71+
</div>
72+
}
73+
74+
}
75+
76+
@functions{
77+
78+
public static HtmlString RenderElementAttributes(dynamic contentItem)
79+
{
80+
var attrs = new List<string>();
81+
JObject cfg = contentItem.config;
82+
83+
if (cfg != null)
84+
{
85+
foreach (JProperty property in cfg.Properties())
86+
{
87+
var propertyValue = HttpUtility.HtmlAttributeEncode(property.Value.ToString());
88+
attrs.Add(property.Name + "=\"" + propertyValue + "\"");
89+
}
90+
}
91+
92+
JObject style = contentItem.styles;
93+
94+
if (style != null)
95+
{
96+
var cssVals = new List<string>();
97+
foreach (JProperty property in style.Properties())
98+
{
99+
var propertyValue = property.Value.ToString();
100+
if (string.IsNullOrWhiteSpace(propertyValue) == false)
101+
{
102+
cssVals.Add(property.Name + ":" + propertyValue + ";");
103+
}
104+
}
105+
106+
if (cssVals.Any())
107+
attrs.Add("style=\"" + HttpUtility.HtmlAttributeEncode(string.Join(" ", cssVals)) + "\"");
108+
}
109+
110+
return new HtmlString(string.Join(" ", attrs));
111+
}
112+
}

0 commit comments

Comments
 (0)