forked from Sitecore/Habitat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Tyack
committed
Mar 21, 2018
1 parent
44a5ff5
commit df6f2e5
Showing
10 changed files
with
226 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 53 additions & 24 deletions
77
src/Foundation/SitecoreExtensions/code/Extensions/RenderingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,61 @@ | ||
namespace Sitecore.Foundation.SitecoreExtensions.Extensions | ||
{ | ||
using System; | ||
using Sitecore.Mvc.Presentation; | ||
using Sitecore.Resources.Media; | ||
using Sitecore.Xml; | ||
|
||
public static class RenderingExtensions | ||
{ | ||
public static int GetIntegerParameter(this Rendering rendering, string parameterName, int defaultValue = 0) | ||
using System; | ||
using System.Web; | ||
using Sitecore.Mvc.Helpers; | ||
using Sitecore.Mvc.Presentation; | ||
using Sitecore.Resources.Media; | ||
using Sitecore.Xml; | ||
|
||
public static class RenderingExtensions | ||
{ | ||
if (rendering == null) | ||
{ | ||
throw new ArgumentNullException(nameof(rendering)); | ||
} | ||
|
||
var parameter = rendering.Parameters[parameterName]; | ||
if (string.IsNullOrEmpty(parameter)) | ||
{ | ||
return defaultValue; | ||
} | ||
|
||
int returnValue; | ||
return !int.TryParse(parameter, out returnValue) ? defaultValue : returnValue; | ||
public static int GetIntegerParameter(this Rendering rendering, string parameterName, int defaultValue = 0) | ||
{ | ||
if (rendering == null) | ||
{ | ||
throw new ArgumentNullException(nameof(rendering)); | ||
} | ||
|
||
var parameter = rendering.Parameters[parameterName]; | ||
if (string.IsNullOrEmpty(parameter)) | ||
{ | ||
return defaultValue; | ||
} | ||
|
||
int returnValue; | ||
return !int.TryParse(parameter, out returnValue) ? defaultValue : returnValue; | ||
} | ||
|
||
public static bool GetUseStaticPlaceholderNames([NotNull] this Rendering rendering) | ||
{ | ||
return MainUtil.GetBool(rendering.Parameters[Constants.DynamicPlaceholdersLayoutParameters.UseStaticPlaceholderNames], false); | ||
} | ||
|
||
public static HtmlString CachedRendering(this SitecoreHelper sitecoreHelper, string pathOrId, RenderingCachingSettings renderingCachingSettings) | ||
{ | ||
return sitecoreHelper.Rendering(pathOrId, renderingCachingSettings); | ||
} | ||
} | ||
|
||
public static bool GetUseStaticPlaceholderNames([NotNull] this Rendering rendering) | ||
|
||
public class RenderingCachingSettings | ||
{ | ||
return MainUtil.GetBool(rendering.Parameters[Constants.DynamicPlaceholdersLayoutParameters.UseStaticPlaceholderNames], false); | ||
public bool? Cacheable { get; set; } | ||
|
||
public TimeSpan? Cache_Timeout { get; set; } | ||
|
||
public bool? Cache_VaryByData { get; set; } | ||
|
||
public bool? Cache_VaryByDevice { get; set; } | ||
|
||
public bool? Cache_VaryByLogin { get; set; } | ||
|
||
public bool? Cache_VaryByParameters { get; set; } | ||
|
||
public bool? Cache_VaryByQueryString { get; set; } | ||
|
||
public bool? Cache_VaryByUser { get; set; } | ||
|
||
public string CacheKey { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/Project/Common/code/Views/Common/Assets/InlineStyles.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@model Sitecore.Mvc.Presentation.RenderingModel | ||
@using Sitecore.Foundation.Assets.Services | ||
|
||
<!-- Inline Viewport CSS | above the fold --> | ||
@RenderAssetsService.Current.RenderInlineStyles(Request) |
6 changes: 6 additions & 0 deletions
6
src/Project/Common/code/Views/Common/Assets/Scripts-3.2.1.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@using Sitecore.Foundation.Assets.Models | ||
@using Sitecore.Foundation.Assets.Services | ||
@model Sitecore.Mvc.Presentation.RenderingModel | ||
|
||
<!-- Latest compiled and minified JavaScript --> | ||
@RenderAssetsService.Current.RenderScriptAsyncBootup(ScriptLocation.Body, "/scripts/jquery-3.2.1.min.js?v=2") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@model Sitecore.Mvc.Presentation.RenderingModel | ||
@using Sitecore.Foundation.Assets.Services | ||
|
||
@RenderAssetsService.Current.RenderStyles(false) |
28 changes: 28 additions & 0 deletions
28
src/Project/Common/code/Views/Common/Assets/StylesDeferred.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@using Sitecore.Foundation.Assets.Services | ||
@model Sitecore.Mvc.Presentation.RenderingModel | ||
|
||
@if (RenderAssetsService.Current.HasInlineStyles(Request)) | ||
{ | ||
<noscript id="deferred-styles"> | ||
@*Styles*@ | ||
@RenderAssetsService.Current.RenderStyles(true) | ||
</noscript> | ||
<script> | ||
var loadDeferredStyles = function() { | ||
var addStylesNode = document.getElementById("deferred-styles"); | ||
var replacement = document.createElement("div"); | ||
replacement.innerHTML = addStylesNode.textContent; | ||
document.body.appendChild(replacement); | ||
addStylesNode.parentElement.removeChild(addStylesNode); | ||
}; | ||
var raf = requestAnimationFrame || mozRequestAnimationFrame || | ||
webkitRequestAnimationFrame || msRequestAnimationFrame; | ||
if (raf) raf(function() { window.setTimeout(loadDeferredStyles, 0); }); | ||
else window.addEventListener('load', loadDeferredStyles); | ||
</script> | ||
} | ||
else | ||
{ | ||
@RenderAssetsService.Current.RenderStyles(false) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 54 additions & 46 deletions
100
src/Project/Habitat/code/Views/Website/Layouts/Default.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,55 @@ | ||
@using Sitecore.Foundation.Assets | ||
@using Sitecore.Foundation.Assets.Models | ||
@using Sitecore.Foundation.Assets.Services | ||
@using Sitecore.Foundation.SitecoreExtensions.Extensions | ||
@using Sitecore.Mvc.Analytics.Extensions | ||
@inherits WebViewPage | ||
@{ | ||
Layout = null; | ||
} | ||
<!DOCTYPE html> | ||
<!--[if IE 9]><html lang="en" class="ie9 no-js"><![endif]--> | ||
<!--[if !IE]><!--> | ||
<html lang="@Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName"> | ||
<!--<![endif]--> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | ||
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> | ||
@if (!Sitecore.Context.PageMode.IsExperienceEditor) | ||
{ | ||
@Html.Sitecore().Placeholder("head") | ||
} | ||
<!-- Latest compiled and minified JavaScript --> | ||
@RenderAssetsService.Current.RenderScript(ScriptLocation.Head) | ||
@RenderAssetsService.Current.RenderStyles() | ||
@Html.Sitecore().VisitorIdentification() | ||
</head> | ||
<body class="header-static @(Sitecore.Context.PageMode.IsNormal ? "" : (Sitecore.Context.PageMode.IsExperienceEditor ? "pagemode-edit" : "pagemode-preview"))"> | ||
<div id="main-container"> | ||
<header class="header-static"> | ||
@Html.Sitecore().Placeholder("header-top") | ||
|
||
@Html.Sitecore().Placeholder("navbar") | ||
</header> | ||
<main role="main"> | ||
@Html.Sitecore().Placeholder("page-layout") | ||
</main> | ||
<footer class="bg-dark"> | ||
@Html.Sitecore().Placeholder("footer") | ||
</footer> | ||
|
||
@Html.Sitecore().Placeholder("page-sidebar") | ||
</div> | ||
@RenderAssetsService.Current.RenderScript(ScriptLocation.Body) | ||
</body> | ||
@using Sitecore.Foundation.Assets | ||
@using Sitecore.Foundation.Assets.Models | ||
@using Sitecore.Foundation.Assets.Services | ||
@using Sitecore.Foundation.SitecoreExtensions.Extensions | ||
@using Sitecore.Mvc.Analytics.Extensions | ||
@inherits WebViewPage | ||
@{ | ||
Layout = null; | ||
string cacheKey = RenderAssetsService.GetPageKey(Request); | ||
} | ||
<!DOCTYPE html> | ||
<!--[if IE 9]><html lang="en" class="ie9 no-js"><![endif]--> | ||
<!--[if !IE]><!--> | ||
<html lang="@Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName"> | ||
<!--<![endif]--> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> | ||
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> | ||
@if (!Sitecore.Context.PageMode.IsExperienceEditor) | ||
{ | ||
@Html.Sitecore().Placeholder("head") | ||
} | ||
|
||
@*Inline Styles Rendering*@ | ||
@Html.Sitecore().CachedRendering("{B14DA82E-F844-4945-8F31-4577A52861E1}", new RenderingCachingSettings { Cacheable = true, CacheKey = cacheKey + "_critical_styles" }) | ||
|
||
@Html.Sitecore().VisitorIdentification() | ||
</head> | ||
<body class="header-static @(Sitecore.Context.PageMode.IsNormal ? "" : (Sitecore.Context.PageMode.IsExperienceEditor ? "pagemode-edit" : "pagemode-preview"))"> | ||
<div id="main-container"> | ||
<header class="header-static"> | ||
@Html.Sitecore().Placeholder("header-top") | ||
|
||
@Html.Sitecore().Placeholder("navbar") | ||
</header> | ||
<main role="main"> | ||
@Html.Sitecore().Placeholder("page-layout") | ||
</main> | ||
<footer class="bg-dark"> | ||
@Html.Sitecore().Placeholder("footer") | ||
</footer> | ||
|
||
@Html.Sitecore().Placeholder("page-sidebar") | ||
</div> | ||
|
||
@*Styles Rendering Deferred Styles *@ | ||
@Html.Sitecore().CachedRendering("{F04C562A-CBF9-40CF-8CA9-8CE83FDF0BFA}", new RenderingCachingSettings { Cacheable = true, CacheKey = cacheKey + "_bottom_styles" }) | ||
|
||
@*Scripts Legacy Jquery jquery-3.2.1 *@ | ||
@Html.Sitecore().CachedRendering("{B0DD36CE-EE4A-4D01-9986-7BEF114196DD}", new RenderingCachingSettings { Cacheable = true, CacheKey = cacheKey + "_bottom_scripts" }) | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters