Exemple #1
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Header))
            {
                return(null);
            }

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

            if (element.tagName == "head" && options.RenderHeader)
            {
                var response = new EvaluatorResponse();
                var result   = new List <IRenderTask>();
                result.Add(new HeaderRenderTask(element));
                response.ContentTask       = result;
                response.OmitTag           = true;
                response.StopNextEvaluator = true;
                return(response);
            }
            return(null);
        }
Exemple #2
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Content))
            {
                return(null);
            }

            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-content" || item.name == "k-content" || item.name == "tal-replace" || item.name == "k-replace")
                {
                    attName = item.name;
                    break;
                }
            }
            if (!string.IsNullOrEmpty(attName))
            {
                var    response = new EvaluatorResponse();
                var    result   = new List <IRenderTask>();
                string value    = element.getAttribute(attName);
                element.removeAttribute(attName);
                result.Add(new ValueRenderTask(value));
                response.ContentTask = result;
                if (attName == "tal-replace" || attName == "k-replace")
                {
                    response.OmitTag = true;
                }

                if (options.RequireBindingInfo)
                {
                    if (response.BindingTask == null)
                    {
                        response.BindingTask = new List <IRenderTask>();
                    }
                    var bindingTask = new BindingRenderTask(value);
                    response.BindingTask.Add(bindingTask);
                    if (response.EndBindingTask == null)
                    {
                        response.EndBindingTask = new List <IRenderTask>();
                    }
                    response.EndBindingTask.Add(bindingTask.BindingEndRenderTask);
                }

                options.HasContentTask = true;
                return(response);
            }
            return(null);
        }
Exemple #3
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Form))
            {
                return(null);
            }

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

            if (ShouldEvaluate(element))
            {
                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();

                Guid   OwnerObjectId = options.OwnerObjectId;
                string KoobooId      = Service.DomService.GetKoobooId(element);
                Guid   FormId        = Kooboo.Data.IDGenerator.GetFormId(OwnerObjectId, KoobooId);

                result.Add(new FormRenderTask(element, OwnerObjectId, FormId, options));

                response.ContentTask       = result;
                response.StopNextEvaluator = true;
                response.OmitTag           = true;

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

                    var startbinding = new BindingObjectRenderTask()
                    {
                        ObjectType = "form", Boundary = boundary, NameOrId = FormId.ToString()
                    };
                    List <IRenderTask> bindingstarts = new List <IRenderTask>();
                    bindingstarts.Add(startbinding);
                    response.BindingTask = bindingstarts;

                    var endbinding = new BindingObjectRenderTask()
                    {
                        ObjectType = "form", IsEndBinding = true, Boundary = boundary, NameOrId = FormId.ToString()
                    };

                    List <IRenderTask> bindingends = new List <IRenderTask>();
                    bindingends.Add(endbinding);
                    response.EndBindingTask = bindingends;
                }
                return(response);
            }

            return(null);
        }
Exemple #4
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Label))
            {
                return(null);
            }

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

            string LabelName = null;

            foreach (var item in element.attributes)
            {
                var lower = item.name.ToLower();
                if (lower == "tal-label" || lower == "k-label")
                {
                    LabelName = item.name;
                    break;
                }
            }
            if (!string.IsNullOrEmpty(LabelName))
            {
                var    response = new EvaluatorResponse();
                var    result   = new List <IRenderTask>();
                string value    = element.getAttribute(LabelName);
                element.removeAttribute(LabelName);

                if (options.RequireBindingInfo)
                {
                    if (response.BindingTask == null)
                    {
                        response.BindingTask = new List <IRenderTask>();
                    }
                    var traceability = new ComponentTrace(value, "label");
                    var bindingTask  = new BindingRenderTask(traceability);
                    response.BindingTask.Add(bindingTask);
                    if (response.EndBindingTask == null)
                    {
                        response.EndBindingTask = new List <IRenderTask>();
                    }
                    response.EndBindingTask.Add(bindingTask.BindingEndRenderTask);
                }

                result.Add(new LabelRenderTask(value));
                response.ContentTask = result;
                return(response);
            }
            return(null);
        }
