/// <summary>
 /// Iterates through the files and folders of the given folder and adds any javascript files found.
 /// </summary>
 /// <param name="bundle">The bundle to which javascript files should be added.</param>
 /// <param name="builder">The builder used for everything except the first iteration...</param>
 /// <param name="folder">The folder to search through.</param>
 /// <returns>The modified bundle.</returns>
 private static IJavaScriptBundleBuilder RecursivelyAddFolder(IJavaScriptBundle bundle, IJavaScriptBundleBuilder builder, string folder)
 {
     foreach (var file in Directory.GetFiles(folder).Where(x => Path.GetExtension(x) == ".js"))
         builder = builder == null ? bundle.Add(TranslatePath(file)) : builder.Add(TranslatePath(file));
     foreach (var localFolder in Directory.GetDirectories(folder))
         builder = RecursivelyAddFolder(bundle, builder, localFolder);
     return builder;
 }
        /// <summary>
        /// Minify the javascript into one file
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="filenames">The filenames.</param>
        /// <param name="outputPathandFilename">The output pathand filename.</param>
        /// <returns></returns>
        public static string Js(this HtmlHelper helper, IEnumerable <string> filenames, string outputPathandFilename)
        {
            IJavaScriptBundle        bundle  = Bundle.JavaScript();
            IJavaScriptBundleBuilder builder = null;

            foreach (string filename in filenames)
            {
                if (builder == null)
                {
                    builder = bundle.Add(filename).WithMinifier(JavaScriptMinifiers.Yui);
                }
                else
                {
                    builder.Add(filename).WithMinifier(JavaScriptMinifiers.Yui);
                }
            }

            return(builder != null ? builder.Render(outputPathandFilename) : string.Empty);
        }
Пример #3
0
 public static MvcHtmlString RenderMvc(this IJavaScriptBundleBuilder javaScriptBundleBuilder, string renderTo)
 {
     return(MvcHtmlString.Create(javaScriptBundleBuilder.Render(renderTo)));
 }
Пример #4
0
 public static IHtmlString RenderMvc(this IJavaScriptBundleBuilder javaScriptBundleBuilder, string renderTo)
 {
     return(new MvcHtmlString(javaScriptBundleBuilder.Render(renderTo)));
 }