示例#1
0
        private static bool TryGetContextItem(IParseContext context, out PhotoInfo photoInfo, out int itemIndex)
        {
            photoInfo = context.Get <PhotoInfo>(ElementName);
            itemIndex = context.Get <int>(ElementName + "ItemIndex");

            return(photoInfo != null && itemIndex > 0);
        }
示例#2
0
 public static void SetContextItem(IParseContext context, PhotoInfo photoInfo, int itemIndex)
 {
     context.Set(ElementName, photoInfo);
     context.Set(ElementName + "ItemIndex", itemIndex);
 }
示例#3
0
        private static string ParseImpl(IParseContext context, PhotoInfo photoInfo, int itemIndex, string leftText, string rightText, string formatString, int startIndex, int length, int wordNum, string ellipsis, string replace, string to, bool isClearTags, bool isReturnToBr, bool isLower, bool isUpper, string type)
        {
            var parsedContent = string.Empty;

            if (!string.IsNullOrEmpty(type))
            {
                if (!string.IsNullOrEmpty(formatString))
                {
                    formatString = formatString.Trim();
                    if (!formatString.StartsWith("{0"))
                    {
                        formatString = "{0:" + formatString;
                    }
                    if (!formatString.EndsWith("}"))
                    {
                        formatString = formatString + "}";
                    }
                }
                else
                {
                    formatString = "{0}";
                }

                if (string.IsNullOrEmpty(type) || Utils.EqualsIgnoreCase(type, "imageUrl"))
                {
                    type = TypeLargeUrl;
                }

                if (Utils.StartsWithIgnoreCase(type, TypeItemIndex))
                {
                    parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, itemIndex) : itemIndex.ToString();
                }
                else if (Utils.StartsWithIgnoreCase(type, TypeId))
                {
                    parsedContent = !string.IsNullOrEmpty(formatString) ? string.Format(formatString, photoInfo.Id) : photoInfo.Id.ToString();
                }
                else if (Utils.StartsWithIgnoreCase(type, TypeSmallUrl))
                {
                    parsedContent = GetImageHtml(photoInfo.SmallUrl, context.StlAttributes, context.IsStlElement);
                }
                else if (Utils.StartsWithIgnoreCase(type, TypeMiddleUrl))
                {
                    parsedContent = GetImageHtml(photoInfo.MiddleUrl, context.StlAttributes, context.IsStlElement);
                }
                else if (Utils.StartsWithIgnoreCase(type, TypeLargeUrl))
                {
                    parsedContent = GetImageHtml(photoInfo.LargeUrl, context.StlAttributes, context.IsStlElement);
                }
                else if (Utils.StartsWithIgnoreCase(type, TypeDescription) || Utils.StartsWithIgnoreCase(type, "content"))
                {
                    parsedContent = Utils.ReplaceNewlineToBr(photoInfo.Description);
                }
            }

            if (!string.IsNullOrEmpty(parsedContent))
            {
                parsedContent = Utils.ParseString(parsedContent, replace, to, startIndex, length, wordNum, ellipsis, isClearTags, isReturnToBr, isLower, isUpper, formatString);

                if (!string.IsNullOrEmpty(parsedContent))
                {
                    parsedContent = leftText + parsedContent + rightText;
                }
            }

            return(parsedContent);
        }