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);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scrummer/Scripts/01. Base.js
Normal file
1
Scrummer/Scripts/01. Base.js
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -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" />
|
||||
|
||||
2
Scrummer/Styles/01. base.css
Normal file
2
Scrummer/Styles/01. base.css
Normal file
@@ -0,0 +1,2 @@
|
||||
body {
|
||||
}
|
||||
Reference in New Issue
Block a user