Skip to content

Commit

Permalink
Merge pull request #29 from serra/template_review
Browse files Browse the repository at this point in the history
Template review: code templates should match the default scaffolding
  • Loading branch information
erichexter committed Nov 13, 2014
2 parents 4ab1c3e + e085fc7 commit aa15efc
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 135 deletions.
6 changes: 5 additions & 1 deletion Test/EndToEnd/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
$p = new-mvcapplication foobar
install-package Newtonsoft.Json
install-package twitter.bootstrap.mvc4.sample -source $source
build-project $p
build-project $p
#close and open solution to remove annoying build errors in temp files
$slnFile = $dte.Solution.FullName
close-solution
open-solution $slnFile
pop-location
$dte.ExecuteCommand("debug.start")
}
Expand Down
20 changes: 18 additions & 2 deletions src/Bootstrap/CodeTemplates/AddController/ControllerWithContext.tt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace <#= Model.Namespace #>
var lambdaVar = modelVariable[0];
var isObjectContext = typeof(ObjectContext).IsAssignableFrom(Model.ContextType);
#>
public class <#= Model.ControllerName #> : BootstrapBaseController
public class <#= Model.ControllerName #> : BootstrapMvcSample.Controllers.BootstrapBaseController
{
private <#= Model.ContextType.Name #> db = new <#= Model.ContextType.Name #>();

Expand Down Expand Up @@ -160,8 +160,24 @@ namespace <#= Model.Namespace #>

//
// GET: <#= routePrefix #>Delete/5

[HttpGet]
public ActionResult Delete(<#= primaryKey.ShortTypeName #> id)
{
<# if(isObjectContext) { #>
<#= modelName #> <#= modelVariable #> = db.<#= entitySetName #>.Single(<#= lambdaVar #> => <#= lambdaVar #>.<#= primaryKey.Name #> == id);
<# } else { #>
<#= modelName #> <#= modelVariable #> = db.<#= entitySetName #>.Find(id);
<# } #>
if (<#= modelVariable #> == null)
{
return HttpNotFound();
}
return View(<#= modelVariable #>);
}

public ActionResult Delete(<#= primaryKey.ShortTypeName #> id)
[HttpPost, ActionName("Delete")]
public ActionResult DeleteModel(<#= primaryKey.ShortTypeName #> id)
{
<# if(isObjectContext) { #>
<#= modelName #> <#= modelVariable #> = db.<#= entitySetName #>.Single(<#= lambdaVar #> => <#= lambdaVar #>.<#= primaryKey.Name #> == id);
Expand Down
35 changes: 9 additions & 26 deletions src/Bootstrap/CodeTemplates/AddView/CSHTML/Create.tt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<#
MvcTextTemplateHost mvcHost = MvcTemplateHost;
#>
@using BootstrapSupport
@model <#= mvcHost.ViewDataTypeName #>
<#
// The following chained if-statement outputs the file header code and markup for a partial view, a content page, or a regular view.
Expand All @@ -36,8 +37,6 @@ if (!String.IsNullOrEmpty(mvcHost.MasterPageFile)) {
#>
}

<h2><#= mvcHost.ViewName#></h2>

<#
} else {
#>
Expand Down Expand Up @@ -75,8 +74,8 @@ if (mvcHost.ReferenceScriptLibraries) {
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)

<fieldset>
<legend><#= mvcHost.ViewDataType.Name #></legend>
<fieldset class="form-horizontal">
<legend>@Model.GetLabel() <small>Details</small></legend>

<#
foreach (ModelProperty property in GetModelProperties(mvcHost.ViewDataType)) {
Expand All @@ -86,11 +85,11 @@ foreach (ModelProperty property in GetModelProperties(mvcHost.ViewDataType)) {
<#
if (property.IsForeignKey) {
#>
@Html.LabelFor(model => model.<#= property.Name #>, "<#= property.AssociationName #>")
@Html.LabelFor(model => model.<#= property.Name #>, "<#= property.AssociationName #>", new { @class = "control-label" })
<#
} else {
#>
@Html.LabelFor(model => model.<#= property.Name #>)
@Html.LabelFor(model => model.<#= property.Name #>, new { @class = "control-label" })
<#
}
#>
Expand All @@ -115,33 +114,17 @@ foreach (ModelProperty property in GetModelProperties(mvcHost.ViewDataType)) {
}
}
#>
<div class="control-group">
<div class="controls">
<input type="submit" value="Create" class="btn" /> &nbsp; @Html.ActionLink("Cancel", "Index")
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save changes</button>
@Html.ActionLink("Cancel", "Index", null, new { @class = "btn " })
</div>
</fieldset>
}

<#
if(mvcHost.IsContentPage && mvcHost.ReferenceScriptLibraries) {
#>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")

<script>

$.validator.setDefaults({
highlight: function (element) {
$(element).closest(".control-group").addClass("error");
},
unhighlight: function (element) {
$(element).closest(".control-group").removeClass("error");
}
});
</script>
}
<#
}
#>
Expand Down
24 changes: 12 additions & 12 deletions src/Bootstrap/CodeTemplates/AddView/CSHTML/Delete.tt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<#
MvcTextTemplateHost mvcHost = MvcTemplateHost;
#>
@using BootstrapSupport
@model <#= mvcHost.ViewDataTypeName #>
<#
// The following chained if-statement outputs the file header code and markup for a partial view, a content page, or a regular view.
Expand All @@ -37,8 +38,6 @@ if (!String.IsNullOrEmpty(mvcHost.MasterPageFile)) {
#>
}

<h2><#= mvcHost.ViewName#></h2>

<#
} else {
#>
Expand All @@ -59,33 +58,34 @@ if (!String.IsNullOrEmpty(mvcHost.MasterPageFile)) {
PushIndent(" ");
}
#>
<h3>Are you sure you want to delete this?</h3>
@using (Html.BeginForm())
{

<fieldset>
<legend><#= mvcHost.ViewDataType.Name #></legend>
<legend>@Model.GetLabel() <small>Details</small></legend>
<dl>
<#
foreach (ModelProperty property in GetModelProperties(mvcHost.ViewDataType)) {
if (!property.IsPrimaryKey && property.Scaffold) {
#>

<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.<#= property.ValueExpression #>)
</dt>
<dd>
@Html.DisplayFor(model => model.<#= property.ValueExpression #>)
</dd>
</dl>
<#
}
}
#>
</fieldset>
@using (Html.BeginForm()) {
<div class="control-group">
<div class="controls">
<input type="submit" value="Delete" class="btn" /> &nbsp; @Html.ActionLink("Cancel", "Index")
</div>
</dl>
<div class="form-actions">
<button type="submit" class="btn btn-danger">Delete</button>
@Html.ActionLink("Cancel", "Index", null, new { @class = "btn" })
</div>
</fieldset>

}
<#
// The following code closes the asp:Content tag used in the case of a master page and the body and html tags in the case of a regular view page
Expand Down
22 changes: 10 additions & 12 deletions src/Bootstrap/CodeTemplates/AddView/CSHTML/Details.tt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<#
MvcTextTemplateHost mvcHost = MvcTemplateHost;
#>
@using BootstrapSupport
@model <#= mvcHost.ViewDataTypeName #>
<#
// The following chained if-statement outputs the file header code and markup for a partial view, a content page, or a regular view.
Expand All @@ -37,8 +38,6 @@ if (!String.IsNullOrEmpty(mvcHost.MasterPageFile)) {
#>
}

<h2><#= mvcHost.ViewName#></h2>

<#
} else {
#>
Expand All @@ -60,24 +59,23 @@ if (!String.IsNullOrEmpty(mvcHost.MasterPageFile)) {
}
#>
<fieldset>
<legend><#= mvcHost.ViewDataType.Name #></legend>
<legend>@Model.GetLabel() <small>Details</small></legend>
<dl> <!-- consider adding class="dl-horizontal" for horizontal styling -->
<#
foreach (ModelProperty property in GetModelProperties(mvcHost.ViewDataType)) {
if (!property.IsPrimaryKey && property.Scaffold) {
#>

<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.<#= property.ValueExpression #>)
</dt>
<dd>
@Html.DisplayFor(model => model.<#= property.ValueExpression #>)
</dd>
</dl>
<dt>
@Html.DisplayNameFor(model => model.<#= property.ValueExpression #>)
</dt>
<dd>
@Html.DisplayFor(model => model.<#= property.ValueExpression #>)
</dd>
<#
}
}
#>
</dl>
</fieldset>
<p>
<#
Expand Down
61 changes: 18 additions & 43 deletions src/Bootstrap/CodeTemplates/AddView/CSHTML/Edit.tt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<#
MvcTextTemplateHost mvcHost = MvcTemplateHost;
#>
@using BootstrapSupport
@model <#= mvcHost.ViewDataTypeName #>
<#
// The following chained if-statement outputs the file header code and markup for a partial view, a content page, or a regular view.
Expand All @@ -36,8 +37,6 @@ if (!String.IsNullOrEmpty(mvcHost.MasterPageFile)) {
#>
}

<h2><#= mvcHost.ViewName#></h2>

<#
} else {
#>
Expand Down Expand Up @@ -75,81 +74,57 @@ if (mvcHost.ReferenceScriptLibraries) {
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)

<fieldset>
<legend><#= mvcHost.ViewDataType.Name #></legend>
<fieldset class="form-horizontal">
<legend>@Model.GetLabel() <small>Details</small></legend>

<#
foreach (ModelProperty property in GetModelProperties(mvcHost.ViewDataType)) {
if (property.Scaffold) {
if (property.IsPrimaryKey) {
#>
@Html.HiddenFor(model => model.<#= property.Name #>)

<#
} else if (!property.IsReadOnly) {
if (!property.IsPrimaryKey && !property.IsReadOnly && property.Scaffold) {
#>

<div class="control-group">
<#
if (property.IsForeignKey) {
if (property.IsForeignKey) {
#>
@Html.LabelFor(model => model.<#= property.Name #>, "<#= property.AssociationName #>")
@Html.LabelFor(model => model.<#= property.Name #>, "<#= property.AssociationName #>", new { @class = "control-label" })
<#
} else {
} else {
#>
@Html.LabelFor(model => model.<#= property.Name #>)
@Html.LabelFor(model => model.<#= property.Name #>, new { @class = "control-label" })
<#
}
}
#>

<div class="controls">
<#
if (property.IsForeignKey) {
if (property.IsForeignKey) {
#>
@Html.DropDownList("<#= property.Name #>", String.Empty)
<#
} else {
} else {
#>
@Html.EditorFor(model => model.<#= property.Name #>)
<#
}
}
#>
@Html.ValidationMessageFor(model => model.<#= property.Name #>, string.Empty, new { @class="help-inline" })
</div>
</div>
</div>
</div>

<#
}
}
}
#>
<div class="control-group">
<div class="controls">
<input type="submit" value="Save" class="btn" /> &nbsp; @Html.ActionLink("Cancel", "Index")
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save changes</button>
@Html.ActionLink("Cancel", "Index", null, new { @class = "btn " })
</div>
</fieldset>
}

<#
if(mvcHost.IsContentPage && mvcHost.ReferenceScriptLibraries) {
#>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")

<script>

$.validator.setDefaults({
highlight: function (element) {
$(element).closest(".control-group").addClass("error");
},
unhighlight: function (element) {
$(element).closest(".control-group").removeClass("error");
}
});
</script>
}
<#
}
#>
Expand Down
Loading

0 comments on commit aa15efc

Please sign in to comment.