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 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));
            }
        }
Esempio n. 5
0
        public void CanRenderDebugTags()
        {
            debugJavaScriptBundle
            .Add(Test1Path)
            .Add(Test2Path)
            .AsNamed("TestWithDebug", currentOutputFile);

            var tag = debugJavaScriptBundle.RenderNamed("TestWithDebug");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"" + Test1Path + "\"></script>\n<script type=\"text/javascript\" src=\"" + Test2Path + "\"></script>\n", tag);
        }
Esempio n. 6
0
 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 CanRenderDebugTags()
        {
            debugJavaScriptBundle
            .Add("~/js/test1.js")
            .Add("~/js/test2.js")
            .AsNamed("TestWithDebug", "~/js/output_3.js");

            var tag = debugJavaScriptBundle.RenderNamed("TestWithDebug");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/test1.js\"></script>\n<script type=\"text/javascript\" src=\"js/test2.js\"></script>\n", TestUtilities.NormalizeLineEndings(tag));
        }
        public void CanBundleJsVaryingOutputBaseHrefRendersIndependentUrl()
        {
            var firstPath  = "first.js";
            var secondPath = "second.js";

            fileReaderFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(firstPath), javaScript);
            fileReaderFactory.SetContentsForFile(TestUtilities.PrepareRelativePath(secondPath), javaScript2);

            string tag = javaScriptBundle
                         .Add(firstPath)
                         .Add(secondPath)
                         .WithOutputBaseHref("http://subdomain.domain.com")
                         .Render("/js/output.js");

            string tagNoBaseHref = javaScriptBundle2
                                   .Add(firstPath)
                                   .Add(secondPath)
                                   .Render("/js/output.js");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"http://subdomain.domain.com/js/output.js?r=A01134C134801A6DEC25510924C1EEA4\"></script>", tag);
            Assert.AreEqual("<script type=\"text/javascript\" src=\"/js/output.js?r=A01134C134801A6DEC25510924C1EEA4\"></script>", tagNoBaseHref);
        }
Esempio n. 9
0
        public void CanRenderDebugTags()
        {
            debugJavaScriptBundle
            .Add("~/js/test1.js")
            .Add("~/js/test2.js")
            .AsNamed("TestWithDebug", "~/js/output_3.js");

            var tag = debugJavaScriptBundle.RenderNamed("TestWithDebug");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/test1.js\"></script><script type=\"text/javascript\" src=\"js/test2.js\"></script>", tag);
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        public void CanRerenderFiles()
        {
            fileReaderFactory.SetFileExists(false);

            javaScriptBundle
            .Add("~/js/test.js")
            .Render("~/js/output_10.js");

            Assert.AreEqual("function product(a,b){return a*b}function sum(a,b){return a+b}", fileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\js\output_10.js")]);

            fileReaderFactory.SetContents(javaScript2);
            fileReaderFactory.SetFileExists(true);
            fileWriterFactory.Files.Clear();
            javaScriptBundle.ClearCache();

            javaScriptBundle2
            .Add("~/js/test.js")
            .Render("~/js/output_10.js");

            Assert.AreEqual("function sum(a,b){return a+b}", fileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\js\output_10.js")]);
        }
Esempio n. 12
0
        public void CanRerenderFiles()
        {
            //fileReaderFactory.SetFileExists(false);

            javaScriptBundle
            .Add(Test1Path)
            .Render(currentOutputFile);

            using (var fr = fileReaderFactory.GetFileReader(currentOutputFile))
            {
                Assert.AreEqual(TEST1_MINIFIED, fr.ReadToEnd());
            }

            //fileReaderFactory.SetContents(javaScript2);
            //fileReaderFactory.SetFileExists(true);
            //fileWriterFactory.Files.Clear();
            javaScriptBundle.ClearCache();

            javaScriptBundle2
            .Add(Test2Path)
            .Render(currentOutputFile);

            minifiedOutput = TEST2_MINIFIED;
        }
Esempio n. 13
0
        public void CanBundleJavaScript()
        {
            var tag = javaScriptBundle
                      .Add(Test1Path)
                      .Render(currentOutputFile);

            Assert.AreEqual(GetResolvedTag(currentOutputFile + "?r=E36D384488ABCF73BCCE650C627FB74F"), tag);
            //Assert.AreEqual(TEST1_MINIFIED, currentFileReader.ReadToEnd());
        }
Esempio n. 14
0
        public void CanBundleJavaScript()
        {
            var tag = javaScriptBundle
                      .Add("~/js/test.js")
                      .Render("~/js/output_1.js");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output_1.js?r=E36D384488ABCF73BCCE650C627FB74F\"></script>", tag);
            Assert.AreEqual("function product(a,b){return a*b}function sum(a,b){return a+b}", fileWriterFactory.Files[TestUtilities.PreparePathRelativeToWorkingDirectory(@"C:\js\output_1.js")]);
        }
Esempio n. 15
0
        public void CanBundleJavaScript()
        {
            var tag = javaScriptBundle
                      .Add("~/js/test.js")
                      .Render("~/js/output_1.js");

            Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output_1.js?r=36286D0CEA57C5ED24B868EB0D2898E9\"></script>", tag);
            Assert.AreEqual("function product(n,t){return n*t}function sum(n,t){return n+t}", fileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output_1.js")]);
        }
Esempio n. 16
0
        /// <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);
        }