Exemple #5
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Label))
            {
                return(null);
            }

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

            string LabelName = null;

            foreach (var item in element.attributes)
            {
                var lower = item.name.ToLower();
                if (lower == "tal-label" || lower == "k-label")
                {
                    LabelName = item.name;
                    break;
                }
            }
            if (!string.IsNullOrEmpty(LabelName))
            {
                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();
                string             value  = element.getAttribute(LabelName);

                if (!options.RequireBindingInfo)
                {
                    element.removeAttribute(LabelName);
                }
                else
                {
                    string koobooid = element.getAttribute("kooboo-id");
                    BindingObjectRenderTask binding = new BindingObjectRenderTask()
                    {
                        ObjectType = "Label", AttributeName = LabelName, BindingValue = value, KoobooId = koobooid
                    };
                    List <IRenderTask> bindings = new List <IRenderTask>();
                    bindings.Add(binding);
                    response.BindingTask = bindings;
                }

                result.Add(new LabelRenderTask(value));
                response.ContentTask = result;
                return(response);
            }
            return(null);
        }
Exemple #6
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Form))
            {
                return(null);
            }

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

            if (ShouldEvaluate(element))
            {
                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();

                Guid   OwnerObjectId = options.OwnerObjectId;
                string KoobooId      = Service.DomService.GetKoobooId(element);
                Guid   FormId        = Kooboo.Data.IDGenerator.GetFormId(OwnerObjectId, KoobooId);

                result.Add(new FormRenderTask(element, OwnerObjectId, FormId, options));

                response.ContentTask       = result;
                response.StopNextEvaluator = true;
                response.OmitTag           = true;

                if (options.RequireBindingInfo)
                {
                    if (response.BindingTask == null)
                    {
                        response.BindingTask = new List <IRenderTask>();
                    }
                    var traceability = new ComponentTrace(FormId.ToString(), "innerform");
                    var bindingTask  = new BindingRenderTask(traceability);
                    response.BindingTask.Add(bindingTask);
                    if (response.EndBindingTask == null)
                    {
                        response.EndBindingTask = new List <IRenderTask>();
                    }
                    response.EndBindingTask.Add(bindingTask.BindingEndRenderTask);
                }
                return(response);
            }

            return(null);
        }
Exemple #7
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.SiteLayout))
            {
                return(null);
            }

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

            if (element.tagName == "layout" && (element.hasAttribute("id") || element.hasAttribute("name")))
            {
                var response = new EvaluatorResponse();
                var result   = new List <IRenderTask>();
                result.Add(new SiteLayoutRenderTask(element, options));
                response.ContentTask = result;
                response.OmitTag     = true;

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

                    var startbinding = new BindingObjectRenderTask()
                    {
                        ObjectType = "layout", Boundary = boundary, NameOrId = element.id
                    };
                    List <IRenderTask> bindingstarts = new List <IRenderTask>();
                    bindingstarts.Add(startbinding);
                    response.BindingTask = bindingstarts;

                    var endbinding = new BindingObjectRenderTask()
                    {
                        ObjectType = "layout", IsEndBinding = true, Boundary = boundary, NameOrId = element.id
                    };

                    List <IRenderTask> bindingends = new List <IRenderTask>();
                    bindingends.Add(endbinding);
                    response.EndBindingTask = bindingends;
                }
                return(response);
            }

            return(null);
        }
Exemple #8
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Component))
            {
                return(null);
            }
            if (node.nodeType != enumNodeType.ELEMENT)
            {
                return(null);
            }
            var element = node as Element;

            if (Components.Manager.IsComponent(element))
            {
                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();
                result.Add(new  ComponentRenderTask(element));
                response.ContentTask       = result;
                response.OmitTag           = true;
                response.StopNextEvaluator = true;

                if (options.RequireBindingInfo)
                {
                    string boundary     = Kooboo.Lib.Helper.StringHelper.GetUniqueBoundary();
                    var    startbinding = new BindingObjectRenderTask()
                    {
                        ObjectType = element.tagName, Boundary = boundary, NameOrId = element.id
                    };
                    List <IRenderTask> bindingstarts = new List <IRenderTask>();
                    bindingstarts.Add(startbinding);
                    response.BindingTask = bindingstarts;

                    var endbinding = new BindingObjectRenderTask()
                    {
                        ObjectType = element.tagName, IsEndBinding = true, Boundary = boundary, NameOrId = element.id
                    };

                    List <IRenderTask> bindingends = new List <IRenderTask>();
                    bindingends.Add(endbinding);
                    response.EndBindingTask = bindingends;
                }
                return(response);
            }

            return(null);
        }
