Exemple #1
0
        public static List <IRenderTask> GetLayoutPlan(string NameOrId, RenderContext context)
        {
            var layout = context.WebSite.SiteDb().Layouts.GetByNameOrId(NameOrId);

            if (layout == null)
            {
                return(null);
            }
            List <IRenderTask> renderplans = null;
            EvaluatorOption    options     = new  EvaluatorOption();

            options.RenderHeader  = true;
            options.OwnerObjectId = layout.Id;

            if (context.Request.Channel == RequestChannel.InlineDesign)
            {
                string body = DomService.ApplyKoobooId(layout.Body);
                options.RequireBindingInfo = true;
                renderplans = RenderEvaluator.Evaluate(body, options);
            }
            else
            {
                renderplans = Cache.RenderPlan.GetOrAddRenderPlan(context.WebSite.SiteDb(), layout.Id, () => RenderEvaluator.Evaluate(layout.Body, options));
            }

            return(renderplans);
        }
Exemple #2
0
        public ConditionRenderTask(Element element, string ConditionText, EvaluatorOption options)
        {
            if (string.IsNullOrWhiteSpace(ConditionText))
            {
                return;
            }

            ConditionText = ConditionText.Trim();
            if (ConditionText.StartsWith("!"))
            {
                ConditionText   = ConditionText.Substring(1);
                this.IsOpposite = true;
            }

            if (ConditionText.ToLower().StartsWith("repeat"))
            {
                this.IsRepeatCondition = true;
                this.ConditionText     = GetConditionText(ConditionText);
            }

            if (FunctionHelper.IsFunction(ConditionText))
            {
                this.IsFunction = true;
                this.function   = FunctionHelper.Parse(ConditionText);
            }
            else
            {
                this.Filter = FilterHelper.GetFilter(ConditionText);
                FilterHelper.CheckValueType(this.Filter);
            }
            string NewElementString = Service.DomService.ReSerializeElement(element);

            this.SubTasks = RenderEvaluator.Evaluate(NewElementString, options);
        }
Exemple #3
0
        public RepeatRenderTask(string DataKey, string Alias, bool RepeatSelf, Element element, EvaluatorOption options)
        {
            this.datakey    = DataKey;
            this.alias      = Alias;
            this.repeatself = RepeatSelf;
            string boundary = null;

            if (options.RequireBindingInfo)
            {
                boundary = Kooboo.Lib.Helper.StringHelper.GetUniqueBoundary();
            }

            BindingEndRenderTask bindingEndRenderTask = null;

            if (options.RequireBindingInfo)
            {
                var bindingRenderTask = new BindingRenderTask(new RepeatItemTrace(Alias));
                bindingEndRenderTask = bindingRenderTask.BindingEndRenderTask;
                this.SubTasks.Add(bindingRenderTask);
            }

            if (repeatself)
            {
                string NewHtml = Service.DomService.ReSerializeElement(element, element.InnerHtml);
                this.SubTasks.AddRange(RenderEvaluator.Evaluate(NewHtml, options));
            }
            else
            {
                string opentag = string.Empty;

                this.ContainerEndTag = "</" + element.tagName + ">";

                var attributeEvaluator = new AttributeEvaluator();
                var response           = attributeEvaluator.Evaluate(element, options);
                if (response != null && response.AttributeTask != null && response.AttributeTask.Count() > 0)
                {
                    opentag = RenderHelper.GetHalfOpenTag(element);
                    this.ContainerTask.Add(new ContentRenderTask(opentag));
                    this.ContainerTask.AddRange(response.AttributeTask);
                    this.ContainerTask.Add(new ContentRenderTask(">"));
                }
                else
                {
                    this.ContainerTask.Add(new ContentRenderTask(Service.DomService.ReSerializeOpenTag(element)));
                }
                this.SubTasks.AddRange(RenderEvaluator.Evaluate(element.InnerHtml, options));
            }

            if (options.RequireBindingInfo)
            {
                this.SubTasks.Add(bindingEndRenderTask);
            }
        }
