Bundler: ScriptsBundler and StylesBundler, Bundles all the scripts and style sheets on specified directories.
This commit is contained in:
57
Scrummer/Code/Bundler.cs
Normal file
57
Scrummer/Code/Bundler.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Scrummer.Code
|
||||
{
|
||||
public class Bundler
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private string _path = null;
|
||||
private List<string> _files = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
private List<string> Files
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_files != null) { return _files; }
|
||||
|
||||
DirectoryInfo dir = new DirectoryInfo(_path);
|
||||
FileInfo[] files = dir.GetFiles();
|
||||
_files = files.OrderBy(file => file.FullName).Select(file2 => file2.FullName).ToList();
|
||||
return _files;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Creator
|
||||
|
||||
public Bundler(string path)
|
||||
{
|
||||
_path = path;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
public void WriteResponse(Stream outStream)
|
||||
{
|
||||
foreach (string fileName in Files)
|
||||
{
|
||||
string fileContent = File.ReadAllText(fileName);
|
||||
byte[] byteArray = Encoding.UTF8.GetBytes(fileContent);
|
||||
outStream.Write(byteArray, 0, byteArray.Length);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
22
Scrummer/Code/ScriptsBundler.cs
Normal file
22
Scrummer/Code/ScriptsBundler.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Scrummer.Code
|
||||
{
|
||||
public class ScriptsBundler : IHttpHandler
|
||||
{
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
Bundler bundler = new Bundler(context.Server.MapPath("~/Scripts/"));
|
||||
context.Response.ContentType = "text/javascript";
|
||||
bundler.WriteResponse(context.Response.OutputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Scrummer/Code/StylesBundler.cs
Normal file
22
Scrummer/Code/StylesBundler.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Scrummer.Code
|
||||
{
|
||||
public class StylesBundler : IHttpHandler
|
||||
{
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
Bundler bundler = new Bundler(context.Server.MapPath("~/Styles/"));
|
||||
context.Response.ContentType = "text/css";
|
||||
bundler.WriteResponse(context.Response.OutputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user