@@ -26,44 +26,48 @@ namespace RequireJS
26
26
public static class RequireJsHtmlHelpers
27
27
{
28
28
const string DefaultConfigPath = "~/RequireJS.config" ;
29
+
29
30
/// <summary>
30
31
/// Setup RequireJS to be used in layouts
31
32
/// </summary>
32
33
/// <example>
33
34
/// @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), Url.Content("~/Scripts/require.js"), "~/RequireJS.release.config")
34
35
/// </example>
35
- /// <param name="baseUrl">Scrips folder </param>
36
+ /// <param name="baseUrl">scripts base url </param>
36
37
/// <param name="requireUrl">requirejs.js url</param>
37
38
/// <param name="configPath">RequireJS.config server local path</param>
39
+ /// <param name="entryPointRoot">Scrips folder relative path ex. ~/Scripts/</param>
38
40
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 )
40
42
{
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 ) ;
42
44
}
43
45
44
46
/// <summary>
45
47
/// Setup RequireJS to be used in layouts
46
48
/// </summary>
47
- /// <param name="baseUrl">Scrips folder </param>
49
+ /// <param name="baseUrl">scripts base url </param>
48
50
/// <param name="requireUrl">requirejs.js url</param>
49
51
/// <param name="configsList">RequireJS.config files path</param>
52
+ /// <param name="entryPointRoot">Scrips folder relative path ex. ~/Scripts/</param>
50
53
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 )
52
55
{
53
- return html . RenderRequireJsSetup ( baseUrl , requireUrl , null , configsList , logger ) ;
56
+ return html . RenderRequireJsSetup ( baseUrl , requireUrl , null , configsList , entryPointRoot , logger ) ;
54
57
}
55
58
56
59
/// <summary>
57
60
/// Setup RequireJS to be used in layouts
58
61
/// </summary>
59
- /// <param name="baseUrl">Scrips folder </param>
62
+ /// <param name="baseUrl">scripts base url </param>
60
63
/// <param name="requireUrl">requirejs.js url</param>
61
64
/// <param name="urlArgs"></param>
62
65
/// <param name="configsList">RequireJS.config files path</param>
66
+ /// <param name="entryPointRoot">Scrips folder relative path ex. ~/Scripts/</param>
63
67
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 )
65
69
{
66
- var entryPointPath = html . RequireJsEntryPoint ( ) ;
70
+ var entryPointPath = html . RequireJsEntryPoint ( entryPointRoot ) ;
67
71
68
72
if ( entryPointPath == null )
69
73
{
@@ -116,14 +120,18 @@ public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string ba
116
120
return new MvcHtmlString ( configBuilder . Render ( ) + requireRootBuilder . Render ( ) ) ;
117
121
}
118
122
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 )
120
128
{
121
129
var routingInfo = html . GetRoutingInfo ( ) ;
122
130
123
131
//search for controller/action.js in current area
124
132
var entryPointTmpl = "Controllers/{0}/" + routingInfo . Controller + "/" + routingInfo . Action ;
125
133
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" ) ;
127
135
128
136
if ( File . Exists ( filePath ) )
129
137
{
@@ -132,7 +140,7 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
132
140
133
141
//search for controller/action.js in common area
134
142
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" ) ;
136
144
137
145
if ( File . Exists ( filePath ) )
138
146
{
@@ -142,7 +150,7 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
142
150
//search for controller/controller-action.js in current area
143
151
entryPointTmpl = "Controllers/{0}/" + routingInfo . Controller + "/" + routingInfo . Controller + "-" + routingInfo . Action ;
144
152
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" ) ;
146
154
147
155
if ( File . Exists ( filePath ) )
148
156
{
@@ -151,7 +159,7 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
151
159
152
160
//search for controller/controller-action.js in common area
153
161
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" ) ;
155
163
156
164
if ( File . Exists ( filePath ) )
157
165
{
@@ -161,8 +169,6 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
161
169
return null ;
162
170
}
163
171
164
-
165
-
166
172
public static string CurrentCulture ( this HtmlHelper html )
167
173
{
168
174
// split the ro-Ro string by '-' so it returns eg. ro / en
0 commit comments