-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Path.Lookup #70
Add Path.Lookup #70
Conversation
Codecov Report
@@ Coverage Diff @@
## master #70 +/- ##
==========================================
+ Coverage 43.98% 44.97% +0.99%
==========================================
Files 40 43 +3
Lines 2626 2679 +53
Branches 362 367 +5
==========================================
+ Hits 1155 1205 +50
- Misses 1372 1375 +3
Partials 99 99
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
How is this different from build-in |
@zjklee So a change could be like: using HandlebarsDotNet.PathStructure;
namespace HandlebarsDotNet.Helpers
{
public sealed class LookupReturnHelperDescriptor : IHelperDescriptor<HelperOptions>
{
public PathInfo Name { get; } = "lookup";
public object Invoke(in HelperOptions options, in Context context, in Arguments arguments)
{
if (arguments.Length != 2 && arguments.Length != 3)
{
throw new HandlebarsException("{{lookup}} helper must have two or three arguments");
}
var segment = ChainSegment.Create(arguments[1]);
var defaultValueIfNotFound = arguments.Length == 3 ? arguments[2] : UndefinedBindingResult.Create(segment);
return !options.TryAccessMember(arguments[0], segment, out var value)
? defaultValueIfNotFound
: value;
}
public void Invoke(in EncodedTextWriter output, in HelperOptions options, in Context context, in Arguments arguments)
{
output.Write(Invoke(options, context, arguments));
}
}
} |
@StefH , looks good to me 🙂 |
@zjklee Shall I create a PR for Handlebars.Net ? |
@zjklee See PR Handlebars-Net/Handlebars.Net#542 |
No description provided.