This repository has been archived by the owner on Dec 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from Sitecore/feature/ThemedAssets
Introducing Themes
- Loading branch information
Showing
36 changed files
with
781 additions
and
358 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
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
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
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
47 changes: 25 additions & 22 deletions
47
...undation/Assets/code/App_Config/Include/Foundation/Foundation.Assets.Serialization.config
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,24 +1,27 @@ | ||
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | ||
<sitecore> | ||
<unicorn> | ||
<configurations> | ||
<configuration name="Foundation.Assets" description="Foundation Assets" dependencies="Foundation.Serialization" patch:after="configuration[@name='Foundation.Serialization']"> | ||
<targetDataStore physicalRootPath="$(sourceFolder)\foundation\assets\serialization" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" /> | ||
<predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true"> | ||
<include name="Foundation.Assets.Templates" database="master" path="/sitecore/templates/Foundation/Assets" /> | ||
<include name="Foundation.Assets.SystemViewRendering" database="master" path="/sitecore/templates/System/Layout/Renderings/View rendering"> | ||
<exclude path="/sitecore/templates/System/Layout/Renderings/View rendering/" /> | ||
</include> | ||
<include name="Foundation.Assets.SystemControllerRendering" database="master" path="/sitecore/templates/System/Layout/Renderings/Controller rendering"> | ||
<exclude path="/sitecore/templates/System/Layout/Renderings/Controller rendering/" /> | ||
</include> | ||
</predicate> | ||
<roleDataStore type="Unicorn.Roles.Data.FilesystemRoleDataStore, Unicorn.Roles" physicalRootPath="$(sourceFolder)\foundation\assets\serialization\Foundation.Assets.Roles" singleInstance="true"/> | ||
<rolePredicate type="Unicorn.Roles.RolePredicates.ConfigurationRolePredicate, Unicorn.Roles" singleInstance="true"> | ||
<include domain="modules" pattern="^Foundation Assets .*$" /> | ||
</rolePredicate> | ||
</configuration> | ||
</configurations> | ||
</unicorn> | ||
</sitecore> | ||
<sitecore> | ||
<unicorn> | ||
<configurations> | ||
<configuration name="Foundation.Assets" description="Foundation Assets" dependencies="Foundation.Serialization" patch:after="configuration[@name='Foundation.Serialization']"> | ||
<targetDataStore physicalRootPath="$(sourceFolder)\foundation\assets\serialization" type="Rainbow.Storage.SerializationFileSystemDataStore, Rainbow" useDataCache="false" singleInstance="true" /> | ||
<predicate type="Unicorn.Predicates.SerializationPresetPredicate, Unicorn" singleInstance="true"> | ||
<include name="Foundation.Assets.Templates" database="master" path="/sitecore/templates/Foundation/Assets" /> | ||
<include name="Foundation.Assets.SystemViewRendering" database="master" path="/sitecore/templates/System/Layout/Renderings/View rendering"> | ||
<exclude children="true" /> | ||
</include> | ||
<include name="Foundation.Assets.SystemControllerRendering" database="master" path="/sitecore/templates/System/Layout/Renderings/Controller rendering"> | ||
<exclude children="true" /> | ||
</include> | ||
<include name="Foundation.Assets.Themes" database="master" path="/sitecore/system/Settings/Project/Themes"> | ||
<exclude children="true" /> | ||
</include> | ||
</predicate> | ||
<roleDataStore type="Unicorn.Roles.Data.FilesystemRoleDataStore, Unicorn.Roles" physicalRootPath="$(sourceFolder)\foundation\assets\serialization\Foundation.Assets.Roles" singleInstance="true" /> | ||
<rolePredicate type="Unicorn.Roles.RolePredicates.ConfigurationRolePredicate, Unicorn.Roles" singleInstance="true"> | ||
<include domain="modules" pattern="^Foundation Assets .*$" /> | ||
</rolePredicate> | ||
</configuration> | ||
</configurations> | ||
</unicorn> | ||
</sitecore> | ||
</configuration> |
25 changes: 13 additions & 12 deletions
25
src/Foundation/Assets/code/App_Config/Include/Foundation/Foundation.Assets.config
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,14 +1,15 @@ | ||
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> | ||
<sitecore> | ||
<pipelines> | ||
<mvc.getPageRendering> | ||
<processor | ||
patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetPageRendering.GetLayoutRendering, Sitecore.Mvc']" | ||
type="Sitecore.Foundation.Assets.Pipelines.GetPageRendering.AddAssets, Sitecore.Foundation.Assets"> | ||
<siteAssets hint="raw:AddAsset"> | ||
</siteAssets> | ||
</processor> | ||
</mvc.getPageRendering> | ||
</pipelines> | ||
</sitecore> | ||
<sitecore> | ||
<pipelines> | ||
<mvc.getPageRendering> | ||
<processor patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetPageRendering.GetLayoutRendering, Sitecore.Mvc']" type="Sitecore.Foundation.Assets.Pipelines.GetPageRendering.ClearAssets, Sitecore.Foundation.Assets"/> | ||
<processor patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetPageRendering.GetLayoutRendering, Sitecore.Mvc']" type="Sitecore.Foundation.Assets.Pipelines.GetPageRendering.AddAssets, Sitecore.Foundation.Assets"> | ||
<siteAssets hint="raw:AddAsset" /> | ||
</processor> | ||
<processor patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetPageRendering.GetLayoutRendering, Sitecore.Mvc']" type="Sitecore.Foundation.Assets.Pipelines.GetPageRendering.AddThemeAssets, Sitecore.Foundation.Assets"/> | ||
<processor patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetPageRendering.GetLayoutRendering, Sitecore.Mvc']" type="Sitecore.Foundation.Assets.Pipelines.GetPageRendering.AddPageAssets, Sitecore.Foundation.Assets"/> | ||
<processor patch:before="*[@type='Sitecore.Mvc.Pipelines.Response.GetPageRendering.GetLayoutRendering, Sitecore.Mvc']" type="Sitecore.Foundation.Assets.Pipelines.GetPageRendering.AddRenderingAssets, Sitecore.Foundation.Assets"/> | ||
</mvc.getPageRendering> | ||
</pipelines> | ||
</sitecore> | ||
</configuration> |
166 changes: 23 additions & 143 deletions
166
src/Foundation/Assets/code/Pipelines/GetPageRendering/AddAssets.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,157 +1,37 @@ | ||
namespace Sitecore.Foundation.Assets.Pipelines.GetPageRendering | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Xml; | ||
using Sitecore.Data; | ||
using Sitecore.Data.Items; | ||
using Sitecore.Diagnostics; | ||
using Sitecore.Foundation.Assets.Models; | ||
using Sitecore.Foundation.Assets.Repositories; | ||
using Sitecore.Foundation.SitecoreExtensions.Extensions; | ||
using Sitecore.Mvc.Pipelines.Response.GetPageRendering; | ||
using Sitecore.Mvc.Presentation; | ||
using System.Collections.Generic; | ||
using System.Xml; | ||
using Sitecore.Foundation.Assets.Models; | ||
using Sitecore.Foundation.Assets.Repositories; | ||
using Sitecore.Mvc.Pipelines.Response.GetPageRendering; | ||
|
||
/// <summary> | ||
/// Mvc.BuildPageDefinition pipeline processor to dynamically reference Cassette Bundles | ||
/// </summary> | ||
public class AddAssets : GetPageRenderingProcessor | ||
{ | ||
private IList<Asset> _siteAssets; | ||
|
||
private IList<Asset> SiteAssets => this._siteAssets ?? (this._siteAssets = new List<Asset>()); | ||
|
||
public void AddAsset(XmlNode node) | ||
{ | ||
var asset = AssetRepository.Current.CreateFromConfiguration(node); | ||
if (asset != null) | ||
{ | ||
this.SiteAssets.Add(asset); | ||
} | ||
} | ||
|
||
public override void Process(GetPageRenderingArgs args) | ||
public class AddAssets : GetPageRenderingProcessor | ||
{ | ||
this.AddSiteAssetsFromConfiguration(); | ||
private IList<Asset> _siteAssets; | ||
|
||
this.AddPageAssets(PageContext.Current.Item); | ||
private IList<Asset> SiteAssets => this._siteAssets ?? (this._siteAssets = new List<Asset>()); | ||
|
||
this.AddRenderingAssets(args.PageContext.PageDefinition.Renderings); | ||
} | ||
|
||
private void AddRenderingAssets(IEnumerable<Rendering> renderings) | ||
{ | ||
foreach (var rendering in renderings) | ||
{ | ||
var renderingItem = this.GetRenderingItem(rendering); | ||
if (renderingItem == null) | ||
public void AddAsset(XmlNode node) | ||
{ | ||
return; | ||
var asset = AssetRepository.Current.CreateFromConfiguration(node); | ||
if (asset != null) | ||
{ | ||
this.SiteAssets.Add(asset); | ||
} | ||
} | ||
|
||
AddScriptAssetsFromRendering(renderingItem); | ||
AddInlineScriptFromRendering(renderingItem); | ||
AddStylingAssetsFromRendering(renderingItem); | ||
AddInlineStylingFromAssets(renderingItem); | ||
} | ||
} | ||
|
||
private static void AddInlineStylingFromAssets(Item renderingItem) | ||
{ | ||
var cssInline = renderingItem[Templates.RenderingAssets.Fields.InlineStyling]; | ||
if (!string.IsNullOrEmpty(cssInline)) | ||
{ | ||
AssetRepository.Current.AddStyling(cssInline, renderingItem.ID.ToString(), true); | ||
} | ||
} | ||
|
||
private static void AddStylingAssetsFromRendering(Item renderingItem) | ||
{ | ||
var cssAssets = renderingItem[Templates.RenderingAssets.Fields.StylingFiles]; | ||
foreach (var cssAsset in cssAssets.Split(';', ',', '\n')) | ||
{ | ||
AssetRepository.Current.AddStyling(cssAsset, true); | ||
} | ||
} | ||
|
||
private static void AddInlineScriptFromRendering(Item renderingItem) | ||
{ | ||
var javaScriptInline = renderingItem[Templates.RenderingAssets.Fields.InlineScript]; | ||
if (!string.IsNullOrEmpty(javaScriptInline)) | ||
{ | ||
AssetRepository.Current.AddScript(javaScriptInline, renderingItem.ID.ToString(), ScriptLocation.Body, true); | ||
} | ||
} | ||
|
||
private static void AddScriptAssetsFromRendering(Item renderingItem) | ||
{ | ||
var javaScriptAssets = renderingItem[Templates.RenderingAssets.Fields.ScriptFiles]; | ||
foreach (var javaScriptAsset in javaScriptAssets.Split(';', ',', '\n')) | ||
{ | ||
AssetRepository.Current.AddScript(javaScriptAsset, true); | ||
} | ||
} | ||
|
||
private Item GetRenderingItem(Rendering rendering) | ||
{ | ||
if (rendering.RenderingItem == null) | ||
{ | ||
Log.Warn($"rendering.RenderingItem is null for {rendering.RenderingItemPath}", this); | ||
return null; | ||
} | ||
|
||
if (Context.PageMode.IsNormal && rendering.Caching.Cacheable) | ||
{ | ||
AssetRepository.Current.Add(rendering.RenderingItem.ID); | ||
} | ||
return rendering.RenderingItem.InnerItem; | ||
} | ||
|
||
private void AddPageAssets(Item item) | ||
{ | ||
var styling = this.GetPageAssetValue(item, Templates.PageAssets.Fields.CssCode); | ||
if (!string.IsNullOrWhiteSpace(styling)) | ||
{ | ||
AssetRepository.Current.AddStyling(styling, styling.GetHashCode().ToString(), true); | ||
} | ||
var scriptBottom = this.GetPageAssetValue(item, Templates.PageAssets.Fields.JavascriptCodeBottom); | ||
if (!string.IsNullOrWhiteSpace(scriptBottom)) | ||
{ | ||
AssetRepository.Current.AddScript(scriptBottom, scriptBottom.GetHashCode().ToString(), ScriptLocation.Body, true); | ||
} | ||
var scriptHead = this.GetPageAssetValue(item, Templates.PageAssets.Fields.JavascriptCodeTop); | ||
if (!string.IsNullOrWhiteSpace(scriptHead)) | ||
{ | ||
AssetRepository.Current.AddScript(scriptHead, scriptHead.GetHashCode().ToString(), ScriptLocation.Head, true); | ||
} | ||
} | ||
|
||
private string GetPageAssetValue(Item item, ID assetField) | ||
{ | ||
if (item.IsDerived(Templates.PageAssets.ID)) | ||
{ | ||
var assetValue = item[assetField]; | ||
if (!string.IsNullOrWhiteSpace(assetValue)) | ||
public override void Process(GetPageRenderingArgs args) | ||
{ | ||
return assetValue; | ||
this.AddSiteAssetsFromConfiguration(); | ||
} | ||
} | ||
|
||
return GetInheritedPageAssetValue(item, assetField); | ||
} | ||
|
||
private static string GetInheritedPageAssetValue(Item item, ID assetField) | ||
{ | ||
var inheritedAssetItem = item.Axes.GetAncestors().FirstOrDefault(i => i.IsDerived(Templates.PageAssets.ID) && MainUtil.GetBool(item[Templates.PageAssets.Fields.InheritAssets], false) && string.IsNullOrWhiteSpace(item[assetField])); | ||
return inheritedAssetItem?[assetField]; | ||
} | ||
|
||
private void AddSiteAssetsFromConfiguration() | ||
{ | ||
foreach (var asset in this.SiteAssets) | ||
{ | ||
AssetRepository.Current.Add(asset, true); | ||
} | ||
private void AddSiteAssetsFromConfiguration() | ||
{ | ||
foreach (var asset in this.SiteAssets) | ||
{ | ||
AssetRepository.Current.Add(asset, true); | ||
} | ||
} | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Foundation/Assets/code/Pipelines/GetPageRendering/AddPageAssets.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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace Sitecore.Foundation.Assets.Pipelines.GetPageRendering | ||
{ | ||
using System.Linq; | ||
using Sitecore.Data; | ||
using Sitecore.Data.Items; | ||
using Sitecore.Foundation.Assets.Models; | ||
using Sitecore.Foundation.Assets.Repositories; | ||
using Sitecore.Foundation.SitecoreExtensions.Extensions; | ||
using Sitecore.Mvc.Pipelines.Response.GetPageRendering; | ||
using Sitecore.Mvc.Presentation; | ||
|
||
public class AddPageAssets : GetPageRenderingProcessor | ||
{ | ||
public override void Process(GetPageRenderingArgs args) | ||
{ | ||
this.AddAssets(PageContext.Current.Item); | ||
} | ||
|
||
protected void AddAssets(Item item) | ||
{ | ||
var styling = this.GetPageAssetValue(item, Templates.PageAssets.Fields.CssCode); | ||
if (!string.IsNullOrWhiteSpace(styling)) | ||
{ | ||
AssetRepository.Current.AddStyling(styling, styling.GetHashCode().ToString(), true); | ||
} | ||
var scriptBottom = this.GetPageAssetValue(item, Templates.PageAssets.Fields.JavascriptCodeBottom); | ||
if (!string.IsNullOrWhiteSpace(scriptBottom)) | ||
{ | ||
AssetRepository.Current.AddScript(scriptBottom, scriptBottom.GetHashCode().ToString(), ScriptLocation.Body, true); | ||
} | ||
var scriptHead = this.GetPageAssetValue(item, Templates.PageAssets.Fields.JavascriptCodeTop); | ||
if (!string.IsNullOrWhiteSpace(scriptHead)) | ||
{ | ||
AssetRepository.Current.AddScript(scriptHead, scriptHead.GetHashCode().ToString(), ScriptLocation.Head, true); | ||
} | ||
} | ||
|
||
private string GetPageAssetValue(Item item, ID assetField) | ||
{ | ||
if (item.IsDerived(Templates.PageAssets.ID)) | ||
{ | ||
var assetValue = item[assetField]; | ||
if (!string.IsNullOrWhiteSpace(assetValue)) | ||
{ | ||
return assetValue; | ||
} | ||
} | ||
|
||
return GetInheritedPageAssetValue(item, assetField); | ||
} | ||
|
||
private static string GetInheritedPageAssetValue(Item item, ID assetField) | ||
{ | ||
var inheritedAssetItem = item.Axes.GetAncestors().FirstOrDefault(i => i.IsDerived(Templates.PageAssets.ID) && MainUtil.GetBool(item[Templates.PageAssets.Fields.InheritAssets], false) && string.IsNullOrWhiteSpace(item[assetField])); | ||
return inheritedAssetItem?[assetField]; | ||
} | ||
} | ||
} |
Oops, something went wrong.