Skip to content

Commit

Permalink
Added support for area/controller/action.js naming
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Nov 3, 2013
1 parent 76201d3 commit c5407cb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
5 changes: 2 additions & 3 deletions RequireJsNet.Docs/RequireJsNet.Docs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,9 @@
<Content Include="Scripts\app-helpers.js" />
<Content Include="Scripts\app-utils.js" />
<Content Include="Scripts\Controllers\Admin\Dashboard\dashboard-index.js" />
<Content Include="Scripts\Controllers\Root\Home\backup.js" />
<Content Include="Scripts\Controllers\Root\Home\home-contact.js" />
<Content Include="Scripts\Controllers\Root\Home\home-inbox.js" />
<Content Include="Scripts\Controllers\Root\Home\home-index.js" />
<Content Include="Scripts\Controllers\Root\Home\inbox.js" />
<Content Include="Scripts\Controllers\Root\Home\index.js" />
<Content Include="RequireJS.config" />
<Content Include="RequireJS.Release.config" />
<Content Include="RequireJS.Shared.config" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/*
* RequireJS for .NET
* Version 1.0.2.0
* Release Date 26/08/2013
* RequireJS.NET
* Copyright Stefan Prodan
* http://stefanprodan.eu
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/

require([
'Mods/myPublicModule',
'jquery',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
/*
* RequireJS for .NET
* Version 1.0.2.0
* Release Date 26/08/2013
* RequireJS.NET
* Copyright Stefan Prodan
* http://stefanprodan.eu
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/

require([
'keepalive-service', //add dependency
'jquery',
'app-global'
], function (keepalive) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*
* RequireJS for .NET
* Version 1.0.2.0
* Release Date 26/08/2013
* RequireJS.NET
* Copyright Stefan Prodan
* http://stefanprodan.eu
* Dual licensed under the MIT and GPL licenses:
Expand Down
2 changes: 1 addition & 1 deletion RequireJsNet.Docs/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<li class="three" style="display:none;">
<h5>Object instantiation</h5>
app-global.js & home-index.js
app-global.js & root/home/index.js
</li>
</ol>

Expand Down
37 changes: 34 additions & 3 deletions RequireJsNet/RequireJsHtmlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,49 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
var area = html.ViewContext.RouteData.DataTokens["area"] != null
? html.ViewContext.RouteData.DataTokens["area"].ToString()
: "Root";

var controller = html.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue as string;
var action = html.ViewContext.Controller.ValueProvider.GetValue("action").RawValue as string;
var entryPointTmpl = "Controllers/{0}/" + controller + "/" + controller + "-" + action;

//search for controller/action.js in current area
var entryPointTmpl = "Controllers/{0}/" + controller + "/" + action;
var entryPoint = string.Format(entryPointTmpl, area);
var filePath = html.ViewContext.HttpContext.Server.MapPath("~/Scripts/" + entryPoint + ".js");

if (File.Exists(filePath))
{
return new MvcHtmlString(entryPoint);
}

//search for controller/action.js in common area
entryPoint = string.Format(entryPointTmpl, "Common");
var fallbackFile = html.ViewContext.HttpContext.Server.MapPath("~/Scripts/" + entryPoint + ".js");
return File.Exists(fallbackFile) ? new MvcHtmlString(entryPoint) : null;
filePath = html.ViewContext.HttpContext.Server.MapPath("~/Scripts/" + entryPoint + ".js");

if (File.Exists(filePath))
{
return new MvcHtmlString(entryPoint);
}

//search for controller/controller-action.js in current area
entryPointTmpl = "Controllers/{0}/" + controller + "/" + controller + "-" + action;
entryPoint = string.Format(entryPointTmpl, area);
filePath = html.ViewContext.HttpContext.Server.MapPath("~/Scripts/" + entryPoint + ".js");

if (File.Exists(filePath))
{
return new MvcHtmlString(entryPoint);
}

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

if (File.Exists(filePath))
{
return new MvcHtmlString(entryPoint);
}

return null;
}

public static MvcHtmlString GetRequireJsPaths(this HtmlHelper html, string configPath = "")
Expand Down

0 comments on commit c5407cb

Please sign in to comment.