Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Commit

Permalink
Merge pull request #263 from Sitecore/feature/ThemedAssets
Browse files Browse the repository at this point in the history
Introducing Themes
  • Loading branch information
eldblom authored Dec 28, 2016
2 parents da481a4 + ea36cb1 commit 6577b05
Show file tree
Hide file tree
Showing 36 changed files with 781 additions and 358 deletions.
8 changes: 0 additions & 8 deletions src/Feature/Accounts/code/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,6 @@ public virtual ActionResult EditProfile(EditProfile profile)
return this.Redirect(this.Request.RawUrl);
}


[HttpGet]
[RedirectUnauthenticated]
public ActionResult Unauthorized()
{
return this.RedirectPermanent("/hello");
}

private ViewResult ProfileMismatchMessage
{
get
Expand Down
3 changes: 1 addition & 2 deletions src/Feature/Accounts/code/Services/ProfileSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ public virtual Item GetUserDefaultProfile()
public virtual IEnumerable<string> GetInterests()
{
var item = GetSettingsItem(null);
ReferenceField interestsFolder = item.Fields[Templates.ProfileSettigs.Fields.InterestsFolder];

return interestsFolder?.TargetItem?.Children.Where(i => i.IsDerived(Templates.Interest.ID))?.Select(i => i.Fields[Templates.Interest.Fields.Title].Value) ?? Enumerable.Empty<string>();
return item?.TargetItem(Templates.ProfileSettigs.Fields.InterestsFolder)?.Children.Where(i => i.IsDerived(Templates.Interest.ID))?.Select(i => i.Fields[Templates.Interest.Fields.Title].Value) ?? Enumerable.Empty<string>();
}

private static Item GetSettingsItem(Item contextItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private Item GetRootItem(Item configurationItem)
Item rootItem = null;
if (configurationItem.FieldHasValue(Templates.SearchResults.Fields.Root))
{
rootItem = ((ReferenceField)configurationItem.Fields[Templates.SearchResults.Fields.Root]).TargetItem;
rootItem = configurationItem.TargetItem(Templates.SearchResults.Fields.Root);
}
return rootItem ?? Context.Site.GetRootItem();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Feature/Teasers/code/Models/DynamicTeaserItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
using System;
using Sitecore.Data.Fields;
using Sitecore.Data.Items;
using Sitecore.Foundation.SitecoreExtensions.Extensions;

public class DynamicTeaserItem
public class DynamicTeaserItem
{
public DynamicTeaserItem(Item headline) : this()
{
Expand All @@ -15,8 +16,7 @@ public DynamicTeaserItem(Item headline) : this()

private string GetIcon(Item headline)
{
ReferenceField iconField = headline.Fields[Templates.TeaserHeadline.Fields.Icon];
return iconField.TargetItem?[Templates.Icon.Fields.CssClass];
return headline?.TargetItem(Templates.TeaserHeadline.Fields.Icon)?[Templates.Icon.Fields.CssClass];
}

public DynamicTeaserItem()
Expand Down
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>
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 src/Foundation/Assets/code/Pipelines/GetPageRendering/AddAssets.cs
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);
}
}
}
}
}
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];
}
}
}
Loading

0 comments on commit 6577b05

Please sign in to comment.