예제 #1
0
        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));
        }
예제 #2
0
 public AssetToken(Asset asset)
 {
     url = asset.Url;
     mimetype = asset.MimeType.Value;
     file = asset.Filename;
     cdn = asset.CdnUrl;
 }
예제 #3
0
파일: AssetGraph.cs 프로젝트: jrios/fubumvc
        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;
        }
예제 #4
0
        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;
        }
예제 #5
0
 public void SetUp()
 {
     theAsset = new Asset(theFile);
 }
예제 #6
0
 public void Add(Asset asset)
 {
     _assets.Add(asset);
 }
예제 #7
0
 public void SetUp()
 {
     FubuMode.Mode("Production");
     theAsset = new Asset(theFile);
 }