Skip to content

Commit d5ff665

Browse files
committed
entryPointRoot parameter added to RenderRequireJsSetup
1 parent 1ddc98c commit d5ff665

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

RequireJsNet.Docs/Views/Shared/_Layout.cshtml

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
{
5757
"~/RequireJS.shared.config",
5858
"~/RequireJS.config"
59-
})
59+
},
60+
entryPointRoot: "~/Scripts/")
6061
}
6162
else
6263
{

RequireJsNet/RequireJsHtmlHelpers.cs

+22-16
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,48 @@ namespace RequireJS
2626
public static class RequireJsHtmlHelpers
2727
{
2828
const string DefaultConfigPath = "~/RequireJS.config";
29+
2930
/// <summary>
3031
/// Setup RequireJS to be used in layouts
3132
/// </summary>
3233
/// <example>
3334
/// @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), Url.Content("~/Scripts/require.js"), "~/RequireJS.release.config")
3435
/// </example>
35-
/// <param name="baseUrl">Scrips folder</param>
36+
/// <param name="baseUrl">scripts base url</param>
3637
/// <param name="requireUrl">requirejs.js url</param>
3738
/// <param name="configPath">RequireJS.config server local path</param>
39+
/// <param name="entryPointRoot">Scrips folder relative path ex. ~/Scripts/</param>
3840
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl, string urlArgs = "",
39-
string configPath = "", IRequireJsLogger logger = null)
41+
string configPath = "", string entryPointRoot = "~/Scripts/", IRequireJsLogger logger = null)
4042
{
41-
return html.RenderRequireJsSetup(baseUrl, requireUrl, urlArgs, new List<string> { configPath }, logger);
43+
return html.RenderRequireJsSetup(baseUrl, requireUrl, urlArgs, new List<string> { configPath }, entryPointRoot, logger);
4244
}
4345

4446
/// <summary>
4547
/// Setup RequireJS to be used in layouts
4648
/// </summary>
47-
/// <param name="baseUrl">Scrips folder</param>
49+
/// <param name="baseUrl">scripts base url</param>
4850
/// <param name="requireUrl">requirejs.js url</param>
4951
/// <param name="configsList">RequireJS.config files path</param>
52+
/// <param name="entryPointRoot">Scrips folder relative path ex. ~/Scripts/</param>
5053
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl,
51-
IList<string> configsList, IRequireJsLogger logger = null)
54+
IList<string> configsList, string entryPointRoot = "~/Scripts/", IRequireJsLogger logger = null)
5255
{
53-
return html.RenderRequireJsSetup(baseUrl, requireUrl, null, configsList, logger);
56+
return html.RenderRequireJsSetup(baseUrl, requireUrl, null, configsList, entryPointRoot, logger);
5457
}
5558

5659
/// <summary>
5760
/// Setup RequireJS to be used in layouts
5861
/// </summary>
59-
/// <param name="baseUrl">Scrips folder</param>
62+
/// <param name="baseUrl">scripts base url</param>
6063
/// <param name="requireUrl">requirejs.js url</param>
6164
/// <param name="urlArgs"></param>
6265
/// <param name="configsList">RequireJS.config files path</param>
66+
/// <param name="entryPointRoot">Scrips folder relative path ex. ~/Scripts/</param>
6367
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl, string urlArgs,
64-
IList<string> configsList, IRequireJsLogger logger = null)
68+
IList<string> configsList, string entryPointRoot = "~/Scripts/", IRequireJsLogger logger = null)
6569
{
66-
var entryPointPath = html.RequireJsEntryPoint();
70+
var entryPointPath = html.RequireJsEntryPoint(entryPointRoot);
6771

6872
if (entryPointPath == null)
6973
{
@@ -116,14 +120,18 @@ public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string ba
116120
return new MvcHtmlString(configBuilder.Render() + requireRootBuilder.Render());
117121
}
118122

119-
public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
123+
/// <summary>
124+
/// Returns entry point script relative path
125+
/// </summary>
126+
/// <param name="root">Relative root path ex. ~/Scripts/</param>
127+
public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html, string root)
120128
{
121129
var routingInfo = html.GetRoutingInfo();
122130

123131
//search for controller/action.js in current area
124132
var entryPointTmpl = "Controllers/{0}/" + routingInfo.Controller + "/" + routingInfo.Action;
125133
var entryPoint = string.Format(entryPointTmpl, routingInfo.Area);
126-
var filePath = html.ViewContext.HttpContext.Server.MapPath("~/Scripts/" + entryPoint + ".js");
134+
var filePath = html.ViewContext.HttpContext.Server.MapPath(root + entryPoint + ".js");
127135

128136
if (File.Exists(filePath))
129137
{
@@ -132,7 +140,7 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
132140

133141
//search for controller/action.js in common area
134142
entryPoint = string.Format(entryPointTmpl, "Common");
135-
filePath = html.ViewContext.HttpContext.Server.MapPath("~/Scripts/" + entryPoint + ".js");
143+
filePath = html.ViewContext.HttpContext.Server.MapPath(root + entryPoint + ".js");
136144

137145
if (File.Exists(filePath))
138146
{
@@ -142,7 +150,7 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
142150
//search for controller/controller-action.js in current area
143151
entryPointTmpl = "Controllers/{0}/" + routingInfo.Controller + "/" + routingInfo.Controller + "-" + routingInfo.Action;
144152
entryPoint = string.Format(entryPointTmpl, routingInfo.Area);
145-
filePath = html.ViewContext.HttpContext.Server.MapPath("~/Scripts/" + entryPoint + ".js");
153+
filePath = html.ViewContext.HttpContext.Server.MapPath(root + entryPoint + ".js");
146154

147155
if (File.Exists(filePath))
148156
{
@@ -151,7 +159,7 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
151159

152160
//search for controller/controller-action.js in common area
153161
entryPoint = string.Format(entryPointTmpl, "Common");
154-
filePath = html.ViewContext.HttpContext.Server.MapPath("~/Scripts/" + entryPoint + ".js");
162+
filePath = html.ViewContext.HttpContext.Server.MapPath(root + entryPoint + ".js");
155163

156164
if (File.Exists(filePath))
157165
{
@@ -161,8 +169,6 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
161169
return null;
162170
}
163171

164-
165-
166172
public static string CurrentCulture(this HtmlHelper html)
167173
{
168174
// split the ro-Ro string by '-' so it returns eg. ro / en

0 commit comments

Comments
 (0)