Exemple #9
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Component))
            {
                return(null);
            }
            if (node.nodeType != enumNodeType.ELEMENT)
            {
                return(null);
            }
            var element = node as Element;

            if (Components.Manager.IsComponent(element))
            {
                var response = new EvaluatorResponse();
                var result   = new List <IRenderTask>();
                result.Add(new ComponentRenderTask(element));
                response.ContentTask       = result;
                response.OmitTag           = true;
                response.StopNextEvaluator = true;

                if (options.RequireBindingInfo)
                {
                    if (response.BindingTask == null)
                    {
                        response.BindingTask = new List <IRenderTask>();
                    }
                    var traceability = new ComponentTrace(element.id, element.tagName);
                    var bindingTask  = new BindingRenderTask(traceability, new Dictionary <string, string> {
                        { "scope", "true" }
                    });
                    response.BindingTask.Add(bindingTask);
                    if (response.EndBindingTask == null)
                    {
                        response.EndBindingTask = new List <IRenderTask>();
                    }
                    response.EndBindingTask.Add(bindingTask.BindingEndRenderTask);
                }
                return(response);
            }

            return(null);
        }
Exemple #10
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.SiteLayout))
            {
                return(null);
            }

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

            if (element.tagName == "layout" && (element.hasAttribute("id") || element.hasAttribute("name")))
            {
                var response = new EvaluatorResponse();
                var result   = new List <IRenderTask>();
                result.Add(new SiteLayoutRenderTask(element, options));
                response.ContentTask = result;
                response.OmitTag     = true;

                if (options.RequireBindingInfo)
                {
                    if (response.BindingTask == null)
                    {
                        response.BindingTask = new List <IRenderTask>();
                    }
                    var traceability = new ComponentTrace(element.id, element.tagName);
                    var bindingTask  = new BindingRenderTask(traceability, new Dictionary <string, string> {
                        { "scope", "true" }
                    });
                    response.BindingTask.Add(bindingTask);
                    if (response.EndBindingTask == null)
                    {
                        response.EndBindingTask = new List <IRenderTask>();
                    }
                    response.EndBindingTask.Add(bindingTask.BindingEndRenderTask);
                }
                return(response);
            }

            return(null);
        }
Exemple #11
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.OmitTag))
            {
                return(null);
            }

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

            bool shouldomit = false;

            foreach (var item in element.attributes)
            {
                if (item.name == "k-omitouter" || item.name == "k-omitoutertag")
                {
                    shouldomit = true;
                    break;
                }
            }

            if (shouldomit)
            {
                TagOmitRenderTask task = new TagOmitRenderTask(element, options);

                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();
                result.Add(task);
                response.ContentTask       = result;
                response.OmitTag           = true;
                response.StopNextEvaluator = true;
                return(response);
            }
            else
            {
                return(null);
            }
        }
Exemple #12
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Condition))
            {
                return(null);
            }

            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-condition" || item.name == "k-if" || item.name == "k-condition")
                {
                    attName = item.name;
                    break;
                }
            }
            if (!string.IsNullOrEmpty(attName))
            {
                string conditiontext = element.getAttribute(attName);
                if (string.IsNullOrEmpty(conditiontext))
                {
                    return(null);
                }
                element.removeAttribute(attName);
                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();
                result.Add(new ConditionRenderTask(element, conditiontext, options));
                response.ContentTask       = result;
                response.StopNextEvaluator = true;
                response.OmitTag           = true;
                return(response);
            }
            return(null);
        }
Exemple #13
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.PlaceHolder))
            {
                return(null);
            }

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

            //"tal-placeholder", "position", "placeholder"
            string PositionName = null;

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

            if (!string.IsNullOrEmpty(PositionName))
            {
                var response = new EvaluatorResponse();
                List <IRenderTask> result        = new List <IRenderTask>();
                string             PositionValue = element.getAttribute(PositionName);
                element.removeAttribute(PositionName);
                result.Add(new PlaceHolderRenderTask(PositionValue));
                response.ContentTask = result;
                return(response);
            }
            return(null);
        }
Exemple #14
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);

            if (!options.RequireBindingInfo)
            {
                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.RequireBindingInfo)
                {
                    string koobooid = element.getAttribute(SiteConstants.KoobooIdAttributeName);
                    BindingObjectRenderTask binding = new BindingObjectRenderTask()
                    {
                        ObjectType = "attribute", AttributeName = attributeName, BindingValue = attributeValue, KoobooId = koobooid
                    };
                    List <IRenderTask> bindings = new List <IRenderTask>();
                    bindings.Add(binding);
                    if (response.BindingTask == null)
                    {
                        response.BindingTask = bindings;
                    }
                    else
                    {
                        response.BindingTask.AddRange(bindings);
                    }
                }
            }

            if (response.AttributeTask == null || response.AttributeTask.Count() == 0)
            {
                return(null);
            }
            else
            {
                return(response);
            }
        }