Exemple #4
0
        public static async Task <string> RenderPageAsync(FrontContext context)
        {
            if (context.Page.Parameters.Count > 0)
            {
                context.RenderContext.DataContext.Push(context.Page.Parameters);
            }

            string result = string.Empty;

            List <IRenderTask> RenderPlan = null;

            var option = RenderOptionHelper.GetPageOption(context);

            if (option.RequireBindingInfo)
            {
                string html = DomService.ApplyKoobooId(context.Page.Body);
                RenderPlan = RenderEvaluator.Evaluate(html, option);
                var traceability = new ComponentTrace(context.Page.Id.ToString(), "page");
                var bindingTask  = new BindingRenderTask(traceability, new Dictionary <string, string> {
                    { "scope", "true" }
                });
                RenderPlan.Insert(0, bindingTask);
                RenderPlan.Add(bindingTask.BindingEndRenderTask);

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
                result = DomService.EnsureDocType(result);
            }
            else
            {
                RenderPlan = Cache.RenderPlan.GetOrAddRenderPlan(context.SiteDb, context.Page.Id, () => RenderEvaluator.Evaluate(context.Page.Body, option));

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
            }


            if (context.Page.Type == Models.PageType.RichText)
            {
                //special for richtext editor. meta name = "viewport" content = "width=device-width, initial-scale=1"
                var header = new Models.HtmlHeader();
                Dictionary <string, string> content = new Dictionary <string, string>();
                content.Add("", "width=device-width, initial-scale=1");
                header.Metas.Add(new Models.HtmlMeta()
                {
                    name = "viewport", content = content
                });

                result = HtmlHeadService.SetHeaderToHtml(result, header);
            }

            return(result);
        }
Exemple #5
0
        public static string Bind(object Model, string Html, string ModelName = "model")
        {
            if (Model == null)
            {
                return(Html);
            }
            RenderContext context = new RenderContext();

            context.DataContext.Push(ModelName, Model);

            var plans = RenderEvaluator.Evaluate(Html, new EvaluatorOption());

            return(RenderHelper.Render(plans, context));
        }
Exemple #6
0
        public ConditionRenderTask(Element element, string ConditionText, EvaluatorOption options)
        {
            if (ConditionText.ToLower().StartsWith("repeat"))
            {
                this.IsRepeatCondition = true;
                this.ConditionText     = GetConditionText(ConditionText);
            }
            else
            {
                this.Filter = FilterHelper.GetFilter(ConditionText);
            }
            string NewElementString = Service.DomService.ReSerializeElement(element);

            this.SubTasks = RenderEvaluator.Evaluate(NewElementString, options);
        }
Exemple #7
0
        public static async Task <string> RenderPageAsync(FrontContext context)
        {
            if (context.Page.Parameters.Count > 0)
            {
                context.RenderContext.DataContext.Push(context.Page.Parameters);
            }

            string result = string.Empty;

            List <IRenderTask> RenderPlan = null;

            if (context.RenderContext.Request.Channel != Data.Context.RequestChannel.InlineDesign)
            {
                RenderPlan = Cache.RenderPlan.GetOrAddRenderPlan(context.SiteDb, context.Page.Id, () => RenderEvaluator.Evaluate(context.Page.Body, GetPageOption(context)));

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
            }
            else
            {
                string html = DomService.ApplyKoobooId(context.Page.Body);
                RenderPlan = RenderEvaluator.Evaluate(html, GetPageOption(context));
                RenderPlan.Insert(0, new BindingObjectRenderTask()
                {
                    ObjectType = "page", NameOrId = context.Page.Id.ToString()
                });

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
                result = DomService.EnsureDocType(result);
            }


            if (context.Page.Type == Models.PageType.RichText)
            {
                //special for richtext editor. meta name = "viewport" content = "width=device-width, initial-scale=1"
                var header = new Models.HtmlHeader();
                Dictionary <string, string> content = new Dictionary <string, string>();
                content.Add("", "width=device-width, initial-scale=1");
                header.Metas.Add(new Models.HtmlMeta()
                {
                    name = "viewport", content = content
                });

                result = HtmlHeadService.SetHeaderToHtml(result, header);
            }

            return(result);
        }
Exemple #8
0
        private void LoadComponents(Element element, EvaluatorOption option)
        {
            foreach (var item in element.childNodes.item)
            {
                if (item.nodeType == enumNodeType.ELEMENT)
                {
                    Element child = item as Element;

                    if (child.tagName == "position" || child.tagName == "placeholder")
                    {
                        string positionname = child.id;
                        if (string.IsNullOrEmpty(positionname))
                        {
                            positionname = child.getAttribute("name");
                        }

                        if (string.IsNullOrEmpty(positionname))
                        {
                            continue;
                        }
                        List <IRenderTask> ComTask = new List <IRenderTask>();

                        string innerhtml = child.InnerHtml;

                        if (!string.IsNullOrWhiteSpace(innerhtml))
                        {
                            var newoption = option.Clone();
                            newoption.RenderHeader = false;
                            ComTask = RenderEvaluator.Evaluate(innerhtml, option);
                        }

                        if (Components.ContainsKey(positionname))
                        {
                            var current = Components[positionname];
                            current.AddRange(ComTask);
                            Components[positionname] = current;
                        }
                        else
                        {
                            Components[positionname] = ComTask;
                        }
                    }
                }
            }
        }
