-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
4 changed files
with
136 additions
and
0 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
46 changes: 46 additions & 0 deletions
46
Sources/Umbraco.Extensions/Extract/PropertyExtractResolver.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,46 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="PropertyExtractResolver.cs" company="Colours B.V."> | ||
// © Colours B.V. 2015 | ||
// </copyright> | ||
// <summary> | ||
// The property extract resolver. | ||
// </summary> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace Umbraco.Extensions.Extract | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Umbraco.Core.ObjectResolution; | ||
using Umbraco.Extensions.Models.Custom; | ||
|
||
/// <summary> | ||
/// The property extract resolver. | ||
/// </summary> | ||
public class PropertyExtractResolver : ManyObjectsResolverBase<PropertyExtractResolver, PropertyExtractBase> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PropertyExtractResolver"/> class. | ||
/// </summary> | ||
/// <param name="extractItems"> | ||
/// The extract items. | ||
/// </param> | ||
public PropertyExtractResolver(IEnumerable<Type> extractItems) | ||
: base(extractItems, ObjectLifetimeScope.Application) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the property extract items. | ||
/// </summary> | ||
public List<PropertyExtractBase> PropertyExtractItems | ||
{ | ||
get | ||
{ | ||
return this.Values.ToList(); | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Sources/Umbraco.Extensions/Models/Custom/PropertyExtractBase.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,71 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright file="PropertyExtractBase.cs" company="Colours B.V."> | ||
// © Colours B.V. 2015 | ||
// </copyright> | ||
// <summary> | ||
// The property extract base. | ||
// </summary> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace Umbraco.Extensions.Models.Custom | ||
{ | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using Umbraco.Core.Models; | ||
using Umbraco.Web; | ||
|
||
/// <summary> | ||
/// The property extract base. | ||
/// </summary> | ||
public abstract class PropertyExtractBase | ||
{ | ||
/// <summary> | ||
/// Gets the allowed types. | ||
/// </summary> | ||
public abstract string[] AllowedTypes { get; } | ||
|
||
/// <summary> | ||
/// Checks if the extract is for this property type. | ||
/// </summary> | ||
/// <param name="propertyTypeAlias"> | ||
/// The property type alias. | ||
/// </param> | ||
/// <returns> | ||
/// The <see cref="bool"/>. | ||
/// </returns> | ||
public bool IsExtractForPropertyType(string propertyTypeAlias) | ||
{ | ||
return this.AllowedTypes.Contains(propertyTypeAlias); | ||
} | ||
|
||
/// <summary> | ||
/// Converts the content into a string for Examine. | ||
/// </summary> | ||
/// /// | ||
/// <param name="extractedContent"> | ||
/// The extracted content. | ||
/// </param> | ||
/// <param name="content"> | ||
/// The content. | ||
/// </param> | ||
/// <param name="alias"> | ||
/// The alias. | ||
/// </param> | ||
/// <param name="language"> | ||
/// The language. | ||
/// </param> | ||
public virtual void Examine( | ||
StringBuilder extractedContent, | ||
IPublishedContent content, | ||
string alias, | ||
string language = null) | ||
{ | ||
var text = content.GetPropertyValue<string>(alias); | ||
if (!string.IsNullOrEmpty(text)) | ||
{ | ||
extractedContent.Append(" " + content.GetPropertyValue<string>(alias)); | ||
} | ||
} | ||
} | ||
} |
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