Skip to content

Instantly share code, notes, and snippets.

@ashmind
Created February 23, 2011 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashmind/840866 to your computer and use it in GitHub Desktop.
Save ashmind/840866 to your computer and use it in GitHub Desktop.
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();
}
}
}
@theluk
Copy link

theluk commented Mar 12, 2012

Hey can this be used???

@ashmind
Copy link
Author

ashmind commented Mar 12, 2012

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