Skip to content

Instantly share code, notes, and snippets.

@neilkennedy
Last active June 15, 2020 10:58
Show Gist options
  • Save neilkennedy/372650b6386f9a811a3c6c9936182813 to your computer and use it in GitHub Desktop.
Save neilkennedy/372650b6386f9a811a3c6c9936182813 to your computer and use it in GitHub Desktop.
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
namespace MyApp.Helpers.HtmlHelpers
{
public static class HtmlHelperExtensions
{
private const string ScriptFolder = "dist";
public static string GetScripts(this HtmlHelper helper, string expression, string path = null)
{
// This is here for unit testing so we can pass in a custom path
if (path == null)
{
path = HttpRuntime.AppDomainAppPath;
}
var files = Directory.GetFiles(Path.Combine(path, ScriptFolder), expression).Select(Path.GetFileName).ToList();
return files.Count == 1 ? $"/{ScriptFolder}/{files[0]}" : "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment