From b9e8dcb5c7e07229b0d8031d1764e91327724033 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 24 Oct 2013 18:18:02 +0300 Subject: [PATCH] RenderRequireJsSetup resolves server path for config files --- RequireJsNet.Docs/Views/Shared/_Layout.cshtml | 28 ++++++++------- RequireJsNet/RequireJsHtmlHelpers.cs | 36 ++++++++++++++++--- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/RequireJsNet.Docs/Views/Shared/_Layout.cshtml b/RequireJsNet.Docs/Views/Shared/_Layout.cshtml index ce965ce..52783de 100644 --- a/RequireJsNet.Docs/Views/Shared/_Layout.cshtml +++ b/RequireJsNet.Docs/Views/Shared/_Layout.cshtml @@ -48,18 +48,22 @@ - @if (HttpContext.Current.IsDebuggingEnabled) - { - @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), - Url.Content("~/Scripts/require.js"), - new List {Server.MapPath("~/RequireJS.shared.config"), Server.MapPath("~/RequireJS.config")}) - } - else - { - @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), - Url.Content("~/Scripts/require.js"), - Server.MapPath("~/RequireJS.release.config")) - } + @if (HttpContext.Current.IsDebuggingEnabled) + { + @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), + Url.Content("~/Scripts/require.js"), + new [] + { + "~/RequireJS.shared.config", + "~/RequireJS.config" + }) + } + else + { + @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), + Url.Content("~/Scripts/require.js"), + Server.MapPath("~/RequireJS.release.config")) + } diff --git a/RequireJsNet/RequireJsHtmlHelpers.cs b/RequireJsNet/RequireJsHtmlHelpers.cs index e70441d..41200a1 100644 --- a/RequireJsNet/RequireJsHtmlHelpers.cs +++ b/RequireJsNet/RequireJsHtmlHelpers.cs @@ -24,7 +24,7 @@ public static class RequireJsHtmlHelpers /// Setup RequireJS to be used in layouts /// /// - /// @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), Url.Content("~/Scripts/require.js"), Server.MapPath("~/RequireJS.release.config")) + /// @Html.RenderRequireJsSetup(Url.Content("~/Scripts"), Url.Content("~/Scripts/require.js"), "~/RequireJS.release.config") /// /// Scrips folder /// requirejs.js url @@ -33,9 +33,15 @@ public static MvcHtmlString RenderRequireJsSetup(this HtmlHelper html, string ba string configPath = "") { var setupHtml = new StringBuilder(); - + var entryPointPath = html.RequireJsEntryPoint(); + //resolve config path + if (!string.IsNullOrEmpty(configPath) && configPath.StartsWith("~")) + { + configPath = html.ViewContext.HttpContext.Server.MapPath(configPath); + } + if (entryPointPath != null) { setupHtml.AppendLine(""); @@ -281,5 +289,23 @@ public static Dictionary ToJsonDictionary() var names = Enum.GetNames(enumType); return Enum.GetNames(enumType).ToDictionary(r => r, r => Convert.ToInt32(Enum.Parse(enumType, r))); } + + private static List MapPath(HtmlHelper html, IList configsList) + { + var list = new List(); + foreach (var item in configsList) + { + if(item.StartsWith("~")) + { + list.Add(html.ViewContext.HttpContext.Server.MapPath(item)); + } + else + { + list.Add(item); + } + } + + return list; + } } } \ No newline at end of file