Skip to content

Commit 34c4d8d

Browse files
committed
feat(Handlebars): options data provide root context
1 parent 9ac5c56 commit 34c4d8d

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/lib/Support/Handlebars.cpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,15 @@ evalExpr(
18801880
dom::Object cb = dom::newObject<HbsHelperObjectImpl>();
18811881
cb.set("name", helper);
18821882
cb.set("context", context);
1883+
dom::Object data;
1884+
if (!state.context.empty())
1885+
{
1886+
data = createFrame(state.context);
1887+
}
1888+
data.set("root", state.rootContext);
1889+
cb.set("data", data);
1890+
cb.set("root", state.rootContext);
1891+
cb.set("log", logger_);
18831892
setupArgs(all, context, state, args, cb, opt);
18841893
return Res{fn.call(args).value(), true, false, true};
18851894
MRDOCS_UNREACHABLE();
@@ -2414,7 +2423,13 @@ renderExpression(
24142423
dom::Object cb = dom::newObject<HbsHelperObjectImpl>();
24152424
cb.set("name", tag.helper);
24162425
cb.set("context", context);
2417-
cb.set("data", state.context);
2426+
dom::Object data;
2427+
if (!state.context.empty())
2428+
{
2429+
data = createFrame(state.context);
2430+
}
2431+
data.set("root", state.rootContext);
2432+
cb.set("data", data);
24182433
cb.set("log", logger_);
24192434
HandlebarsOptions noStrict = opt;
24202435
noStrict.strict = false;
@@ -2449,7 +2464,13 @@ renderExpression(
24492464
dom::Object cb = dom::newObject<HbsHelperObjectImpl>();
24502465
cb.set("name", helper_expr);
24512466
cb.set("context", context);
2452-
cb.set("data", state.context);
2467+
dom::Object data;
2468+
if (!state.context.empty())
2469+
{
2470+
data = createFrame(state.context);
2471+
}
2472+
data.set("root", state.rootContext);
2473+
cb.set("data", data);
24532474
cb.set("log", logger_);
24542475
HandlebarsOptions noStrict = opt;
24552476
noStrict.strict = false;
@@ -2487,7 +2508,13 @@ renderExpression(
24872508
dom::Object cb = dom::newObject<HbsHelperObjectImpl>();
24882509
cb.set("name", helper_expr);
24892510
cb.set("context", context);
2490-
cb.set("data", state.context);
2511+
dom::Object data;
2512+
if (!state.context.empty())
2513+
{
2514+
data = createFrame(state.context);
2515+
}
2516+
data.set("root", state.rootContext);
2517+
cb.set("data", data);
24912518
cb.set("log", logger_);
24922519
HandlebarsOptions noStrict = opt;
24932520
noStrict.strict = false;
@@ -3071,7 +3098,13 @@ renderBlock(
30713098
dom::Object cb = dom::newObject<HbsHelperObjectImpl>();
30723099
cb.set("name", tag.helper);
30733100
cb.set("context", context);
3074-
cb.set("data", state.context);
3101+
dom::Object data;
3102+
if (!state.context.empty())
3103+
{
3104+
data = createFrame(state.context);
3105+
}
3106+
data.set("root", state.rootContext);
3107+
cb.set("data", data);
30753108
cb.set("log", logger_);
30763109
HandlebarsOptions noStrict = opt;
30773110
noStrict.strict = opt.strict && emulateMustache;

0 commit comments

Comments
 (0)