Exemple #9
0
        public SysRenderTask(Element element, string attributeName, string ConditionText, EvaluatorOption options)
        {
            this.ConditionText = ConditionText.Trim();

            this.AttributeName = attributeName;

            this.KeyWord = this.AttributeName.Replace("k-sys-", "");

            if (this.KeyWord != null)
            {
                var para = ",;'\"";
                this.KeyWord = this.KeyWord.ToLower().Trim(para.ToCharArray());
            }

            string NewElementString = Service.DomService.ReSerializeElement(element);

            this.SubTasks = RenderEvaluator.Evaluate(NewElementString, options);
        }
Exemple #10
0
        public static async Task <string> RenderMockPageAsync(FrontContext context)
        {
            if (context.Page.Parameters.Count > 0)
            {
                context.RenderContext.DataContext.Push(context.Page.Parameters);
            }

            string result = string.Empty;

            List <IRenderTask> RenderPlan = null;

            var option = RenderOptionHelper.GetPageOption(context);

            option.Evaluators = EvaluatorContainer.MockData;

            context.RenderContext.MockData = true;

            RenderPlan = RenderEvaluator.Evaluate(context.Page.Body, option);

            result = RenderHelper.Render(RenderPlan, context.RenderContext);

            return(result);
        }
Exemple #11
0
        public static List <IRenderTask> GetLayoutPlan(string NameOrId, RenderContext context)
        {
            var layout = context.WebSite.SiteDb().Layouts.GetByNameOrId(NameOrId);

            if (layout == null)
            {
                return(null);
            }
            List <IRenderTask> renderplans = null;

            EvaluatorOption options = RenderOptionHelper.GetLayoutOption(context, layout.Id);

            if (options.RequireBindingInfo)
            {
                string body = DomService.ApplyKoobooId(layout.Body);
                renderplans = RenderEvaluator.Evaluate(body, options);
            }
            else
            {
                renderplans = Cache.RenderPlan.GetOrAddRenderPlan(context.WebSite.SiteDb(), layout.Id, () => RenderEvaluator.Evaluate(layout.Body, options));
            }

            return(renderplans);
        }
Exemple #12
0
        public static string Bind(string Html, RenderContext context)
        {
            var plans = RenderEvaluator.Evaluate(Html, new EvaluatorOption());

            return(RenderHelper.Render(plans, context));
        }
Exemple #13
0
 private List <IRenderTask> GetBodyTask(string body, EvaluatorOption option)
 {
     return(RenderEvaluator.Evaluate(body, option));
 }
Exemple #14
0
        public static async Task <string> RenderPageAsync(FrontContext context)
        {
            if (context.Page.Parameters.Count > 0)
            {
                context.RenderContext.DataContext.Push(context.Page.Parameters);
            }

            string result = string.Empty;

            List <IRenderTask> RenderPlan = null;

            var option = RenderOptionHelper.GetPageOption(context);

            if (option.RequireBindingInfo)
            {
                string html = DomService.ApplyKoobooId(context.Page.Body);
                RenderPlan = RenderEvaluator.Evaluate(html, option);
                var traceability = new ComponentTrace(context.Page.Id.ToString(), "page");
                var bindingTask  = new BindingRenderTask(traceability, new Dictionary <string, string> {
                    { "scope", "true" }
                });
                RenderPlan.Insert(0, bindingTask);
                RenderPlan.Add(bindingTask.BindingEndRenderTask);

                result = RenderHelper.Render(RenderPlan, context.RenderContext);
                result = DomService.EnsureDocType(result);
            }
            else
            {
                RenderPlan = Cache.RenderPlan.GetOrAddRenderPlan(context.SiteDb, context.Page.Id, () => RenderEvaluator.Evaluate(context.Page.Body, option));

                // check the cache.
                if (context.Page.EnableCache)
                {
                    Dictionary <string, string> querystring = null;

                    if (!string.IsNullOrWhiteSpace(context.Page.CacheQueryKeys))
                    {
                        //querystring = RequestManager.GetQueryString(context.RenderContext.Request);
                        querystring = GetParaValues(context.RenderContext, context.Page.CacheKeys);
                    }

                    if (context.Page.CacheByVersion)
                    {
                        result = PageCache.PageCache.GetByVersion(context.SiteDb.Id, context.Page.Id, context.Page.Version, querystring);
                    }
                    else
                    {
                        result = PageCache.PageCache.GetByMinutes(context.SiteDb.Id, context.Page.Id, context.Page.CacheMinutes, querystring, context.Page.Version);
                    }

                    if (string.IsNullOrEmpty(result))
                    {
                        result = RenderHelper.Render(RenderPlan, context.RenderContext);

                        Kooboo.Sites.Render.PageCache.PageCache.Set(context.SiteDb.Id, context.Page.Id, result, context.Page.Version, querystring);
                    }


                    // cache result may have replacement.
                }
                else
                {
                    result = RenderHelper.Render(RenderPlan, context.RenderContext);
                }
            }


            if (context.Page.Type == Models.PageType.RichText)
            {
                //special for richtext editor. meta name = "viewport" content = "width=device-width, initial-scale=1"
                var header = new Models.HtmlHeader();
                Dictionary <string, string> content = new Dictionary <string, string>();
                content.Add("", "width=device-width, initial-scale=1");
                header.Metas.Add(new Models.HtmlMeta()
                {
                    name = "viewport", content = content
                });

                result = HtmlHeadService.SetHeaderToHtml(result, header);
            }

            return(result);
        }
 public TagOmitRenderTask(Element element, EvaluatorOption options)
 {
     //string NewElementString = Service.DomService.ReSerializeElement(element);
     this.SubTasks = RenderEvaluator.Evaluate(element.InnerHtml, options);
 }
