Ejemplo n.º 1
0
 public IHtmlString Field(string fieldAlias, string valueAlias = "",
                          string altFieldAlias                 = "", string altValueAlias      = "", string altText              = "", string insertBefore = "", string insertAfter = "",
                          bool recursive                       = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
                          RebelRenderItemCaseType casing       = RebelRenderItemCaseType.Unchanged,
                          RebelRenderItemEncodingType encoding = RebelRenderItemEncodingType.Unchanged,
                          string formatString                  = "")
 {
     return(Field(_currentPage, fieldAlias, valueAlias, altFieldAlias, altValueAlias,
                  altText, insertBefore, insertAfter, recursive, convertLineBreaks, removeParagraphTags,
                  casing, encoding, formatString));
 }
Ejemplo n.º 2
0
        public IHtmlString RenderField(IRoutableRequestContext routableRequestContext, ControllerContext controllerContext, Content item,
            string fieldAlias = "", string valueAlias = "", string altFieldAlias = "", string altValueAlias = "", string altText = "", string insertBefore = "", string insertAfter = "",
            bool recursive = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
            RebelRenderItemCaseType casing = RebelRenderItemCaseType.Unchanged,
            RebelRenderItemEncodingType encoding = RebelRenderItemEncodingType.Unchanged,
            string formatString = "")
        {
            var sb = new StringBuilder();

            var valObj = GetFieldValue(item, fieldAlias, valueAlias, recursive);

            if ((valObj == null || valObj.ToString().IsNullOrWhiteSpace()) && !altFieldAlias.IsNullOrWhiteSpace())
            {
                valObj = GetFieldValue(item, altFieldAlias, altValueAlias, recursive);
            }

            if ((valObj == null || valObj.ToString().IsNullOrWhiteSpace()) && !altText.IsNullOrWhiteSpace())
            {
                valObj = altText;
            }

            if(!formatString.IsNullOrWhiteSpace())
                formatString = "{0:" + formatString.Replace("\\", "\\\\").Replace("\"", "\\\"") + "}";
            else
                formatString = "{0}";

            var val = string.Format(formatString, valObj);

            if(!val.IsNullOrWhiteSpace())
            {
                switch (casing)
                {
                    case RebelRenderItemCaseType.Upper:
                        val = val.ToUpper();
                        break;
                    case RebelRenderItemCaseType.Lower:
                        val = val.ToLower();
                        break;
                    case RebelRenderItemCaseType.Title:
                        val = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(val);
                        break;
                    default:
                        break;
                }

                switch (encoding)
                {
                    case RebelRenderItemEncodingType.Url:
                        val = HttpUtility.UrlEncode(val);
                        break;
                    case RebelRenderItemEncodingType.Html:
                        val = HttpUtility.HtmlEncode(val);
                        break;
                    default:
                        break;
                }

                if (convertLineBreaks)
                {
                    val = val.Replace(Environment.NewLine, "<br />");
                }

                if (removeParagraphTags)
                {
                    val = val.Trim().Trim("<p>").Trim("</p>");
                }

                sb.Append(HttpUtility.HtmlDecode(insertBefore));
                sb.Append(val);
                sb.Append(HttpUtility.HtmlDecode(insertAfter));
            }

            //now we need to parse the macro syntax out and replace it with the rendered macro content

            var macroRenderer = new MacroRenderer(routableRequestContext.RegisteredComponents, routableRequestContext);
            var macroParser = new MacroSyntaxParser();
            IEnumerable<MacroParserResult> parseResults;
            var parsed = macroParser.Parse(sb.ToString(),
                                           (macroAlias, macroParams)
                                           => macroRenderer.RenderMacroAsString(macroAlias,
                                                                                macroParams,
                                                                                controllerContext, false,
                                                                                () => item), out parseResults);

            //now we need to parse any internal links and replace with actual URLs
            var linkParse = new LinkSyntaxParser();
            parsed = linkParse.Parse(parsed, x => routableRequestContext.RoutingEngine.GetUrl(x));

            return new MvcHtmlString(parsed);
        }
