예제 #1
0
        public virtual async Task <HtmlString> GetAsync(string asset, FileType type, ScriptLoad load = ScriptLoad.Normal)
        {
            if (type == FileType.Css && load != ScriptLoad.Normal)
            {
                throw new Exception("You can't define load type on CSS files!");
            }

            if (string.IsNullOrEmpty(asset))
            {
                return(HtmlString.Empty);
            }

            switch (type)
            {
            case FileType.Css:
                asset += ".css";
                break;

            case FileType.Js:
                asset += ".js";
                break;

            default:
                throw new ArgumentException($"Unknown type {type}", nameof(type));
            }

            asset = await GetFromManifestAsync(asset);

            return(asset != null
                ? new HtmlString(GetTag(asset, type, load))
                : HtmlString.Empty);
        }
예제 #2
0
        private string GetTag(string file, FileType type, ScriptLoad load)
        {
            var path     = _assetPath + file;
            var loadType = string.Empty;

            switch (load)
            {
            case ScriptLoad.Async:
                loadType += "async";
                break;

            case ScriptLoad.Defer:
                loadType += "defer";
                break;

            case ScriptLoad.AsyncDefer:
                loadType += "async defer";
                break;
            }

            switch (type)
            {
            case FileType.Css:
                return($"<link href=\"{path}\" rel=\"stylesheet\" />");

            case FileType.Js:
                return($"<script src=\"{path}\" {loadType}></script>");

            default:
                throw new ArgumentException($"Unknown type {type}", nameof(type));
            }
        }
    public void LoadInLevelList()
    {
        scriptLoad = gameObject.GetComponent<ScriptLoad>();

        itemList = scriptLoad.levels;
        PopulateList();
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetScriptTagFixture"/> class.
 /// </summary>
 /// <param name="bundle">The bundle name to test against.</param>
 /// <param name="scriptLoad">The script load mode.</param>
 public GetScriptTagFixture(string bundle, ScriptLoad scriptLoad = ScriptLoad.Normal)
     : base(ValidBundleWithExtension, ValidFallbackBundleWithExtension)
 {
     Bundle     = bundle;
     ScriptLoad = scriptLoad;
     SetupGetFromManifest();
     SetupBuildScriptTag(ValidBundleResult, ScriptTag);
     SetupBuildScriptTag(ValidFallbackBundleResult, FallbackScriptTag);
 }
예제 #5
0
        /// <summary>
        /// Gets a html script tag for the specified asset.
        /// </summary>
        /// <param name="bundle">The name of the Webpack bundle.</param>
        /// <param name="fallbackBundle">The name of the bundle to fallback to if main bundle does not exist.</param>
        /// <param name="load">Enum for modifying script load behavior.</param>
        /// <returns>An HtmlString containing the html script tag.</returns>
        public async Task <HtmlString> GetScriptTagAsync(string bundle, string?fallbackBundle, ScriptLoad load = ScriptLoad.Normal)
        {
            if (string.IsNullOrEmpty(bundle))
            {
                return(HtmlString.Empty);
            }

            bundle = TryFixJsBundleName(bundle);
            var file = await _manifestService.GetFromManifestAsync(bundle).ConfigureAwait(false);

            if (file == null)
            {
                if (string.IsNullOrEmpty(fallbackBundle))
                {
                    return(HtmlString.Empty);
                }

                fallbackBundle = TryFixJsBundleName(fallbackBundle);
                file           = await _manifestService.GetFromManifestAsync(fallbackBundle).ConfigureAwait(false);
            }

            return(file != null
                ? new HtmlString(_tagBuilder.BuildScriptTag(file, load))
                : HtmlString.Empty);
        }
예제 #6
0
 /// <summary>
 /// Gets a html script tag for the specified asset.
 /// </summary>
 /// <param name="bundle">The name of the Webpack bundle.</param>
 /// <param name="load">Enum for modifying script load behavior.</param>
 /// <returns>An HtmlString containing the html script tag.</returns>
 public async Task <HtmlString> GetScriptTagAsync(string bundle, ScriptLoad load = ScriptLoad.Normal)
 {
     return(await GetScriptTagAsync(bundle, null, load).ConfigureAwait(false));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetScriptTagFixture"/> class.
 /// </summary>
 /// <param name="bundle">The bundle name to test against.</param>
 /// <param name="fallbackBundle">The fallback bundle name to test against.</param>
 /// <param name="scriptLoad">The script load mode.</param>
 public GetScriptTagFixture(string bundle, string fallbackBundle, ScriptLoad scriptLoad = ScriptLoad.Normal)
     : this(bundle, scriptLoad)
 {
     FallbackBundle = fallbackBundle;
 }