Exemple #16
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Attribute))
            {
                return(null);
            }

            Dictionary <string, string> appendValues = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            if (node.nodeType != enumNodeType.ELEMENT)
            {
                return(null);
            }
            var element = node as Element;

            string attName = null;

            foreach (var item in element.attributes)
            {
                if (item.name == "tal-attribute" || item.name == "k-attribute" || item.name == "tal-attributes" || item.name == "k-attributes")
                {
                    attName = item.name;
                    break;
                }
            }

            if (string.IsNullOrEmpty(attName))
            {
                return(null);
            }

            string attributeValues = element.getAttribute(attName);

            element.removeAttribute(attName);

            if (string.IsNullOrEmpty(attributeValues) || attributeValues.IndexOf(' ') < 0)
            {
                return(null);
            }

            EvaluatorResponse response = new EvaluatorResponse();

            string[] attributes = attributeValues.Split(';');

            foreach (var item in attributes)
            {
                var attkeyvalue = ParseAtt(item);
                if (attkeyvalue == null)
                {
                    continue;
                }

                string attributeName  = attkeyvalue.Key;
                string attributeValue = attkeyvalue.Value;

                if (AppendAttributes.ContainsKey(attributeName))
                {
                    string sep   = AppendAttributes[attributeName];
                    string value = element.getAttribute(attributeName);

                    if (!string.IsNullOrEmpty(value))
                    {
                        if (!value.Trim().EndsWith(sep))
                        {
                            value = value + sep;
                        }
                        if (appendValues.ContainsKey(attributeName))
                        {
                            var orgvalue = appendValues[attributeName];
                            value = orgvalue + value;
                        }
                        appendValues[attributeName] = value;
                    }
                }

                List <IRenderTask> tasks = new List <IRenderTask>();
                tasks.Add(new ContentRenderTask(" " + attributeName + "=\""));

                if (appendValues.ContainsKey(attributeName))
                {
                    tasks.Add(new ContentRenderTask(appendValues[attributeName]));
                }

                tasks.Add(new ValueRenderTask(attributeValue));
                tasks.Add(new ContentRenderTask("\""));

                if (response.AttributeTask == null)
                {
                    response.AttributeTask = tasks;
                }
                else
                {
                    response.AttributeTask.AddRange(tasks);
                }

                element.removeAttribute(attributeName);


                if (!options.HasContentTask)
                {
                    response.ContentTask       = RenderEvaluator.Evaluate(element.InnerHtml, options);
                    response.StopNextEvaluator = true;
                }

                if (options.RequireBindingInfo)
                {
                    if (response.BindingTask == null)
                    {
                        response.BindingTask = new List <IRenderTask>();
                    }
                    var bindingTask = new BindingRenderTask(attributeValue, new Dictionary <string, string> {
                        { "attribute", attributeName }
                    });
                    response.BindingTask.Add(bindingTask);
                    if (response.EndBindingTask == null)
                    {
                        response.EndBindingTask = new List <IRenderTask>();
                    }
                    response.EndBindingTask.Add(bindingTask.BindingEndRenderTask);
                }
            }

            if (response.AttributeTask == null || response.AttributeTask.Count() == 0)
            {
                return(null);
            }
            else
            {
                return(response);
            }
        }
