Bundler: ScriptsBundler and StylesBundler, Bundles all the scripts and style sheets on specified directories.

This commit is contained in:
2015-05-24 15:57:07 +02:00
parent b35379b8fe
commit 1dd4841901
6 changed files with 109 additions and 0 deletions

57
Scrummer/Code/Bundler.cs Normal file
View 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
}
}

View 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);
}
}
}

View 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);
}
}
}

View File

@@ -0,0 +1 @@

View File

@@ -58,6 +58,7 @@
<Reference Include="System.EnterpriseServices" />
</ItemGroup>
<ItemGroup>
<Content Include="Scripts\01. Base.js" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
<SubType>Designer</SubType>
@@ -68,12 +69,16 @@
</None>
</ItemGroup>
<ItemGroup>
<Content Include="Styles\01. base.css" />
<Content Include="Web.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="Code\Bundler.cs" />
<Compile Include="Code\Controls\CLabel.cs" />
<Compile Include="Code\GlobalErrorHandler.cs" />
<Compile Include="Code\JSON\ParserContext.cs" />
<Compile Include="Code\ScriptsBundler.cs" />
<Compile Include="Code\StylesBundler.cs" />
<Compile Include="GlobalRouter.cs" />
<Compile Include="Code\JSON\JSONParser.cs" />
<Compile Include="Code\JSON\JSONWriter.cs" />

View File

@@ -0,0 +1,2 @@
body {
}