Skip to content

Commit

Permalink
entryPointRoot parameter added to RenderRequireJsSetup
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Mar 15, 2014
1 parent 1ddc98c commit d5ff665
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion RequireJsNet.Docs/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
{
"~/RequireJS.shared.config",
"~/RequireJS.config"
})
},
entryPointRoot: "~/Scripts/")
}
else
{
Expand Down
38 changes: 22 additions & 16 deletions RequireJsNet/RequireJsHtmlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,48 @@ namespace RequireJS
public static class RequireJsHtmlHelpers
{
const string DefaultConfigPath = "~/RequireJS.config";

/// <summary>
/// Setup RequireJS to be used in layouts
/// </summary>
/// <example>
/// @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), Url.Content("~/Scripts/require.js"), "~/RequireJS.release.config")
/// </example>
/// <param name="baseUrl">Scrips folder</param>
/// <param name="baseUrl">scripts base url</param>
/// <param name="requireUrl">requirejs.js url</param>
/// <param name="configPath">RequireJS.config server local path</param>
/// <param name="entryPointRoot">Scrips folder relative path ex. ~/Scripts/</param>
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl, string urlArgs = "",
string configPath = "", IRequireJsLogger logger = null)
string configPath = "", string entryPointRoot = "~/Scripts/", IRequireJsLogger logger = null)
{
return html.RenderRequireJsSetup(baseUrl, requireUrl, urlArgs, new List<string> { configPath }, logger);
return html.RenderRequireJsSetup(baseUrl, requireUrl, urlArgs, new List<string> { configPath }, entryPointRoot, logger);
}

/// <summary>
/// Setup RequireJS to be used in layouts
/// </summary>
/// <param name="baseUrl">Scrips folder</param>
/// <param name="baseUrl">scripts base url</param>
/// <param name="requireUrl">requirejs.js url</param>
/// <param name="configsList">RequireJS.config files path</param>
/// <param name="entryPointRoot">Scrips folder relative path ex. ~/Scripts/</param>
public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string baseUrl, string requireUrl,
IList<string> configsList, IRequireJsLogger logger = null)
IList<string> configsList, string entryPointRoot = "~/Scripts/", IRequireJsLogger logger = null)
{
return html.RenderRequireJsSetup(baseUrl, requireUrl, null, configsList, logger);
return html.RenderRequireJsSetup(baseUrl, requireUrl, null, configsList, entryPointRoot, logger);
}

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

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

public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
/// <summary>
/// Returns entry point script relative path
/// </summary>
/// <param name="root">Relative root path ex. ~/Scripts/</param>
public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html, string root)
{
var routingInfo = html.GetRoutingInfo();

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

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

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

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

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

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

if (File.Exists(filePath))
{
Expand All @@ -161,8 +169,6 @@ public static MvcHtmlString RequireJsEntryPoint(this HtmlHelper html)
return null;
}



public static string CurrentCulture(this HtmlHelper html)
{
// split the ro-Ro string by '-' so it returns eg. ro / en
Expand Down

0 comments on commit d5ff665

Please sign in to comment.