public static AssetTagPlan For(MimeType mimeType, params IAssetTagSubject[] subjects) { var plan = new AssetTagPlan(mimeType); plan.AddSubjects(subjects); return plan; }
public void only_group_by_the_same_folder() { var files = new AssetFile[]{ new AssetFile("a.css"), new AssetFile("b.css"), new AssetFile("f1/c.css"), new AssetFile("f1/d.css"), new AssetFile("e.css"), new AssetFile("f2/f.css"), new AssetFile("f2/g.css") }; var plan = new AssetTagPlan(MimeType.Css, files); var policy = new CombineAllStylesheets(); var combos = policy.DetermineCombinations(plan); combos.Count().ShouldEqual(3); combos.ElementAt(0).Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("a.css", "b.css"); combos.ElementAt(1).Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("f1/c.css", "f1/d.css"); combos.ElementAt(1).ShouldBeOfType<StyleFileCombination>().Name.ShouldStartWith("f1/"); combos.ElementAt(2).Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("f2/f.css", "f2/g.css"); combos.ElementAt(2).ShouldBeOfType<StyleFileCombination>().Name.ShouldStartWith("f2/"); }
public override void TryToReplaceWithCombinations(AssetTagPlan plan) { var mimeTypePolicies = policies.Where(x => x.MimeType == plan.MimeType); mimeTypePolicies.Each(p => ExecutePolicy(plan, p)); base.TryToReplaceWithCombinations(plan); }
private void applyPoliciesToDiscoverPotentialCombinations(AssetTagPlan plan) { IEnumerable<ICombinationPolicy> mimeTypePolicies = _policies.Where(x => x.MimeType == plan.MimeType); IEnumerable<ICombinationPolicy> combinationPolicies = _cache.OrderedCombinationCandidatesFor(plan.MimeType).Union(mimeTypePolicies); combinationPolicies.Each(policy => ExecutePolicy(plan, policy)); }
private void applyPoliciesToDiscoverPotentialCombinations(AssetTagPlan plan) { var mimeTypePolicies = _policies.Where(x => x.MimeType == plan.MimeType); var combinationPolicies = _cache.OrderedCombinationCandidatesFor(plan.MimeType).Union(mimeTypePolicies); combinationPolicies.Each(policy => ExecutePolicy(plan, policy)); }
private static void validateMatchingMimetypes(MimeType mimeType, AssetTagPlan plan, IEnumerable<string> names) { if (plan.Subjects.Any(x => x.MimeType != mimeType)) { var message = "Files {0} have mixed mimetype's".ToFormat(names.Join(", ")); throw new MixedMimetypeException(message); } }
public static AssetTagPlan For(MimeType mimeType, params IAssetTagSubject[] subjects) { var plan = new AssetTagPlan(mimeType); plan.AddSubjects(subjects); return(plan); }
public void negative_match_because_the_mimetype_is_all_wrong() { var assetFiles = new []{_files["a"], _files["b"]}; var thePlan = new AssetTagPlan(MimeType.Css, assetFiles); var theCandidate = new CombinationCandidate(MimeType.Javascript, "c1", assetFiles); theCandidate.DetermineCombinations(thePlan).Any().ShouldBeFalse(); }
public virtual void ExecutePolicy(AssetTagPlan plan, ICombinationPolicy policy) { policy.DetermineCombinations(plan).Each(combo => { _cache.StoreCombination(plan.MimeType, combo); //plan.TryCombination(combo); }); }
public virtual void ExecutePolicy(AssetTagPlan plan, ICombinationPolicy policy) { policy.DetermineCombinations(plan).Each(combo => { _cache.StoreCombination(plan.MimeType, combo); //plan.TryCombination(combo); }); }
public IEnumerable<AssetFileCombination> DetermineCombinations(AssetTagPlan plan) { var grouper = new AssetGrouper<IAssetTagSubject>(); var groups = grouper.GroupSubjects(plan.Subjects, s => s is AssetFile) .Where(x => x.Count > 1); foreach (var @group in groups) { yield return new ScriptFileCombination(@group.Cast<AssetFile>().ToList()); } }
public IEnumerable <AssetFileCombination> DetermineCombinations(AssetTagPlan plan) { var grouper = new AssetGrouper <IAssetTagSubject>(); var groups = grouper.GroupSubjects(plan.Subjects, s => s is AssetFile) .Where(x => x.Count > 1); foreach (var @group in groups) { yield return(new ScriptFileCombination(@group.Cast <AssetFile>().ToList())); } }
public IEnumerable<HtmlTag> Build(AssetTagPlan plan) { var missingSubjects = plan.RemoveMissingAssets(); var func = _builders[plan.MimeType]; Func<IAssetTagSubject, HtmlTag> builder = s => { var url = AssetContentHandler.DetermineAssetUrl(s); return func(s, url); }; var missingTags = _missingHandler.BuildTagsAndRecord(missingSubjects); var assetTags = plan.Subjects.Select(builder); return missingTags.Union(assetTags); }
public IEnumerable<AssetFileCombination> DetermineCombinations(AssetTagPlan plan) { var folders = plan.Subjects.OfType<AssetFile>().Select(x => x.ContentFolder()).Distinct(); foreach (var folder in folders) { var grouper = new AssetGrouper<IAssetTagSubject>(); var groups = grouper.GroupSubjects(plan.Subjects, s => s is AssetFile && s.As<AssetFile>().ContentFolder() == folder) .Where(x => x.Count > 1); foreach (var @group in groups) { yield return new StyleFileCombination(folder, @group.Cast<AssetFile>().ToList()); } } }
public AssetTagPlan BuildPlan(MimeType mimeType, IEnumerable<string> names) { var plan = new AssetTagPlan(mimeType); plan.AddSubjects(FindSubjects(names)); validateMatchingMimetypes(mimeType, plan, names); if (plan.Subjects.Count == 1) { return plan; } _combinations.TryToReplaceWithCombinations(plan); return plan; }
public IEnumerable <AssetFileCombination> DetermineCombinations(AssetTagPlan plan) { var folders = plan.Subjects.OfType <AssetFile>().Select(x => x.ContentFolder()).Distinct(); foreach (var folder in folders) { var grouper = new AssetGrouper <IAssetTagSubject>(); var groups = grouper.GroupSubjects(plan.Subjects, s => s is AssetFile && s.As <AssetFile>().ContentFolder() == folder) .Where(x => x.Count > 1); foreach (var @group in groups) { yield return(new StyleFileCombination(folder, @group.Cast <AssetFile>().ToList())); } } }
public void apply_to_an_asset_tag_plan_simple_condition_of_all_files() { var files = new AssetFile[]{ new AssetFile("a.js"), new AssetFile("b.js"), new AssetFile("c.js"), new AssetFile("d.js") }; var plan = new AssetTagPlan(MimeType.Javascript, files); var policy = new CombineAllScriptFiles(); var combo = policy.DetermineCombinations(plan).Single(); combo.Files.ShouldHaveTheSameElementsAs(files); }
public IEnumerable<HtmlTag> Build(AssetTagPlan plan) { // This will happen when a user tries to request an asset set // with no assets -- think optional sets if (!plan.Subjects.Any()) { return new HtmlTag[0]; } IEnumerable<MissingAssetTagSubject> missingSubjects = plan.RemoveMissingAssets(); Func<IAssetTagSubject, string, HtmlTag> func = _builders[plan.MimeType]; Func<IAssetTagSubject, HtmlTag> builder = s => { string url = _urls.UrlForAsset(s.Folder, s.Name); return func(s, url); }; IEnumerable<HtmlTag> missingTags = _missingHandler.BuildTagsAndRecord(missingSubjects); IEnumerable<HtmlTag> assetTags = plan.Subjects.Select(builder); return missingTags.Union(assetTags); }
public void skip_over_non_files_in_the_plan() { var files = new IAssetTagSubject[]{ new AssetFile("a.js"), new AssetFile("b.js"), new MissingAssetTagSubject("something.wrong"), new AssetFile("c.js"), new AssetFile("d.js") , new MissingAssetTagSubject("else.wrong"), new AssetFile("e.js") }; var plan = new AssetTagPlan(MimeType.Javascript); plan.AddSubjects(files); var combos = new CombineAllScriptFiles().DetermineCombinations(plan); combos.Count().ShouldEqual(2); combos.First().Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("a.js", "b.js"); combos.Last().Files.Select(x => x.Name).ShouldHaveTheSameElementsAs("c.js", "d.js"); }
public IEnumerable <AssetFileCombination> DetermineCombinations(AssetTagPlan plan) { if (plan.MimeType != MimeType) { yield break; } foreach (var assetFile in _files) { var sequence = plan.TryFindSequenceStartingWith(assetFile, _files.Count); if (sequence == null) { continue; } if (_files.All(sequence.Contains)) { yield return(_combinationBuilder(sequence)); break; } } }
public void TryToReplaceWithCombinations(AssetTagPlan plan) { // That's right, do nothing }
public virtual void TryToReplaceWithCombinations(AssetTagPlan plan) { applyPoliciesToDiscoverPotentialCombinations(plan); TryAllExistingCombinations(plan); }
public void TryAllExistingCombinations(AssetTagPlan plan) { _cache.OrderedListOfCombinations(plan.MimeType).Each(combo => plan.TryCombination(combo)); }
public override void TryToReplaceWithCombinations(AssetTagPlan plan) { policies.Each(p => ExecutePolicy(plan, p)); base.TryToReplaceWithCombinations(plan); }
public override void TryToReplaceWithCombinations(AssetTagPlan plan) { policies.Each(p => ExecutePolicy(plan, p)); base.TryToReplaceWithCombinations(plan); }
public IEnumerable<AssetFileCombination> DetermineCombinations(AssetTagPlan plan) { throw new NotImplementedException(); }
public override void TryToReplaceWithCombinations(AssetTagPlan plan) { var mimeTypePolicies = policies.Where(x => x.MimeType == plan.MimeType); mimeTypePolicies.Each(p => ExecutePolicy(plan, p)); base.TryToReplaceWithCombinations(plan); }
public void TryAllExistingCombinations(AssetTagPlan plan) { _cache.OrderedListOfCombinations(plan.MimeType).Each(combo => plan.TryCombination(combo)); }
public virtual void TryToReplaceWithCombinations(AssetTagPlan plan) { applyPoliciesToDiscoverPotentialCombinations(plan); TryAllExistingCombinations(plan); }