Example #1
0
 public static void AddAppAdminScripts(this HtmlHelper html)
 {
     foreach (var script in MrCMSApplication.GetAll <IAppScriptList>().SelectMany(appScriptList => appScriptList.AdminScripts))
     {
         html.IncludeScript(script);
     }
 }
        private static string GetPageScript(HtmlHelper htmlHelper, string pageSuffix = "")
        {
            var view = htmlHelper.ViewContext.View as WebFormView;
            Debug.Assert(view != null);
            Debug.Assert(view.ViewPath.StartsWith("~/Views"));
            Debug.Assert(view.ViewPath.EndsWith(".aspx"));

            var viewScriptPath = Regex.Replace(view.ViewPath.Replace("~/", ""), @"\.aspx$", pageSuffix + ".js");
            return htmlHelper.IncludeScript(new[] { viewScriptPath });
        }
        /// <summary>
        /// Include script files to page
        /// </summary>
        /// <param name="includeScripts">Script files to include</param>
        /// <returns></returns>
        public ResourceScriptManager Include(params string[] includeScripts)
        {
            if (includeScripts != null)
            {
                foreach (var includeScript in includeScripts)
                {
                    HtmlHelper.IncludeScript(includeScript);
                }
            }

            return(this);
        }
        public void IncludeScriptsReturnsScriptsWithFullPathIfPathHasTrailingSlash()
        {
            var httpContext = MockRepository.GenerateStub<HttpContextBase>();
            var viewContext = MockRepository.GenerateStub<ViewContext>();
            var httpRequest = MockRepository.GenerateStub<HttpRequestBase>();

            httpContext.Stub(c => c.Request).Return(httpRequest).Repeat.Any();

            httpRequest.Stub(c => c.ApplicationPath).Return("http://localhost/TestComet/");

            viewContext.HttpContext = httpContext;
            viewContext.RequestContext = new RequestContext(httpContext, new RouteData());

            var html = new HtmlHelper(viewContext, new ViewPage());
            Assert.AreEqual(@"<script src=""http://localhost/TestComet/Scripts/Cometd.js"" type=""text/javascript""></script>" +
                            @"<script src=""http://localhost/TestComet/Scripts/OtherScript.js"" type=""text/javascript""></script>",
                            html.IncludeScript("Cometd.js", "OtherScript.js"));
        }