Exemplo n.º 1
0
        public async Task <IActionResult> Render()
        {
            if (!HttpContext.Items.ContainsKey("object"))
            {
                return(RedirectPermanent("/"));
            }

            var obj  = (APEntity)HttpContext.Items["object"];
            var regs = new TemplateService.Registers();

            regs.UsedEntities[obj.Id] = obj;

            var text = await _templateService.ParseTemplate("body", _entityStore, obj, regs);

            var objectTemplates = regs.UsedEntities.Select(a => new Tuple <string, JToken>(a.Key, a.Value.Data.Serialize(true))).ToDictionary(a => a.Item1, a => a.Item2);

            if (Request.Query.ContainsKey("nopreload"))
            {
                objectTemplates.Clear();
            }

            var page = _templateService.PageTemplate.Replace("{{render:body}}", text).Replace("{{preload}}", JsonConvert.SerializeObject(objectTemplates));

            return(Content(page, "text/html"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> RenderRemote(string url)
        {
            if (url == null)
            {
                return(RedirectPermanent("/"));
            }

            var obj = await _entityStore.GetEntity(url, true);

            var regs = new TemplateService.Registers();

            regs.UsedEntities[obj.Id] = obj;

            var text = await _templateService.ParseTemplate("body", _entityStore, obj, regs);

            var objectTemplates = regs.UsedEntities.Select(a => new Tuple <string, JToken>(a.Key, a.Value.Data.Serialize(true))).ToDictionary(a => a.Item1, a => a.Item2);

            if (Request.Query.ContainsKey("nopreload"))
            {
                objectTemplates.Clear();
            }

            var page = _templateService.PageTemplate.Replace("<div class=\"container\" x-render=\"body\"></div>", text).Replace("{{preload}}", JsonConvert.SerializeObject(objectTemplates).Replace("<", "\\u003C"));

            return(Content(page, "text/html"));
        }