mirror of https://github.com/Sonarr/Sonarr
cleanup in HtmlIncludeExtentions
This commit is contained in:
parent
e306f0f817
commit
847b743a16
|
@ -8,40 +8,41 @@ namespace NzbDrone.Web.Helpers
|
||||||
{
|
{
|
||||||
public static class HtmlIncludeExtentions
|
public static class HtmlIncludeExtentions
|
||||||
{
|
{
|
||||||
private static string _versionString;
|
private static readonly string versionString;
|
||||||
private static bool _isProduction;
|
private static readonly bool isProduction;
|
||||||
|
|
||||||
static HtmlIncludeExtentions()
|
static HtmlIncludeExtentions()
|
||||||
{
|
{
|
||||||
_versionString = new EnviromentProvider().Version.ToString().Replace('.', '_');
|
versionString = new EnviromentProvider().Version.ToString().Replace('.', '_');
|
||||||
_isProduction = EnviromentProvider.IsProduction;
|
isProduction = EnviromentProvider.IsProduction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MvcHtmlString IncludeScript(this HtmlHelper helper, string filename)
|
public static MvcHtmlString IncludeScript(this HtmlHelper helper, string filename)
|
||||||
{
|
{
|
||||||
var relativePath = "/Scripts/" + filename;
|
var relativePath = "/Scripts/" + filename;
|
||||||
VerifyFile(helper, relativePath);
|
VerifyFile(helper, relativePath);
|
||||||
return MvcHtmlString.Create(String.Format("<script type='text/javascript' src='{0}?{1}'></script>", relativePath, _versionString));
|
return MvcHtmlString.Create(String.Format("<script type='text/javascript' src='{0}?{1}'></script>", relativePath, versionString));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MvcHtmlString IncludeCss(this HtmlHelper helper, string filename)
|
public static MvcHtmlString IncludeCss(this HtmlHelper helper, string filename)
|
||||||
{
|
{
|
||||||
var relativePath = "/Content/" + filename;
|
var relativePath = "/Content/" + filename;
|
||||||
VerifyFile(helper, relativePath);
|
VerifyFile(helper, relativePath);
|
||||||
return MvcHtmlString.Create(String.Format("<link type='text/css' rel='stylesheet' href='{0}?{1}'/>", relativePath, _versionString));
|
return MvcHtmlString.Create(String.Format("<link type='text/css' rel='stylesheet' href='{0}?{1}'/>", relativePath, versionString));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void VerifyFile(HtmlHelper helper, string filename)
|
private static void VerifyFile(HtmlHelper helper, string filename)
|
||||||
{
|
{
|
||||||
if (!_isProduction)
|
if (isProduction)
|
||||||
{
|
return;
|
||||||
|
|
||||||
var path = helper.ViewContext.RequestContext.HttpContext.Server.MapPath(filename);
|
var path = helper.ViewContext.RequestContext.HttpContext.Server.MapPath(filename);
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
throw new FileNotFoundException("static file not found " + path, path);
|
throw new FileNotFoundException("Static file not found " + path, path);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue