Skip to content

Commit

Permalink
Merge pull request johnculviner#4 from zackpudil/master
Browse files Browse the repository at this point in the history
Required Tokens when display required properties
  • Loading branch information
johnculviner committed May 12, 2013
2 parents c021a68 + 75614b0 commit be559ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/FluentKnockoutHelpers.Core/Builders/Builder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
Expand Down Expand Up @@ -172,8 +173,6 @@ public virtual StringReturningBuilder<TModel> LabelFor<TProp>(Expression<Func<TM
return ElementSelfClosing("label", DisplayNameFor(propExpr).ToString()).Attr("for", ExpressionParser.GetExpressionText(propExpr));
}



#region Bound ___ For

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions src/FluentKnockoutHelpers.Core/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace FluentKnockoutHelpers.Core
public static class GlobalSettings
{
private static IJsonSerializer _jsonSerializer = new DefaultJsonSerializer();
private static string _requiredToken = "*";
private static bool _useRequiredToken = true;

/// <summary>
/// Supply a custom IJsonSerializer to use something other than the default JSON.NET. Ex: ServiceStack
Expand All @@ -17,5 +19,23 @@ public static IJsonSerializer JsonSerializer
get { return _jsonSerializer; }
set { _jsonSerializer = value; }
}

/// <summary>
/// Supply a custom required token to use something other than the default "*"
/// </summary>
public static string RequiredToken
{
get { return _requiredToken; }
set { _requiredToken = value; }
}

/// <summary>
/// Set whether or not to use a required token on the display name for non-nullable/required properties
/// </summary>
public static bool UseRequiredToken
{
get { return _useRequiredToken; }
set { _useRequiredToken = value; }
}
}
}
4 changes: 3 additions & 1 deletion src/FluentKnockoutHelpers.Core/Utility/ExpressionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ public static string DisplayNameFor<TParameter, TValue>(Expression<Func<TParamet
var propertyName = memberExpression.Member.Name;
var propMetadata = metaData.Properties.FirstOrDefault(p => p.PropertyName == propertyName);

var requiredToken = (GlobalSettings.UseRequiredToken && propMetadata.IsRequired ? GlobalSettings.RequiredToken : String.Empty);

if (propMetadata == null)
return CamelCaseSpacer(propertyName);

return propMetadata.DisplayName ?? CamelCaseSpacer(propMetadata.PropertyName);
return requiredToken + (propMetadata.DisplayName ?? CamelCaseSpacer(propMetadata.PropertyName));
}

//FirstName => First Name
Expand Down

0 comments on commit be559ae

Please sign in to comment.