public bool Transform(ContentItem item)
        {
            string text = item[Name] as string;
            if(text != null)
            {
                string detailName = Name + "_Tokens";
                int i = 0;
                var p = new Parser(new TemplateAnalyzer());
                foreach (var c in p.Parse(text).Where(c => c.Command != Parser.TextCommand))
                {
                    var dc = item.GetDetailCollection(detailName, true);
                    var cd = ContentDetail.Multi(detailName, stringValue: c.Tokens.Select(t => t.Fragment).StringJoin(), integerValue: c.Tokens.First().Index);
                    cd.EnclosingItem = item;
                    cd.EnclosingCollection = dc;

                    if (dc.Details.Count > i)
                        dc.Details[i] = cd;
                    else
                        dc.Details.Add(cd);
                    i++;
                }
                if (i > 0)
                {
                    var dc = item.GetDetailCollection(detailName, true);
                    for (int j = dc.Details.Count - 1; j >= i; j--)
                    {
                        dc.Details.RemoveAt(j);
                    }
                    return true;
                }
            }
            return false;
        }
Exemple #2
0
		public override Component GetComponent(Parser parser, System.Collections.Generic.IList<Token> tokens, int index)
		{
			if (tokens[index].Type == TokenType.Comment)
				return new Component { Command = Name, Tokens = new List<Token> { tokens[index] } };

			if (tokens[index].Fragment.StartsWith("<!--") && tokens[index].Fragment.EndsWith("-->"))
				return new Component { Command = Name, Tokens = new List<Token> { tokens[index] } };

			return null;
		}
 public override Component GetComponent(Parser parser, IList<Token> tokens, int index)
 {
     var token = tokens[index];
     if (token.Type == TokenType.Element || token.Type == TokenType.EndElement)
         return new Component
         {
             Argument = token.Fragment,
             Command = "HtmlElement",
             Tokens = new List<Token> { token },
             Components = Component.None
         };
     return null;
 }
Exemple #4
0
 public override Component GetComponent(Parser parser, IList<Token> tokens, int index)
 {
     var token = tokens[index];
     if (token.Type == TokenType.Symbol && token.Fragment.StartsWith("~~~"))
         return new Component
         {
             Command = "UserInfo",
      					Argument = token.Fragment,
             Tokens = new List<Token> { token },
             Components = Component.None
         };
     return null;
 }
Exemple #5
0
 public override Component GetComponent(Parser parser, IList<Token> tokens, int index)
 {
     if (index == 0)
         return null;
     if (index == tokens.Count - 1)
         return null;
     var token = tokens[index];
     if (token.Type == TokenType.NewLine)
         return new Component
         {
             Command = "NewLine",
             Argument = token.Fragment,
             Tokens = new List<Token> { token },
             Components = Component.None
         };
     return null;
 }
Exemple #6
0
		private Component StartAnalyzing(Parser parser, IList<Token> tokens, int startIndex)
		{
			for (int i = startIndex + 1; i < tokens.Count; i++)
			{
				if (IsStopToken(tokens, startIndex, ref i))
				{
					if (!AllowEmpty && i == startIndex + 1)
						return null;
					
					var componentTokens = tokens.Skip(startIndex).Take(i - startIndex + 1).ToList();
					var subComponents = GetSubComponents(parser, componentTokens);
					return CreateComponent(componentTokens, subComponents);
				}

				if (!IsValidInnerToken(tokens, i))
					return null;
			}
			return null;
		}
Exemple #7
0
		public override Component GetComponent(Parser parser, IList<Token> tokens, int index)
		{
			var token = tokens[index];
			if (IsStartToken(token))
			{
				if (!ParseContents || token.Fragment.EndsWith("/>"))
					return new Component { Command = Name, Tokens = new List<Token> { token } };

				int depth = 1;
				for (int i = index + 1; i < tokens.Count; i++)
				{
					var innerToken = tokens[i];
					if (XmlContents)
					{
						if (innerToken.Type == TokenType.Element && !innerToken.Fragment.EndsWith("/>"))
						{
							depth++;
						}
						else if (innerToken.Type == TokenType.EndElement)
						{
							depth--;
						}
					}
					else if (IsStopToken(innerToken))
					{
						depth--;
					}
					if (depth == 0)
					{
						return new Component { Command = Name, Tokens = tokens.Skip(index).Take(i - index + 1).ToList() };
					}
				}
			}
			else if (!ParseContents && IsStopToken(token))
			{
				return new Component { Command = Name + "-end", Tokens = new List<Token> { token } };
			}
			return null;
		}
Exemple #8
0
		public override Component GetComponent(Parser parser, IList<Token> tokens, int startIndex)
		{
			if (IsStartToken(tokens, ref startIndex))
				return StartAnalyzing(parser, tokens, startIndex);
			return null;
		}
Exemple #9
0
		protected virtual IEnumerable<Component> GetSubComponents(Parser parser, IList<Token> innerTokens)
		{
			if (ParseSubComponents)
				return parser.Parse(innerTokens.Skip(1).Take(innerTokens.Count - 2));
			
			return Component.None;
		}
 protected override IEnumerable<Component> GetSubComponents(Parser parser, IList<Token> innerTokens)
 {
     return parser.Parse(innerTokens.Skip(2).Where(c => c.Type != TokenType.NewLine));
 }