Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created August 9, 2010 19:25
Show Gist options
  • Save jmarnold/515951 to your computer and use it in GitHub Desktop.
Save jmarnold/515951 to your computer and use it in GitHub Desktop.
public class HelloWorldHtmlConventions : DefaultHtmlConventions
{
private readonly ValidationGraph _graph;
public HelloWorldHtmlConventions(ValidationGraph graph)
{
_graph = graph;
Editors
.If(a => a.Accessor.FieldName.Contains("Password"))
.Modify(t => t.Attr("type", "password"));
Editors
.Always
.Modify(ModifyWithValidationGraph);
}
private void ModifyWithValidationGraph(ElementRequest request, HtmlTag tag)
{
// check for partials
var modelType = (request.Accessor is SingleProperty)
? request.Model.GetType()
: request.Accessor.OwnerType;
var calls = _graph
.FindChain(modelType)
.CallsFor(request.Accessor.FieldName);
calls
.Where(call => !typeof(ComparisonValidationRule<>).IsAssignableFrom(call.RuleType))
.Each(call => tag.Modify(t => t.AddClass(call.ToRuleDef().Name.ToLower())));
tag.Attr("id", request.ElementId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment