Пример #1
0
        public void AddMasterPageDirectives_CustomString_AppendsMasterDirective()
        {
            //Arrange
            var layoutTemplateHtmlProcessor = new MasterPageBuilder();
            var htmlString = "Some html string";

            //Act
            htmlString = layoutTemplateHtmlProcessor.AddMasterPageDirectives(htmlString);

            //Assert
            Assert.IsTrue(htmlString.StartsWith(MasterPageBuilderTests.masterPageDirective), "Master page doesn't start with" + MasterPageBuilderTests.masterPageDirective);
        }
Пример #2
0
        /// <summary>
        /// Gets the layout template.
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="model">The model.</param>
        /// <param name="isPartial">if set to <c>true</c> requested view is partial.</param>
        /// <returns></returns>
        public virtual string GetLayoutTemplate(string templateName, object model = null, bool isPartial = false)
        {
            var genericController = this.CreateController();
            var layoutHtmlString  = this.RenderViewToString(genericController.ControllerContext, templateName, model, isPartial);

            if (!layoutHtmlString.IsNullOrEmpty())
            {
                var htmlProcessor = new MasterPageBuilder();
                layoutHtmlString = htmlProcessor.ProcessLayoutString(layoutHtmlString);
                layoutHtmlString = htmlProcessor.AddMasterPageDirectives(layoutHtmlString);
            }

            return(layoutHtmlString);
        }
Пример #3
0
        /// <summary>
        /// Gets the layout template.
        /// </summary>
        /// <param name="templateName">The name of the layout template to render.</param>
        /// <param name="placeholdersOnly">When true the method returns a master page containing only content placeholders.</param>
        /// <returns></returns>
        public virtual string GetLayoutTemplate(string templateName, bool placeholdersOnly = false)
        {
            var genericController = this.CreateController();
            var layoutHtmlString  = this.RenderViewToString(genericController.ControllerContext, templateName, placeholdersOnly);

            if (!layoutHtmlString.IsNullOrEmpty() && !placeholdersOnly)
            {
                var htmlProcessor = new MasterPageBuilder();
                layoutHtmlString = htmlProcessor.ProcessLayoutString(layoutHtmlString);
                layoutHtmlString = htmlProcessor.AddMasterPageDirectives(layoutHtmlString);
            }

            return(layoutHtmlString);
        }
Пример #4
0
        /// <summary>
        /// Gets the layout template.
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="model">The model.</param>
        /// <param name="partial">if set to <c>true</c> requested view is partial.</param>
        /// <returns></returns>
        public virtual string GetLayoutTemplate(string templateName, object model = null, bool partial = false)
        {
            var genericController = this.CreateController();
            var layoutHtmlString = this.RenderViewToString(genericController.ControllerContext, templateName, model, partial);

            if (!layoutHtmlString.IsNullOrEmpty())
            {
                var htmlProcessor = new MasterPageBuilder();
                layoutHtmlString = htmlProcessor.ProcessLayoutString(layoutHtmlString);
                layoutHtmlString = htmlProcessor.AddMasterPageDirectives(layoutHtmlString);
            }

            return layoutHtmlString;
        }
Пример #5
0
        /// <summary>
        /// Gets the layout template.
        /// </summary>
        /// <param name="templateName">The name of the layout template to render.</param>
        /// <param name="placeholdersOnly">When true the method returns a master page containing only content placeholders.</param>
        /// <returns></returns>
        public virtual string GetLayoutTemplate(string templateName, bool placeholdersOnly = false)
        {
            var genericController = this.CreateController();
            var layoutHtmlString = this.RenderViewToString(genericController.ControllerContext, templateName, placeholdersOnly);

            if (!layoutHtmlString.IsNullOrEmpty() && !placeholdersOnly)
            {
                var htmlProcessor = new MasterPageBuilder();
                layoutHtmlString = htmlProcessor.ProcessLayoutString(layoutHtmlString);
                layoutHtmlString = htmlProcessor.AddMasterPageDirectives(layoutHtmlString);
            }

            return layoutHtmlString;
        }