*Breaking Change* Removed Parameter & Culture Dictionaries - results in easier to read razor
This commit is contained in:
@@ -10,11 +10,11 @@ namespace umbraco.MacroEngines
|
||||
private MacroModel _macro;
|
||||
private INode _node;
|
||||
protected T CurrentModel;
|
||||
protected DynamicLambdaDictionary<string> ParameterDictionary;
|
||||
protected DynamicLambdaDictionary<string> CultureDictionary;
|
||||
protected ParameterDictionary ParameterDictionary;
|
||||
protected CultureDictionary CultureDictionary;
|
||||
|
||||
public dynamic Parameter { get { return ParameterDictionary; } }
|
||||
public dynamic Dictionary { get { return CultureDictionary; } }
|
||||
public ParameterDictionary Parameter { get { return ParameterDictionary; } }
|
||||
public CultureDictionary Dictionary { get { return CultureDictionary; } }
|
||||
|
||||
public MacroModel Macro { get { return _macro; } }
|
||||
public INode Node { get { return _node; } }
|
||||
|
||||
@@ -1,30 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using umbraco.cms.businesslogic;
|
||||
using umbraco.cms.businesslogic.language;
|
||||
|
||||
namespace umbraco.MacroEngines {
|
||||
public class CultureDictionary : DynamicLambdaDictionary<string> {
|
||||
public CultureDictionary() : base(ParseDictionaryKey) { }
|
||||
|
||||
public static string ParseDictionaryKey(string key) {
|
||||
if (string.IsNullOrEmpty(key))
|
||||
return string.Empty;
|
||||
var list = new List<string>();
|
||||
list.Add(key);
|
||||
if (key.Contains("_"))
|
||||
list.Add(key.Replace("_", " "));
|
||||
return GetFirstDictionaryItem(list);
|
||||
}
|
||||
public class CultureDictionary : LambdaDictionary<string> {
|
||||
public CultureDictionary() : base(CollectEntry) { }
|
||||
|
||||
public static string GetFirstDictionaryItem(IEnumerable<string> keys) {
|
||||
foreach (var item in keys) {
|
||||
try {
|
||||
var l = Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentUICulture.Name);
|
||||
return new Dictionary.DictionaryItem(item).Value(l.id);
|
||||
} catch (Exception errDictionary) {}
|
||||
public static string CollectEntry(string key) {
|
||||
try{
|
||||
var l = Language.GetByCultureCode(System.Threading.Thread.CurrentThread.CurrentUICulture.Name);
|
||||
return new Dictionary.DictionaryItem(key).Value(l.id);
|
||||
}
|
||||
catch (Exception errDictionary) { }
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
|
||||
namespace umbraco.MacroEngines {
|
||||
|
||||
public abstract class DynamicLambdaDictionary<TValue> : DynamicObject {
|
||||
|
||||
protected Func<string, TValue> RequestLambda;
|
||||
|
||||
protected DynamicLambdaDictionary() {}
|
||||
|
||||
protected DynamicLambdaDictionary(Func<string, TValue> requestLambda) {
|
||||
if (requestLambda == null)
|
||||
throw new ArgumentNullException("requestLambda");
|
||||
RequestLambda = requestLambda;
|
||||
}
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result) {
|
||||
result = RequestLambda.Invoke(binder.Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
26
umbraco.MacroEngines.Juno/LambdaDictionary.cs
Normal file
26
umbraco.MacroEngines.Juno/LambdaDictionary.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
|
||||
namespace umbraco.MacroEngines {
|
||||
|
||||
public abstract class LambdaDictionary<TValue> {
|
||||
|
||||
protected Func<string, TValue> RequestLambda;
|
||||
|
||||
protected LambdaDictionary() {}
|
||||
|
||||
protected LambdaDictionary(Func<string, TValue> requestLambda) {
|
||||
if (requestLambda == null)
|
||||
throw new ArgumentNullException("requestLambda");
|
||||
RequestLambda = requestLambda;
|
||||
}
|
||||
|
||||
public TValue this[string alias] {
|
||||
get {
|
||||
return RequestLambda.Invoke(alias);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using umbraco.cms.businesslogic.macro;
|
||||
|
||||
namespace umbraco.MacroEngines {
|
||||
public class ParameterDictionary : DynamicLambdaDictionary<string> {
|
||||
public class ParameterDictionary : LambdaDictionary<string> {
|
||||
public ParameterDictionary(IEnumerable<MacroPropertyModel> properties) {
|
||||
RequestLambda = new Func<string, string>(key => {
|
||||
var model = properties.FirstOrDefault(p => p.Key == key);
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<Compile Include="DynamicNode.cs" />
|
||||
<Compile Include="DynamicNodeContext.cs" />
|
||||
<Compile Include="IMacroContext.cs" />
|
||||
<Compile Include="DynamicLambdaDictionary.cs" />
|
||||
<Compile Include="LambdaDictionary.cs" />
|
||||
<Compile Include="ParameterDictionary.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RazorBuildProvider.cs" />
|
||||
|
||||
Reference in New Issue
Block a user