Skip to content

Instantly share code, notes, and snippets.

@CoreyKaylor
Created October 20, 2010 21:31
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 CoreyKaylor/637375 to your computer and use it in GitHub Desktop.
Save CoreyKaylor/637375 to your computer and use it in GitHub Desktop.
<link href="~/Content/Site.css" type="text/css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.4.1.js" type="text/javascript" language="javascript" />
<?xml version="1.0" encoding="utf-8" ?>
<bindings>
<element name="Greetings">"Hello from binding!"</element>
<element name="link">
HtmlHelper.RenderLinkImport('@href', '@type', '@rel')
</element>
<element name="script">
HtmlHelper.RenderScriptImport('@src', '@type', '@language')
</element>
</bindings>
private static readonly string _version;
static ViewExtensions()
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
_version = "{0}{1}{2}{3}".ToFormat(version.Major, version.MajorRevision, version.Minor, version.MinorRevision);
}
public static string RenderLinkImport(this HtmlHelper helper, string href, string type, string rel)
{
return @"<link href=""{0}?v={1}"" type=""{2}"" rel=""{3}"" />".ToFormat(href, _version, type, rel);
}
public static string RenderScriptImport(this HtmlHelper helper, string src, string type, string language)
{
#if !DEBUG
if(src.EndsWith(".js"))
src = src.Insert(src.IndexOf(".js"), ".min");
#endif
return @"<link src=""{0}?v={1}"" type=""{2}"" language=""{3}"" />".ToFormat(src, _version, type, language);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment