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 CanIncludeDynamicContentInRelease()
        {
            //this doesn't really test the nitty-gritty details (http resolver, download etc...) but its a start
            var context = new Mock <HttpContextBase>();
            var request = new Mock <HttpRequestBase>();

            request.SetupGet(r => r.Url).Returns(new Uri("http://example.com"));
            context.SetupGet(c => c.Request).Returns(request.Object);

            using (new HttpContextScope(context.Object))
            {
                javaScriptBundle
                .ForceRelease()
                .AddDynamic("/some/dynamic/js");
            }

            var tag = javaScriptBundle
                      .Render("~/combined.js");

            Assert.AreEqual(1, fileWriterFactory.Files.Count);
            Assert.AreEqual(minifiedJavaScript, fileWriterFactory.Files[TestUtilities.PrepareRelativePath("combined.js")]);
            Assert.AreEqual("<script type=\"text/javascript\" src=\"combined.js?r=36286D0CEA57C5ED24B868EB0D2898E9\"></script>", tag);
        }
Exemple #3
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));
        }
Exemple #4
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);
        }