Skip to content

Commit

Permalink
allow specifying of writer type
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Harrison committed Feb 11, 2015
1 parent 4f0b3e5 commit 805af74
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions MVCGrid/Interfaces/IMVCGridDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ internal interface IMVCGridDefinition
string ClientSideLoadingMessageFunctionName { get; set; }
string ClientSideLoadingCompleteFunctionName { get; set; }
bool Filtering { get; set; }

Type HtmlWriterType { get; set; }
}
}
13 changes: 13 additions & 0 deletions MVCGrid/Models/GridDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class GridDefinitionBase

public class GridDefinition<T1> : GridDefinitionBase, IMVCGridDefinition
{
private Type _htmlWriterType;
const string DefaultNoResultsMessage = "No results.";

public GridDefinition() : this(null)
Expand All @@ -31,6 +32,7 @@ public GridDefinition(GridConfiguration copyFromConfig):base()

Columns = new List<GridColumn<T1>>();
NoResultsMessage = DefaultNoResultsMessage;
_htmlWriterType = typeof(MVCGrid.Rendering.BootstrapHtmlWriter);
}

public GridConfiguration GridConfiguration { get; set; }
Expand Down Expand Up @@ -147,6 +149,17 @@ internal override GridData GetData(GridContext context)
public string ClientSideLoadingMessageFunctionName { get; set; }
public string ClientSideLoadingCompleteFunctionName { get; set; }

public Type HtmlWriterType
{
get
{
return _htmlWriterType;
}
set
{
_htmlWriterType = value;
}
}
}

}
8 changes: 5 additions & 3 deletions MVCGrid/Rendering/HtmlRenderingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ namespace MVCGrid.Rendering
{
public class HtmlRenderingEngine : IMVCGridRenderingEngine
{
public HtmlRenderingEngine()
IMVCGridHtmlWriter _writer;

public HtmlRenderingEngine(IMVCGridHtmlWriter writer)
{
_writer = writer;
}

public void PrepareResponse(HttpResponse response)
Expand All @@ -30,8 +33,7 @@ public void Render(GridData data, GridContext gridContext, Stream outputStream)/
{
RenderingModel model = PrepModel(data, gridContext);

BootstrapHtmlWriter writer = new BootstrapHtmlWriter();
var content = writer.WriteHtml(model);
var content = _writer.WriteHtml(model);

using (StreamWriter sw = new StreamWriter(outputStream))
{
Expand Down
3 changes: 2 additions & 1 deletion MVCGrid/Web/HtmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ internal static IHtmlString MVCGrid(this HtmlHelper helper, string name, IMVCGri

var gridContext = GridContextUtility.Create(HttpContext.Current, gridName, grid, options);

IMVCGridRenderingEngine renderingEngine = new HtmlRenderingEngine();
IMVCGridHtmlWriter writer = (IMVCGridHtmlWriter)Activator.CreateInstance(gridContext.GridDefinition.HtmlWriterType, true);
IMVCGridRenderingEngine renderingEngine = new HtmlRenderingEngine(writer);

var results = ((MVCGrid.Models.GridDefinitionBase)grid).GetData(gridContext);

Expand Down
9 changes: 6 additions & 3 deletions MVCGrid/Web/MVCGridHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ private void HandleTable(HttpContext context)

var gridContext = GridContextUtility.Create(context, gridName, grid, options);

IMVCGridRenderingEngine renderingEngine = DetermineRenderingEngine(context);
IMVCGridHtmlWriter writer = (IMVCGridHtmlWriter)Activator.CreateInstance(gridContext.GridDefinition.HtmlWriterType, true);

IMVCGridRenderingEngine renderingEngine = DetermineRenderingEngine(context, writer);


//if (renderingEngine is HtmlRenderingEngine)
//{
Expand All @@ -199,7 +202,7 @@ private void HandleTable(HttpContext context)
renderingEngine.Render(results, gridContext, context.Response.OutputStream);
}

private IMVCGridRenderingEngine DetermineRenderingEngine(HttpContext context)
private IMVCGridRenderingEngine DetermineRenderingEngine(HttpContext context, IMVCGridHtmlWriter writer)
{
IMVCGridRenderingEngine engine = null;

Expand All @@ -214,7 +217,7 @@ private IMVCGridRenderingEngine DetermineRenderingEngine(HttpContext context)

if (engine == null)
{
engine = new HtmlRenderingEngine();
engine = new HtmlRenderingEngine(writer);
}

return engine;
Expand Down

0 comments on commit 805af74

Please sign in to comment.