Skip to content

Commit 1ddc98c

Browse files
committed
Added support for JS assets versioning
resolves #13
1 parent 2ba3581 commit 1ddc98c

File tree

5 files changed

+84
-61
lines changed

5 files changed

+84
-61
lines changed

RequireJsNet.Docs/Helpers/MvcRenders.cs

+5
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ public static string RenderView(this Controller controller, string viewName, obj
4343
return sw.GetStringBuilder().ToString().Trim();
4444
}
4545
}
46+
47+
public static string RenderAppVersion()
48+
{
49+
return "v=" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
50+
}
4651
}
4752
}

RequireJsNet.Docs/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("1.0.0.0")]
34+
[assembly: AssemblyVersion("1.1.0.1")]
35+
[assembly: AssemblyFileVersion("1.1.0.1")]
+58-56
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,71 @@
11
@using RequireJS
2+
@using RequireJsNet.Docs.Helpers
23

34
<!DOCTYPE html>
45
<html lang="en">
5-
<head>
6-
<meta charset="utf-8" />
7-
<title>@ViewBag.Title</title>
8-
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
9-
<meta name="viewport" content="width=device-width" />
10-
11-
<!--[if lt IE 9]>
12-
<script src="@Url.Content("~/Scripts/Lib/Vendor/HTML5/json2.js")" type="text/javascript"></script>
13-
<script src="@Url.Content("~/Scripts/Lib/Vendor/HTML5/html5shiv.js")"></script>
14-
<![endif]-->
6+
<head>
7+
<meta charset="utf-8" />
8+
<title>@ViewBag.Title</title>
9+
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
10+
<meta name="viewport" content="width=device-width" />
1511

16-
@Styles.Render("~/css")
17-
</head>
18-
<body>
19-
<header>
20-
<div class="content-wrapper">
21-
<div class="float-left">
22-
<p class="site-title">@Html.ActionLink("RequireJS for .NET", "Index", "Home")</p>
23-
</div>
24-
<div class="float-right">
25-
<section id="login">
26-
</section>
27-
<nav>
28-
<ul id="menu">
29-
<li>@Html.ActionLink("Home", "Index", "Home")</li>
30-
<li>@Html.ActionLink("About", "About", "Home")</li>
31-
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
32-
</ul>
33-
</nav>
34-
</div>
12+
<!--[if lt IE 9]>
13+
<script src="@Url.Content("~/Scripts/Lib/Vendor/HTML5/json2.js")" type="text/javascript"></script>
14+
<script src="@Url.Content("~/Scripts/Lib/Vendor/HTML5/html5shiv.js")"></script>
15+
<![endif]-->
16+
@Styles.Render("~/css")
17+
</head>
18+
<body>
19+
<header>
20+
<div class="content-wrapper">
21+
<div class="float-left">
22+
<p class="site-title">@Html.ActionLink("RequireJS for .NET", "Index", "Home")</p>
23+
</div>
24+
<div class="float-right">
25+
<section id="login"></section>
26+
<nav>
27+
<ul id="menu">
28+
<li>@Html.ActionLink("Home", "Index", "Home")</li>
29+
<li>@Html.ActionLink("About", "About", "Home")</li>
30+
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
31+
</ul>
32+
</nav>
3533
</div>
36-
</header>
37-
<div id="body">
38-
@RenderSection("featured", required: false)
39-
<section class="content-wrapper main-content clear-fix">
40-
@RenderBody()
41-
</section>
4234
</div>
43-
<footer>
44-
<div class="content-wrapper">
45-
<div class="float-left">
46-
<p>&copy; @DateTime.Now.Year - <a href="http://www.stefanprodan.eu">Stefan Prodan's Tech Notes</a></p>
47-
</div>
35+
</header>
36+
<div id="body">
37+
@RenderSection("featured", required: false)
38+
<section class="content-wrapper main-content clear-fix">
39+
@RenderBody()
40+
</section>
41+
</div>
42+
<footer>
43+
<div class="content-wrapper">
44+
<div class="float-left">
45+
<p>&copy; @DateTime.Now.Year - <a href="http://www.stefanprodan.eu">Stefan Prodan's Tech Notes</a></p>
4846
</div>
49-
</footer>
47+
</div>
48+
</footer>
5049

