public static String Js(String files, Boolean debug) { String name = HelperService.CalculateMD5Hash(files); String path = @"/cache/script/js/"; String FilePath = path + name + ".js"; if (!HelperService.DirExists(path)) { System.IO.Directory.CreateDirectory(path); } JavaScriptBundle js = new JavaScriptBundle(); foreach (string fl in files.Split(',')) { if (File.Exists(HttpContext.Current.Server.MapPath(fl))) { js.Add(fl); } } if (debug == true) { return(js.ForceRelease().ForceDebug().Render(FilePath)); } else { return(js.ForceRelease().Render(FilePath)); } }
public void WithPreprocessor_Uses_Instance_Preprocessors() { var scriptPreprocessor = new StubScriptPreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); JavaScriptBundle javaScriptBundle = javaScriptBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = javaScriptBundle .WithPreprocessor(scriptPreprocessor) .WithPreprocessor(globalPreprocessor) .Add("~/js/test.script.global") .Render("~/js/output.js"); string contents = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")]; Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=hash\"></script>", tag); Assert.AreEqual("scripty;\n", contents); Assert.AreEqual("globey", scriptPreprocessor.CalledWith); Assert.AreEqual("start", globalPreprocessor.CalledWith); Assert.IsEmpty(Configuration.Instance.Preprocessors.Where(x => !(x is NullPreprocessor))); }
public void WithPreprocessor_Uses_Instance_Preprocessors() { var scriptPreprocessor = new StubScriptPreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); JavaScriptBundle javaScriptBundle = javaScriptBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = javaScriptBundle .WithPreprocessor(scriptPreprocessor) .WithPreprocessor(globalPreprocessor) .Add("~/js/test.script.fake.global.bogus") .Render("~/js/output.js"); string contents = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")]; Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=1CAFA2D8FF256D13A3BBBFB4770AC743\"></script>", tag); Assert.AreEqual("scripty;", contents); Assert.AreEqual("globey", scriptPreprocessor.CalledWith); Assert.AreEqual("start", globalPreprocessor.CalledWith); Assert.IsEmpty(Bundle.Preprocessors); }
// // GET: /ClearCaches/ public ActionResult Index() { CssBundle.Clear(); JavaScriptBundle.Clear(); return(RedirectToAction("Index", "Home")); }
public void Js_Skips_Extensions_With_No_Preprocessors() { var scriptPreprocessor = new StubScriptPreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); using (new ScriptPreprocessorScope <StubScriptPreprocessor>(scriptPreprocessor)) using (new GlobalPreprocessorScope <StubGlobalPreprocessor>(globalPreprocessor)) { JavaScriptBundle javaScriptBundle = javaScriptBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = javaScriptBundle .Add("~/js/test.script.fake.global.bogus") .Render("~/js/output.js"); string contents = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")]; Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=A87E7F7EA72FD18FC3E75FACD850E2EB\"></script>", tag); Assert.AreEqual("scripty", contents); Assert.AreEqual("globey", scriptPreprocessor.CalledWith); Assert.AreEqual("start", globalPreprocessor.CalledWith); } }
public void Js_Stops_At_First_Extension_With_No_Defined_Preprocessor() { var scriptPreprocessor = new StubScriptPreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); using (new ScriptPreprocessorScope <StubScriptPreprocessor>(scriptPreprocessor)) using (new GlobalPreprocessorScope <StubGlobalPreprocessor>(globalPreprocessor)) { JavaScriptBundle javaScriptBundle = javaScriptBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = javaScriptBundle .Add("~/js/test.script.fake.global.bogus") .Render("~/js/output.js"); string contents = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")]; Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=hash\"></script>", tag); Assert.AreEqual("start;\n", contents); Assert.Null(scriptPreprocessor.CalledWith); Assert.Null(globalPreprocessor.CalledWith); } }
public void Js_Style_Then_Global() { var scriptPreprocessor = new StubScriptPreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); using (new ScriptPreprocessorScope <StubScriptPreprocessor>(scriptPreprocessor)) using (new GlobalPreprocessorScope <StubGlobalPreprocessor>(globalPreprocessor)) { JavaScriptBundle javaScriptBundle = javaScriptBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = javaScriptBundle .Add("~/js/test.global.script") .Render("~/js/output.js"); string contents = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")]; Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=6816A2FDB0EE7941EE20E53D23779FC7\"></script>", tag); Assert.AreEqual("globey", contents); Assert.AreEqual("start", scriptPreprocessor.CalledWith); Assert.AreEqual("scripty", globalPreprocessor.CalledWith); } }
public void CanMarkJavaScriptBundleAsPackageable() { IJavaScriptBundle jsBundle = new JavaScriptBundle(mockDebugStatusReader, mockFileWriterFactory, jsMockFileReaderFactory); string tag = jsBundle .Add("/js/test.js") .AsPackageable() .Render("/js/render_differently_if_packaged_#.js"); }
public void Setup() { var nonDebugStatusReader = new StubDebugStatusReader(false); var debugStatusReader = new StubDebugStatusReader(true); currentDirectoryWrapper = new StubCurrentDirectoryWrapper(); stubBundleCache = new ApplicationCache(); var retryableFileOpener = new RetryableFileOpener(); hasher = new Hasher(retryableFileOpener); //fileReaderFactory.SetContents(javaScript); javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader, fileWriterFactory, fileReaderFactory, currentDirectoryWrapper, hasher, stubBundleCache); javaScriptBundle2 = new JavaScriptBundle(nonDebugStatusReader, fileWriterFactory, fileReaderFactory, currentDirectoryWrapper, hasher, stubBundleCache); debugJavaScriptBundle = new JavaScriptBundle(debugStatusReader, fileWriterFactory, fileReaderFactory, currentDirectoryWrapper, hasher, stubBundleCache); debugJavaScriptBundle2 = new JavaScriptBundle(debugStatusReader, fileWriterFactory, fileReaderFactory, currentDirectoryWrapper, hasher, stubBundleCache); outputFileNumber += 1; currentOutputFile = outputFileRoot + outputFileNumber + ".js"; }
public static String Js(string files) { String name = CalculateMD5Hash(files); String path = @"/cache/script/js/"; String FilePath = path + name + ".js"; if (!HelperService.DirExists(path)) { System.IO.Directory.CreateDirectory(path); } JavaScriptBundle js = new JavaScriptBundle(); foreach (string fl in files.Split(',')) { js.Add(fl); } return(js.ForceRelease().Render(FilePath)); }
public void Setup() { var nonDebugStatusReader = new StubDebugStatusReader(false); var debugStatusReader = new StubDebugStatusReader(true); fileWriterFactory = new StubFileWriterFactory(); fileReaderFactory = new StubFileReaderFactory(); currentDirectoryWrapper = new StubCurrentDirectoryWrapper(); stubBundleCache = new StubBundleCache(); var retryableFileOpener = new RetryableFileOpener(); hasher = new Hasher(retryableFileOpener); fileReaderFactory.SetContents(javaScript); javaScriptBundle = new JavaScriptBundle(nonDebugStatusReader, fileWriterFactory, fileReaderFactory, currentDirectoryWrapper, hasher, stubBundleCache); javaScriptBundle2 = new JavaScriptBundle(nonDebugStatusReader, fileWriterFactory, fileReaderFactory, currentDirectoryWrapper, hasher, stubBundleCache); debugJavaScriptBundle = new JavaScriptBundle(debugStatusReader, fileWriterFactory, fileReaderFactory, currentDirectoryWrapper, hasher, stubBundleCache); debugJavaScriptBundle2 = new JavaScriptBundle(debugStatusReader, fileWriterFactory, fileReaderFactory, currentDirectoryWrapper, hasher, stubBundleCache); }
/// <summary> /// Renders current <see cref="JavaScriptBundle" /> to given file /// </summary> /// <param name="javaScriptBundle">Current javascript bundle</param> /// <param name="renderTo">File to render to</param> /// <returns>Current bundle</returns> public static IHtmlString MvcRender(this JavaScriptBundle javaScriptBundle, string renderTo) { return(new NonEncodedHtmlString(javaScriptBundle.Render(renderTo))); }
public static MvcHtmlString MvcRender(this JavaScriptBundle javaScriptBundle, string renderTo) { return(MvcHtmlString.Create(javaScriptBundle.Render(renderTo))); }
public static MvcHtmlString MvcRenderCachedAssetTag(this JavaScriptBundle javaScriptBundle, string name) { return(MvcHtmlString.Create(javaScriptBundle.RenderCachedAssetTag(name))); }
public static MvcHtmlString MvcRenderNamed(this JavaScriptBundle javaScriptBundle, string name) { return(MvcHtmlString.Create(javaScriptBundle.RenderNamed(name))); }
/// <summary> /// Renders current <see cref="JavaScriptBundle" /> as a named tag /// </summary> /// <param name="javaScriptBundle">Current javascript bundle</param> /// <param name="name">javascript bundle name</param> /// <returns>Current bundle</returns> public static IHtmlString MvcRenderNamed(this JavaScriptBundle javaScriptBundle, string name) { return(new NonEncodedHtmlString(javaScriptBundle.RenderNamed(name))); }
/// <summary> /// Render current <see cref="JavaScriptBundle" /> as a cached asset tag /// </summary> /// <param name="javaScriptBundle">Current javascript bundle</param> /// <param name="name">javascript bundle name</param> /// <returns>Current bundle as a cached asset tag</returns> public static IHtmlString MvcRenderCachedAssetTag(this JavaScriptBundle javaScriptBundle, string name) { return(new NonEncodedHtmlString(javaScriptBundle.RenderCachedAssetTag(name))); }
/// <summary> /// Save current JavaScript bundle as a cached resource on server /// </summary> /// <param name="jsBundle">Current JavaScript bundle</param> /// <param name="name">Name with which to store current bundle</param> /// <returns>Cached bundle access HTML tag</returns> public static string AsCached(this JavaScriptBundle jsBundle, ContentBundle name) { return(jsBundle.AsCached(name.ToString(), "~/assets/js/" + name)); }
/// <summary> </summary> public static String Js(String files, String mode, Boolean debug) { String name = helperService.CalculateMD5Hash(files); String path = file_info.virtual_site_cache_path().Trim('/') + "/scripts/js/"; path = file_info.normalize_path(path); String dir = Path.GetDirectoryName(path); try { if (!Directory.Exists(dir)) { DirectoryInfo di = Directory.CreateDirectory(dir); } } catch { }//let it pass String FilePath = file_info.normalize_path(path + name + ".js"); if (!file_info.dir_exists(path)) { System.IO.Directory.CreateDirectory(path); } site site = siteService.getCurrentSite(); String theme = themeService.current_theme_alias(); JavaScriptBundle js = new JavaScriptBundle(); foreach (string fl in files.Split(',')) { String filepath = themeService.virtual_theme_skin_path(site, theme, mode, "js").Trim('/') + "/" + fl.Trim('/'); if (!file_info.file_exists(filepath)) { filepath = themeService.virtual_theme_skin_path(site, "base", mode, "js").Trim('/') + "/" + fl.Trim('/'); } if (file_info.file_exists(filepath)) { js.Add(filepath); } } String output = ""; debug = true; if (debug == true) { output = js.ForceRelease().ForceDebug().Render(FilePath); } else { try { output = js.ForceRelease().Render(FilePath); if (!String.IsNullOrWhiteSpace(output)) { String content = file_handler.read_from_file(FilePath); content = htmlService.filter_file_images_paths(content, themeService.theme_skin_url(site, theme, mode, "images")); if (!String.IsNullOrWhiteSpace(content)) { file_handler.write_to_file(FilePath, content); } } } catch { output = js.ForceRelease().ForceDebug().Render(FilePath) + "<!-- there is something wrong with your css and can't be parsed -->"; } } return(output); }