Esempio n. 1
0
        public static string LinkToTag(Context context, object input, Tag tag)
        {
            var field = tag.Field;
            var tagName = tag.Label;
            var val = tag.Value;
            var count = tag.Count;

            var relativeUri = HttpContext.Current.Request.Url;
            var url = UpdateWithTags(context, relativeUri, String.Format("{0}_{1}", field, val));

            return String.Format(
                "<a title=\"Show products matching tag {1}\" href=\"{0}\">{1}{2}</a>",
                url,
                tagName,
                count == 0 ? "" : String.Format(" ({0})", count));
        }
Esempio n. 2
0
        protected override void Parse(List <string> tokens)
        {
            NodeList = NodeList ?? new List <object>();
            NodeList.Clear();

            string token;

            while ((token = tokens.Shift()) != null)
            {
                Match isTagMatch = IsTag.Match(token);
                if (isTagMatch.Success)
                {
                    Match fullTokenMatch = FullToken.Match(token);
                    if (fullTokenMatch.Success)
                    {
                        // If we found the proper block delimitor just end parsing here and let the outer block
                        // proceed
                        if (BlockDelimiter == fullTokenMatch.Groups[1].Value)
                        {
                            EndTag();
                            return;
                        }

                        // Fetch the tag from registered blocks
                        Type tagType;
                        if ((tagType = Template.GetTagType(fullTokenMatch.Groups[1].Value)) != null)
                        {
                            Tag tag = (Tag)Activator.CreateInstance(tagType);
                            tag.Initialize(fullTokenMatch.Groups[1].Value, fullTokenMatch.Groups[2].Value, tokens);
                            NodeList.Add(tag);

                            // If the tag has some rules (eg: it must occur once) then check for them
                            tag.AssertTagRulesViolation(NodeList);
                        }
                        else
                        {
                            // This tag is not registered with the system
                            // pass it to the current block for special handling or error reporting
                            UnknownTag(fullTokenMatch.Groups[1].Value, fullTokenMatch.Groups[2].Value, tokens);
                        }
                    }
                    else
                    {
                        throw new SyntaxException(Liquid.ResourceManager.GetString("BlockTagNotTerminatedException"), token, Liquid.TagEnd);
                    }
                }
                else if (IsVariable.Match(token).Success)
                {
                    NodeList.Add(CreateVariable(token));
                }
                else if (token == string.Empty)
                {
                    // Pass
                }
                else
                {
                    NodeList.Add(token);
                }
            }

            // Make sure that its ok to end parsing in the current block.
            // Effectively this method will throw an exception unless the current block is
            // of type Document
            AssertMissingDelimitation();
        }