예제 #1
0
        public string ReadTemplateFile(DotLiquid.Context context, string templateName)
        {
            try {
                templateName = templateName.Trim('\'', '"');

                context.GetTracer().Info("Loading template: " + templateName);

                var res = TemplateResolver.GetTemplateContents(templateName);

                if (string.IsNullOrEmpty(res))
                {
                    if (!string.IsNullOrEmpty(LocalPath))
                    {
                        templateName = Path.Combine(LocalPath, templateName);

                        if (File.Exists(templateName))
                        {
                            res = File.ReadAllText(templateName);
                        }
                        else
                        {
                            throw new WhamTemplateException("[FKASIHQJWKTP] Template not found: " + templateName);
                        }
                    }
                    else
                    {
                        throw new WhamTemplateException($"[FHBAOUTOPQA] Template not loaded: '{templateName}'");
                    }
                }

                return(res);
            } catch (Exception x) {
                throw new WhamTemplateException($"[FKJJAHQROIZ] Template error accessing '{templateName}': {x.Message}", x);
            }
        }
예제 #2
0
        public string Liquidize(string template)
        {
            Context["schema"] = new JSchemaDrop(CurrentSchema);

            Context.GetTracer().Info("[WHEGNJHKOQPA] Liquidizing template: " + template);
            if (RenderParameters == null)
            {
                RenderParameters = new RenderParameters
                {
                    Context = Context,
                    Filters = new[]
                    {
                        typeof(ClassNameFilters),
                        typeof(CollectionFilters),
                        typeof(TextFilters),
                    },
                    LocalVariables = Hash.FromAnonymousObject(new
                    {
                        schema = new JSchemaDrop(CurrentSchema),
                    }),
                    RethrowErrors = true,
                };
            }

            if (template.EndsWith(".dlq") && template.IndexOfAny(Path.GetInvalidPathChars()) < 0)
            {
                Context.GetTracer().Info("[WHGNJFIUQYU] Loading template contents from: " + template);
                template = TemplateResolver.GetTemplateContents(template) ?? $"[XQLGFTZHTD] Template not found: {template}";
            }

            if (template != null)
            {
                // tags that sit alone on a line are moved to the line above to avoid excessive whitespace
                template = Regex.Replace(template, @"(?m)^\s+({%[^{%]+%})\s*$", "$1");
            }
            var parsedTemplate = Template.Parse(template);

            return(parsedTemplate.Render(RenderParameters));
        }