Created
February 23, 2011 18:16
-
-
Save ashmind/840866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.Compilation; | |
using System.Web.Mvc; | |
using System.Web.Razor; | |
using System.Web.WebPages.Razor; | |
[assembly: PreApplicationStartMethod(typeof(AshMind.Web.Mvc.Razor.RazorJavaScriptSupport), "SetupAll")] | |
namespace AshMind.Web.Mvc.Razor { | |
public static class RazorJavaScriptSupport { | |
private static bool setupPerformed; | |
public static void SetupAll() { | |
if (setupPerformed) | |
return; | |
var razor = ViewEngines.Engines.OfType<RazorViewEngine>().SingleOrDefault(); | |
if (razor != null) { | |
razor.FileExtensions = AppendJavaScriptVariants(razor.FileExtensions); | |
razor.MasterLocationFormats = AppendJavaScriptVariants(razor.MasterLocationFormats); | |
razor.PartialViewLocationFormats = AppendJavaScriptVariants(razor.PartialViewLocationFormats); | |
razor.ViewLocationFormats = AppendJavaScriptVariants(razor.ViewLocationFormats); | |
} | |
BuildProvider.RegisterBuildProvider(".csjs", typeof(RazorBuildProvider)); | |
BuildProvider.RegisterBuildProvider(".vbjs", typeof(RazorBuildProvider)); | |
RazorCodeLanguage.Languages.Add("csjs", new CSharpRazorCodeLanguage()); | |
RazorCodeLanguage.Languages.Add("vbjs", new VBRazorCodeLanguage()); | |
setupPerformed = true; | |
} | |
private static string[] AppendJavaScriptVariants(string[] razorValues) { | |
return razorValues.Concat( | |
razorValues.Select(v => v.Replace("html", "js")) | |
).Distinct().ToArray(); | |
} | |
} | |
} |
Why not? Though I haven't tested it for a long time now and also Intellisense does not understand it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey can this be used???