Ejemplo n.º 3
0
        public IHtmlString RenderField(IRoutableRequestContext routableRequestContext, ControllerContext controllerContext, Content item,
                                       string fieldAlias = "", string valueAlias         = "", string altFieldAlias        = "", string altValueAlias = "", string altText = "", string insertBefore = "", string insertAfter = "",
                                       bool recursive    = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
                                       RebelRenderItemCaseType casing       = RebelRenderItemCaseType.Unchanged,
                                       RebelRenderItemEncodingType encoding = RebelRenderItemEncodingType.Unchanged,
                                       string formatString = "")
        {
            var sb = new StringBuilder();

            var valObj = GetFieldValue(item, fieldAlias, valueAlias, recursive);

            if ((valObj == null || valObj.ToString().IsNullOrWhiteSpace()) && !altFieldAlias.IsNullOrWhiteSpace())
            {
                valObj = GetFieldValue(item, altFieldAlias, altValueAlias, recursive);
            }

            if ((valObj == null || valObj.ToString().IsNullOrWhiteSpace()) && !altText.IsNullOrWhiteSpace())
            {
                valObj = altText;
            }

            if (!formatString.IsNullOrWhiteSpace())
            {
                formatString = "{0:" + formatString.Replace("\\", "\\\\").Replace("\"", "\\\"") + "}";
            }
            else
            {
                formatString = "{0}";
            }

            var val = string.Format(formatString, valObj);

            if (!val.IsNullOrWhiteSpace())
            {
                switch (casing)
                {
                case RebelRenderItemCaseType.Upper:
                    val = val.ToUpper();
                    break;

                case RebelRenderItemCaseType.Lower:
                    val = val.ToLower();
                    break;

                case RebelRenderItemCaseType.Title:
                    val = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(val);
                    break;

                default:
                    break;
                }

                switch (encoding)
                {
                case RebelRenderItemEncodingType.Url:
                    val = HttpUtility.UrlEncode(val);
                    break;

                case RebelRenderItemEncodingType.Html:
                    val = HttpUtility.HtmlEncode(val);
                    break;

                default:
                    break;
                }

                if (convertLineBreaks)
                {
                    val = val.Replace(Environment.NewLine, "<br />");
                }

                if (removeParagraphTags)
                {
                    val = val.Trim().Trim("<p>").Trim("</p>");
                }

                sb.Append(HttpUtility.HtmlDecode(insertBefore));
                sb.Append(val);
                sb.Append(HttpUtility.HtmlDecode(insertAfter));
            }

            //now we need to parse the macro syntax out and replace it with the rendered macro content

            var macroRenderer = new MacroRenderer(routableRequestContext.RegisteredComponents, routableRequestContext);
            var macroParser   = new MacroSyntaxParser();
            IEnumerable <MacroParserResult> parseResults;
            var parsed = macroParser.Parse(sb.ToString(),
                                           (macroAlias, macroParams)
                                           => macroRenderer.RenderMacroAsString(macroAlias,
                                                                                macroParams,
                                                                                controllerContext, false,
                                                                                () => item), out parseResults);

            //now we need to parse any internal links and replace with actual URLs
            var linkParse = new LinkSyntaxParser();

            parsed = linkParse.Parse(parsed, x => routableRequestContext.RoutingEngine.GetUrl(x));

            return(new MvcHtmlString(parsed));
        }
Ejemplo n.º 4
0
 public IHtmlString Field(Content currentPage, string fieldAlias, string valueAlias = "",
     string altFieldAlias = "", string altValueAlias = "", string altText = "", string insertBefore = "", string insertAfter = "",
     bool recursive = false, bool convertLineBreaks = false, bool removeParagraphTags = false,
     RebelRenderItemCaseType casing = RebelRenderItemCaseType.Unchanged,
     RebelRenderItemEncodingType encoding = RebelRenderItemEncodingType.Unchanged,
     string formatString = "")
 {
     return new FieldRenderer()
         .RenderField(_requestContext, _controllerContext, currentPage, fieldAlias, valueAlias, altFieldAlias, altValueAlias,
         altText, insertBefore, insertAfter, recursive, convertLineBreaks, removeParagraphTags,
         casing, encoding, formatString);
 }