Example #1
0
File: Form.cs Project: xhute/Kooboo
        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);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
            }
        }
Example #6
0
File: Url.cs Project: xhute/Kooboo
        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);
        }