コード例 #1
0
        private static StringBuilder BuildDebugScripts(UrlHelper urlHelper)
        {
            var builder = new StringBuilder();
            IPathMapper mapper = new PathMapper();
            var basePath = mapper.MapPath("~/Scripts/Required/debug");

            var files = Directory.GetFiles(basePath).ToList();

            files.ForEach(file =>
            {
                var scriptTag = new TagBuilder("script");
                scriptTag.MergeAttribute("type", "text/javascript");
                var scriptUrl = urlHelper.Content("~/Scripts/Required/debug/" + Path.GetFileName(file));
                scriptTag.MergeAttribute("src", scriptUrl);

                builder.AppendLine(scriptTag.ToString());
            });
            return builder;
        }
コード例 #2
0
ファイル: ThemeRoller.cs プロジェクト: rinckd/sblog.net
        public static MvcHtmlString LoadStylesAndScripts(this HtmlHelper helper, string themeName)
        {
            var urlHelper = helper.GetUrlHelper();
            var builder = new StringBuilder();

            var pathMapper = new PathMapper();
            var basePath = pathMapper.MapPath(string.Format(ThemeCssBasePath, themeName));

            var cssFiles = Directory.GetFiles(basePath, "*.css").ToList();

            cssFiles.ForEach(file =>
            {
                var themeStyle = new TagBuilder("link");
                themeStyle.MergeAttribute("href", urlHelper.Content(string.Format("{0}/{1}", string.Format(ThemeCssBasePath, themeName), Path.GetFileName(file))));
                themeStyle.MergeAttribute("rel", "stylesheet");
                themeStyle.MergeAttribute("type", "text/css");

                builder.AppendLine(themeStyle.ToString());
            });

            basePath = pathMapper.MapPath(string.Format(ThemeScriptBasePath, themeName));

            if (Directory.Exists(basePath))
            {
                var scriptFiles = Directory.GetFiles(basePath, "*.js").ToList();

                scriptFiles.ForEach(file =>
                {
                    var themeScript = new TagBuilder("script");
                    themeScript.MergeAttribute("src", urlHelper.Content(string.Format("{0}/{1}", string.Format(ThemeScriptBasePath, themeName), Path.GetFileName(file))));
                    themeScript.MergeAttribute("type", "text/javascript");

                    builder.AppendLine(themeScript.ToString());
                });
            }

            return MvcHtmlString.Create(builder.ToString());
        }