Skip to content

Commit

Permalink
Added support for JS assets versioning
Browse files Browse the repository at this point in the history
resolves #13
  • Loading branch information
stefanprodan committed Mar 2, 2014
1 parent 2ba3581 commit 1ddc98c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 61 deletions.
5 changes: 5 additions & 0 deletions RequireJsNet.Docs/Helpers/MvcRenders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ public static string RenderView(this Controller controller, string viewName, obj
return sw.GetStringBuilder().ToString().Trim();
}
}

public static string RenderAppVersion()
{
return "v=" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
}
4 changes: 2 additions & 2 deletions RequireJsNet.Docs/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.1")]
[assembly: AssemblyFileVersion("1.1.0.1")]
114 changes: 58 additions & 56 deletions RequireJsNet.Docs/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,69 +1,71 @@
@using RequireJS
@using RequireJsNet.Docs.Helpers

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />

<!--[if lt IE 9]>
<script src="@Url.Content("~/Scripts/Lib/Vendor/HTML5/json2.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Lib/Vendor/HTML5/html5shiv.js")"></script>
<![endif]-->
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />

@Styles.Render("~/css")
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">@Html.ActionLink("RequireJS for .NET", "Index", "Home")</p>
</div>
<div class="float-right">
<section id="login">
</section>
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</nav>
</div>
<!--[if lt IE 9]>
<script src="@Url.Content("~/Scripts/Lib/Vendor/HTML5/json2.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Lib/Vendor/HTML5/html5shiv.js")"></script>
<![endif]-->
@Styles.Render("~/css")
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">@Html.ActionLink("RequireJS for .NET", "Index", "Home")</p>
</div>
<div class="float-right">
<section id="login"></section>
<nav>
<ul id="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</nav>
</div>
</header>
<div id="body">
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>&copy; @DateTime.Now.Year - <a href="http://www.stefanprodan.eu">Stefan Prodan's Tech Notes</a></p>
</div>
</header>
<div id="body">
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>&copy; @DateTime.Now.Year - <a href="http://www.stefanprodan.eu">Stefan Prodan's Tech Notes</a></p>
</div>
</footer>
</div>
</footer>

@if (HttpContext.Current.IsDebuggingEnabled)
{
@Html.RenderRequireJsSetup(Url.Content("~/Scripts"),
Url.Content("~/Scripts/require.js"),
new []
@if (HttpContext.Current.IsDebuggingEnabled)
{
@Html.RenderRequireJsSetup(
baseUrl: Url.Content("~/Scripts"),
requireUrl: Url.Content("~/Scripts/require.js"),
configsList: new[]
{
"~/RequireJS.shared.config",
"~/RequireJS.shared.config",
"~/RequireJS.config"
})
}
else
{
@Html.RenderRequireJsSetup(Url.Content("~/Scripts"),
Url.Content("~/Scripts/require.js"),
Server.MapPath("~/RequireJS.release.config"))
}

</body>
}
else
{
@Html.RenderRequireJsSetup(
baseUrl: Url.Content("~/Scripts"),
requireUrl: Url.Content("~/Scripts/require.js"),
urlArgs: MvcRenders.RenderAppVersion(),
configPath: Server.MapPath("~/RequireJS.release.config"))
}

</body>
</html>
2 changes: 2 additions & 0 deletions RequireJsNet/Models/JsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal class JsonConfig
public string BaseUrl { get; set; }
[JsonProperty(PropertyName = "locale")]
public string Locale { get; set; }
[JsonProperty(PropertyName = "urlArgs")]
public string UrlArgs { get; set; }
[JsonProperty(PropertyName = "paths")]
public Dictionary<string, string> Paths { get; set; }
[JsonProperty(PropertyName = "shim")]
Expand Down
20 changes: 17 additions & 3 deletions RequireJsNet/RequireJsHtmlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public static class RequireJsHtmlHelpers
/// <param name="baseUrl">Scrips folder</param>
/// <param name="requireUrl">requirejs.js url</param>
/// <param name="configPath">RequireJS.config server local path</param>
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl,
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl, string urlArgs = "",
string configPath = "", IRequireJsLogger logger = null)
{
return html.RenderRequireJsSetup(baseUrl, requireUrl, new List<string> { configPath }, logger);
return html.RenderRequireJsSetup(baseUrl, requireUrl, urlArgs, new List<string> { configPath }, logger);
}

/// <summary>
Expand All @@ -49,6 +49,19 @@ public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string ba
/// <param name="configsList">RequireJS.config files path</param>
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl,
IList<string> configsList, IRequireJsLogger logger = null)
{
return html.RenderRequireJsSetup(baseUrl, requireUrl, null, configsList, logger);
}

/// <summary>
/// Setup RequireJS to be used in layouts
/// </summary>
/// <param name="baseUrl">Scrips folder</param>
/// <param name="requireUrl">requirejs.js url</param>
/// <param name="urlArgs"></param>
/// <param name="configsList">RequireJS.config files path</param>
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl, string urlArgs,
IList<string> configsList, IRequireJsLogger logger = null)
{
var entryPointPath = html.RequireJsEntryPoint();

Expand All @@ -57,7 +70,7 @@ public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string ba
return new MvcHtmlString(string.Empty);
}

if (!configsList.Any())
if (configsList == null || !configsList.Any())
{
throw new Exception("No config files to load.");
}
Expand All @@ -74,6 +87,7 @@ public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string ba
{
BaseUrl = baseUrl,
Locale = html.CurrentCulture(),
UrlArgs = urlArgs,
Paths = resultingConfig.Paths.PathList.ToDictionary(r => r.Key, r => r.Value),
Shim = resultingConfig.Shim.ShimEntries.ToDictionary(r => r.For, r => new JsonRequireDeps
{
Expand Down

0 comments on commit 1ddc98c

Please sign in to comment.