Last active
June 15, 2020 10:58
-
-
Save neilkennedy/372650b6386f9a811a3c6c9936182813 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.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