51-
@if (HttpContext.Current.IsDebuggingEnabled)
52-
{
53-
@Html.RenderRequireJsSetup(Url.Content("~/Scripts"),
54-
Url.Content("~/Scripts/require.js"),
55-
new []
50+
@if (HttpContext.Current.IsDebuggingEnabled)
51+
{
52+
@Html.RenderRequireJsSetup(
53+
baseUrl: Url.Content("~/Scripts"),
54+
requireUrl: Url.Content("~/Scripts/require.js"),
55+
configsList: new[]
5656
{
57-
"~/RequireJS.shared.config",
57+
"~/RequireJS.shared.config",
5858
"~/RequireJS.config"
5959
})
60-
}
61-
else
62-
{
63-
@Html.RenderRequireJsSetup(Url.Content("~/Scripts"),
64-
Url.Content("~/Scripts/require.js"),
65-
Server.MapPath("~/RequireJS.release.config"))
66-
}
67-
68-
</body>
60+
}
61+
else
62+
{
63+
@Html.RenderRequireJsSetup(
64+
baseUrl: Url.Content("~/Scripts"),
65+
requireUrl: Url.Content("~/Scripts/require.js"),
66+
urlArgs: MvcRenders.RenderAppVersion(),
67+
configPath: Server.MapPath("~/RequireJS.release.config"))
68+
}
69+
70+
</body>
6971
</html>

RequireJsNet/Models/JsonConfig.cs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ internal class JsonConfig
1515
public string BaseUrl { get; set; }
1616
[JsonProperty(PropertyName = "locale")]
1717
public string Locale { get; set; }
18+
[JsonProperty(PropertyName = "urlArgs")]
19+
public string UrlArgs { get; set; }
1820
[JsonProperty(PropertyName = "paths")]
1921
public Dictionary<string, string> Paths { get; set; }
2022
[JsonProperty(PropertyName = "shim")]

RequireJsNet/RequireJsHtmlHelpers.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public static class RequireJsHtmlHelpers
3535
/// <param name="baseUrl">Scrips folder</param>
3636
/// <param name="requireUrl">requirejs.js url</param>
3737
/// <param name="configPath">RequireJS.config server local path</param>
38-
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl,
38+
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl, string urlArgs = "",
3939
string configPath = "", IRequireJsLogger logger = null)
4040
{
41-
return html.RenderRequireJsSetup(baseUrl, requireUrl, new List<string> { configPath }, logger);
41+
return html.RenderRequireJsSetup(baseUrl, requireUrl, urlArgs, new List<string> { configPath }, logger);
4242
}
4343

4444
/// <summary>
@@ -49,6 +49,19 @@ public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string ba
4949
/// <param name="configsList">RequireJS.config files path</param>
5050
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl,
5151
IList<string> configsList, IRequireJsLogger logger = null)
52+
{
53+
return html.RenderRequireJsSetup(baseUrl, requireUrl, null, configsList, logger);
54+
}
55+
56+
/// <summary>
57+
/// Setup RequireJS to be used in layouts
58+
/// </summary>
59+
/// <param name="baseUrl">Scrips folder</param>
60+
/// <param name="requireUrl">requirejs.js url</param>
61+
/// <param name="urlArgs"></param>
62+
/// <param name="configsList">RequireJS.config files path</param>
63+
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl, string urlArgs,
64+
IList<string> configsList, IRequireJsLogger logger = null)
5265
{
5366
var entryPointPath = html.RequireJsEntryPoint();
5467

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

60-
if (!configsList.Any())
73+
if (configsList == null || !configsList.Any())
6174
{
6275
throw new Exception("No config files to load.");
6376
}
@@ -74,6 +87,7 @@ public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string ba
7487
{
7588
BaseUrl = baseUrl,
7689
Locale = html.CurrentCulture(),
90+
UrlArgs = urlArgs,
7791
Paths = resultingConfig.Paths.PathList.ToDictionary(r => r.Key, r => r.Value),
7892
Shim = resultingConfig.Shim.ShimEntries.ToDictionary(r => r.For, r => new JsonRequireDeps
7993
{

0 commit comments

Comments
 (0)