Exemple #15
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);
        }
Exemple #16
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Repeater))
            {
                return(null);
            }

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

            string attName = null;

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

            if (string.IsNullOrEmpty(attName))
            {
                return(null);
            }
            string repeatitems = element.getAttribute(attName).Trim();

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

            //if (!options.RequireBindingInfo)
            // {
            element.removeAttribute(attName);
            //}

            bool repeatself = false;

            if (element.hasAttribute("repeat-self"))
            {
                repeatself = true;
                element.removeAttribute("repeat-self");
            }
            else if (element.hasAttribute("tal-repeat-self"))
            {
                repeatself = true;
                element.removeAttribute("tal-repeat-self");
            }
            else if (element.hasAttribute("k-repeat-self"))
            {
                repeatself = true;
                element.removeAttribute("k-repeat-self");
            }

            string datakey;
            string alias = string.Empty;

            // the repeat item can be with or without an alias. it can be like articles or "item articles";
            string[] items = repeatitems.Split(' ');
            if (items.Length == 1)
            {
                datakey = items[0];
            }
            else if (items.Length == 2)
            {
                datakey = items[1];
                alias   = items[0];
            }
            else
            {
                return(null);
            }

            RepeatRenderTask task = new RepeatRenderTask(datakey, alias, repeatself, element, options);

            var response = new EvaluatorResponse();
            List <IRenderTask> result = new List <IRenderTask>();

            result.Add(task);
            response.ContentTask       = result;
            response.OmitTag           = true;
            response.StopNextEvaluator = true;

            return(response);
        }
Exemple #17
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;

            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);
                if (!options.RequireBindingInfo)
                {
                    element.removeAttribute(attName);
                }
            }

            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))
            {
                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();
                result.Add(new ContentRenderTask(" href=\""));
                result.Add(new UrlRenderTask(url));
                result.Add(new ContentRenderTask("\""));
                response.AttributeTask = result;

                if (options.RequireBindingInfo)
                {
                    string attributeName            = string.IsNullOrEmpty(attName) ? "href" : attName;
                    string koobooid                 = element.getAttribute(SiteConstants.KoobooIdAttributeName);
                    BindingObjectRenderTask binding = new BindingObjectRenderTask()
                    {
                        ObjectType = "Url", AttributeName = attributeName, BindingValue = url, KoobooId = koobooid
                    };
                    List <IRenderTask> bindings = new List <IRenderTask>();
                    bindings.Add(binding);
                    response.BindingTask = bindings;
                }

                element.removeAttribute("href");

                return(response);
            }

            return(null);
        }
Exemple #18
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.Content))
            {
                return(null);
            }

            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-content" || item.name == "k-content" || item.name == "tal-replace" || item.name == "k-replace")
                {
                    attName = item.name;
                    break;
                }
            }
            if (!string.IsNullOrEmpty(attName))
            {
                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();
                string             value  = element.getAttribute(attName);
                element.removeAttribute(attName);
                result.Add(new ValueRenderTask(value));
                response.ContentTask = result;
                if (attName == "tal-replace" || attName == "k-replace")
                {
                    response.OmitTag = true;
                }

                if (options.RequireBindingInfo)
                {
                    string koobooid = element.getAttribute(SiteConstants.KoobooIdAttributeName);
                    if (!string.IsNullOrEmpty(koobooid))
                    {
                        BindingContentRenderTask binding = new BindingContentRenderTask()
                        {
                            ObjectType = "content", BindingValue = value, KoobooId = koobooid
                        };
                        List <IRenderTask> bindings = new List <IRenderTask>();
                        bindings.Add(binding);
                        response.BindingTask = bindings;
                    }
                    else
                    {
                        string boundary = Kooboo.Lib.Helper.StringHelper.GetUniqueBoundary();
                        BindingContentRenderTask binding = new BindingContentRenderTask()
                        {
                            ObjectType = "content", BindingValue = value, Boundary = boundary, KoobooId = koobooid
                        };
                        List <IRenderTask> bindings = new List <IRenderTask>();
                        bindings.Add(binding);
                        response.BindingTask = bindings;

                        BindingContentRenderTask bindingend = new BindingContentRenderTask()
                        {
                            ObjectType = "content", BindingValue = value, Boundary = boundary, KoobooId = koobooid, IsEndBinding = true
                        };
                        List <IRenderTask> bindingsend = new List <IRenderTask>();
                        bindingsend.Add(bindingend);
                        response.EndBindingTask = bindingsend;
                    }
                }

                return(response);
            }
            return(null);
        }