public ScriptTag(string mode, Func<string, string> toFullUrl, Asset asset, string defaultUrl = null) : base("script") { // http://stackoverflow.com/a/1288319/75194 Attr("type", "text/javascript"); if (asset == null) { Attr("src", toFullUrl(defaultUrl)); return; } if (asset.CdnUrl.IsNotEmpty()) { Attr("src", asset.CdnUrl); if (asset.FallbackTest.IsNotEmpty() && asset.File != null) { Next = new HtmlTag("script"); var text = "if ({0}) document.write(unescape(\"%3Cscript src='{1}' type='text/javascript'%3E%3C/script%3E\"));".ToFormat(asset.FallbackTest, asset.Url); Next.Encoded(false); Next.Text(text); } return; } var url = asset.Url; if (mode.InDevelopment() && asset.File != null) { url += "?Etag=" + asset.File.Etag(); } Attr("src", toFullUrl(url)); }
public AssetToken(Asset asset) { url = asset.Url; mimetype = asset.MimeType.Value; file = asset.Filename; cdn = asset.CdnUrl; }
public Asset RegisterCdnAsset(CdnAsset cdn) { var file = cdn.File ?? new Uri(cdn.Url).Segments.Last(); var asset = _searches[file]; if (asset == null) { asset = new Asset(cdn.Url) { }; _assets.Add(asset); } asset.CdnUrl = cdn.Url; asset.FallbackTest = cdn.Fallback; return asset; }
private Asset findAsset(string search) { search = search.TrimStart('/'); var alias = _settings.FileForAlias(search); if (alias.IsNotEmpty()) search = alias; var filename = Path.GetFileName(search); var cdn = _settings.FindCdnAsset(search); var files = findFiles(filename).ToArray(); var file = findMatch(files, search); if (file != null) { var asset = new Asset(file); if (cdn != null) { asset.CdnUrl = cdn.Url; asset.FallbackTest = cdn.Fallback; } return asset; } if (cdn != null) { return new Asset(cdn.Url) { CdnUrl = cdn.Url, FallbackTest = cdn.Fallback }; } return null; }
public void SetUp() { theAsset = new Asset(theFile); }
public void Add(Asset asset) { _assets.Add(asset); }
public void SetUp() { FubuMode.Mode("Production"); theAsset = new Asset(theFile); }