예제 #1
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));
        }
예제 #2
0
        public Uri AddSchema(string jsonSchema, bool makeCurrent = false)
        {
            JSchema jschema = JSchema.Parse(jsonSchema, Resolver);

            Context.GetTracer().Info($"WhamEngine adding schema {jschema.Title}");
            if (!string.IsNullOrEmpty(jschema.Title))
            {
                if (ClassNameFilters.IsValidTypeName.IsMatch(jschema.Title))
                {
                    if (makeCurrent)
                    {
                        CurrentSchema = jschema;
                    }

                    var uri = new Uri("http://wham.org/" + jschema.Title);
                    Resolver.Add(uri, jsonSchema);

                    if (Context != null)
                    {
                        Context["currentSchema"] = new JSchemaDrop(CurrentSchema);
                        var schemas = Context["schemas"] as List <JSchemaDrop> ?? new List <JSchemaDrop>();
                        schemas.Add(new JSchemaDrop(jschema));
                        Context["schemas"] = schemas;
                    }

                    return(uri);
                }
                else
                {
                    throw new WhamException("[FIAIQIWEHRH] Invalid schema title, it needs to be in namespace.class format");
                }
            }
            else
            {
                throw new WhamException("[FAUHQRJKWRTO] Schema needs Title");
            }
        }