Exemple #17
0
        public ForRenderTask(string DataKey, string lowbound, string highbound, bool RepeatSelf, Element element, EvaluatorOption options)
        {
            this.datakey = DataKey;

            long low;

            if (long.TryParse(lowbound, out low))
            {
                this.LowBound = low;
            }
            else
            {
                this.LowBoundKey = lowbound;
            }

            long high;

            if (long.TryParse(highbound, out high))
            {
                this.HighBound = high;
            }
            else
            {
                this.HighBoundKey = highbound;
            }

            this.repeatself = RepeatSelf;
            string boundary = null;

            if (options.RequireBindingInfo)
            {
                boundary = Kooboo.Lib.Helper.StringHelper.GetUniqueBoundary();
            }

            if (repeatself)
            {
                string NewHtml = Service.DomService.ReSerializeElement(element, element.InnerHtml);

                if (options.RequireBindingInfo)
                {
                    //  this.SubTasks.Add(new BindingTextContentItemRenderTask(this.alias, boundary, false));
                }
                this.SubTasks.AddRange(RenderEvaluator.Evaluate(NewHtml, options));

                if (options.RequireBindingInfo)
                {
                    //this.SubTasks.Add(new BindingTextContentItemRenderTask(this.alias, boundary, true));
                }
            }
            else
            {
                string opentag = string.Empty;

                this.ContainerEndTag = "</" + element.tagName + ">";

                var attributeEvaluator = new AttributeEvaluator();
                var response           = attributeEvaluator.Evaluate(element, options);
                if (response != null && response.AttributeTask != null && response.AttributeTask.Count() > 0)
                {
                    opentag = RenderHelper.GetHalfOpenTag(element);
                    this.ContainerTask.Add(new ContentRenderTask(opentag));
                    this.ContainerTask.AddRange(response.AttributeTask);
                    this.ContainerTask.Add(new ContentRenderTask(">"));
                }
                else
                {
                    this.ContainerTask.Add(new ContentRenderTask(Service.DomService.ReSerializeOpenTag(element)));
                }


                if (options.RequireBindingInfo)
                {
                    // this.SubTasks.Add(new BindingTextContentItemRenderTask(this.alias, boundary, false));
                }

                this.SubTasks.AddRange(RenderEvaluator.Evaluate(element.InnerHtml, options));

                if (options.RequireBindingInfo)
                {
                    // this.SubTasks.Add(new BindingTextContentItemRenderTask(this.alias, boundary, true));
                }
            }
        }
Exemple #18
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Url))
            {
                return(null);
            }

            if (node.nodeType != enumNodeType.ELEMENT)
            {
                return(null);
            }
            var element  = node as Element;
            var response = new EvaluatorResponse();

            string url     = string.Empty;
            string attName = null;

            foreach (var item in element.attributes)
            {
                var lower = item.name.ToLower();
                if (lower == "tal-href" || lower == "k-href")
                {
                    attName = item.name;
                    break;
                }
            }

            if (!string.IsNullOrEmpty(attName))
            {
                url = element.getAttribute(attName);
                element.removeAttribute(attName);

                if (options.RequireBindingInfo)
                {
                    if (response.BindingTask == null)
                    {
                        response.BindingTask = new List <IRenderTask>();
                    }
                    var bindingTask = new BindingRenderTask(url, new Dictionary <string, string> {
                        { "attribute", "href" }
                    });
                    response.BindingTask.Add(bindingTask);
                    if (response.EndBindingTask == null)
                    {
                        response.EndBindingTask = new List <IRenderTask>();
                    }
                    response.EndBindingTask.Add(bindingTask.BindingEndRenderTask);
                }
            }

            if (string.IsNullOrEmpty(url))
            {
                if (options.RenderUrl && element.tagName == "a")
                {
                    string href = element.getAttribute("href");
                    if (!string.IsNullOrEmpty(href))
                    {
                        url = href.Trim();
                    }
                    if (!options.RequireBindingInfo)
                    {
                        element.removeAttribute("href");
                    }
                }
            }

            if (!string.IsNullOrEmpty(url))
            {
                if (Kooboo.Sites.Service.DomUrlService.IsSpecialUrl(url))
                {
                    return(null);
                }

                var result = new List <IRenderTask>();
                result.Add(new ContentRenderTask(" href=\""));
                result.Add(new UrlRenderTask(url));
                result.Add(new ContentRenderTask("\""));
                response.AttributeTask = result;
                element.removeAttribute("href");

                if (!options.HasContentTask)
                {
                    response.ContentTask       = RenderEvaluator.Evaluate(element.InnerHtml, options);
                    response.StopNextEvaluator = true;
                }

                return(response);
            }


            return(null);
        }