Example #1
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (node.nodeType != enumNodeType.COMMENT)
            {
                return(null);
            }

            /// NOTO: There are two place for evaluating comment command.
            if (Commands.CommandManager.IsCommand(node as Comment))
            {
                var response = new EvaluatorResponse();
                List <IRenderTask> result = new List <IRenderTask>();

                Guid OwnerObjectId = options.OwnerObjectId;

                var command = Commands.CommandParser.ParseCommand(node as Comment);

                if (command.Name.ToLower() == "layout")
                {
                    if ((options.IgnoreEvaluators & EnumEvaluator.LayoutCommand) == EnumEvaluator.LayoutCommand)
                    {
                        return(null);
                    }
                    var task = new CommandRenderTask(node as Comment, options);
                    task.ClearBefore = true;
                    result.Add(task);
                    response.AppendTask = result;
                }
                else
                {
                    var task = new CommandRenderTask(node as Comment, options);
                    result.Add(task);
                    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(command.Name, "command");
                    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);
        }
Example #2
0
        public EvaluatorResponse Evaluate(Node node, EvaluatorOption options)
        {
            if (options.IgnoreEvaluators.HasFlag(EnumEvaluator.For))
            {
                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-for" || lower == "k-for")
                {
                    attName = item.name;
                    break;
                }
            }

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

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

            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");
            }

            var para = PrasePara(repeatitems);

            if (para == null)
            {
                return(null);
            }

            ForRenderTask task = new ForRenderTask(para.DataKey, para.LowBound, para.HighBound, repeatself, element, options);

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

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

            if (options.RequireBindingInfo)
            {
                if (response.BindingTask == null)
                {
                    response.BindingTask = new List <IRenderTask>();
                }
                var traceability = new RepeatTrace();
                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);
        }