public IEnumerable <string> Transform(ImportNode item) { //{% import 'forms.html' as forms %} var importObject = Environment.Evaluation.EvaluateDynamic(item.Template, ExpressionParserTransformer); if (!(importObject is string importString)) { throw new NotImplementedException(); } if (Environment.TryGetDynamicTemplate(importString, out var template) == false || template == null) { throw new NotImplementedException(); } var macros = NodeFinderVisitor.FindNodes <MacroNode>(template.TemplateNode); foreach (var macro in macros) { template.AddUserDefinedFunction(ConvertMacroToUserDefinedFunction(macro)); } Scopes.Current.DefineAndSetVariable(item.As, template); yield break; }
public IEnumerable <string> Transform(FromNode item) { //{% from 'forms.html' import input as input_field, textarea %} var importObject = Environment.Evaluation.EvaluateDynamic(item.Template, ExpressionParserTransformer); if (!(importObject is string importString)) { throw new NotImplementedException(); } if (Environment.TryGetDynamicTemplate(importString, out var template) == false || template == null) { throw new NotImplementedException(); } var macros = NodeFinderVisitor.FindNodes <MacroNode>(template.TemplateNode).ToDictionary(macro => macro.FunctionDeclaration.Name); foreach (var import in item.Imports) { if (macros.TryGetValue(import.MacroName, out var macroNode)) { Scopes.Current.DefineAndSetVariable(import.AliasName, ConvertMacroToUserDefinedFunction(macroNode)); } else { throw new NotImplementedException(); } } yield break; }