示例#1
0
        private static void applyBatchedNonGlobalTransforms(ContentPlan plan, TransformerRequirements requirements)
        {
            var policy = findBatchedTransformerPolicy(requirements);

            if (policy == null)
            {
                return;
            }


            var groups = new AssetGrouper <IContentSource>()
                         .GroupSubjects(plan.GetAllSources(), source => requirements.IsNextPolicy(source, policy));

            groups.Each(group =>
            {
                if (group.Count == 1)
                {
                    plan.ApplyTransform(group.Single(), policy.TransformerType);
                }
                else
                {
                    var combo = plan.Combine(group);
                    plan.ApplyTransform(combo, policy.TransformerType);
                }

                group.Each(s => requirements.DequeueTransformer(s, policy));
            });
        }
示例#2
0
        private void applyGlobalTransforms(ContentPlan plan)
        {
            var globalPolicies = _library.FindGlobalPoliciesFor(plan.MimeType);
            globalPolicies.Each(policy =>
            {
                if (policy.MustBeBatched())
                {
                    plan.CombineAll();
                }

                plan.GetAllSources().Each(s => plan.ApplyTransform(s, policy.TransformerType));
            });
        }
示例#3
0
        public void constructor_sets_up_the_default_content_sources_for_each_file()
        {
            var files = new AssetFile[]{
                new AssetFile("something.js"){FullPath = "something.js"},
                new AssetFile("something2.js"){FullPath = "something2.js"},
                new AssetFile("something3.js"){FullPath = "something3.js"},
                new AssetFile("something4.js"){FullPath = "something4.js"},
            };

            var plan = new ContentPlan("a plan", files);

            plan.GetAllSources().ShouldHaveTheSameElementsAs(files.Select(x => new FileRead(x)));
        }
        private void applyGlobalTransforms(ContentPlan plan)
        {
            var globalPolicies = _library.FindGlobalPoliciesFor(plan.MimeType);
            globalPolicies.Each(policy =>
            {
                if (policy.MustBeBatched())
                {
                    plan.CombineAll();
                }

                plan.GetAllSources().Each(s => plan.ApplyTransform(s, policy.TransformerType));
            });
        }
示例#5
0
        public void AssertMatches(ContentPlan plan)
        {
            var previewer = new ContentPlanPreviewer();
            plan.AcceptVisitor(previewer);

            try
            {
                previewer.Descriptions.ShouldHaveTheSameElementsAs(_expectations);
            }
            catch (Exception)
            {
                new ContentExpectationWriter(_expectations, previewer.Descriptions.ToList()).Write();

                throw;
            }
        }
示例#6
0
        public void find_for_file_initially()
        {
            var files = new AssetFile[]{
                new AssetFile("something.js"){FullPath = "something.js"},
                new AssetFile("something2.js"){FullPath = "something2.js"},
                new AssetFile("something3.js"){FullPath = "something3.js"},
                new AssetFile("something4.js"){FullPath = "something4.js"},
            };

            var plan = new ContentPlan("a plan", files);

            files.Each(f =>
            {
                plan.FindForFile(f).ShouldBeOfType<FileRead>().Files.Single().ShouldBeTheSameAs(f);
            });
        }
示例#7
0
        public ContentPlan BuildPlanFor(string name)
        {
            var files = FindFiles(name);
            var requirements = new TransformerRequirements(_library);

            var plan = new ContentPlan(name, files);

            applyNonBatchedNonGlobalTransforms(files, plan, requirements);

            applyBatchedNonGlobalTransforms(plan, requirements);

            applyGlobalTransforms(plan);

            combineWhateverIsLeft(plan);

            return plan;
        }
示例#8
0
        public ContentPlan BuildPlanFor(string name)
        {
            var files = FindFiles(name);
            var requirements = new TransformerRequirements(_library);

            var plan = new ContentPlan(name, files);

            applyNonBatchedNonGlobalTransforms(files, plan, requirements);

            applyBatchedNonGlobalTransforms(plan, requirements);

            applyGlobalTransforms(plan);

            combineWhateverIsLeft(plan);

            return plan;
        }
示例#9
0
        private static void applyBatchedNonGlobalTransforms(ContentPlan plan, TransformerRequirements requirements)
        {
            var policy = findBatchedTransformerPolicy(requirements);
            if (policy == null) return;

            var groups = new AssetGrouper<IContentSource>()
                .GroupSubjects(plan.GetAllSources(), source => requirements.IsNextPolicy(source, policy));

            groups.Each(group =>
            {
                if (group.Count == 1)
                {
                    plan.ApplyTransform(group.Single(), policy.TransformerType);
                }
                else
                {
                    var combo = plan.Combine(group);
                    plan.ApplyTransform(combo, policy.TransformerType);
                }

                group.Each(s => requirements.DequeueTransformer(s, policy));
            });
        }
        private static void applyNonBatchedNonGlobalTransforms(IEnumerable<AssetFile> files, ContentPlan plan,
                                                               TransformerRequirements requirements)
        {
            foreach (var file in files)
            {
                var source = plan.FindForFile(file);
                var policies = requirements.PoliciesFor(file);

                while (policies.Any() && !policies.Peek().MustBeBatched())
                {
                    var policy = policies.Dequeue();
                    source = plan.ApplyTransform(source, policy.TransformerType);
                }
            }
        }
示例#11
0
        private static void applyNonBatchedNonGlobalTransforms(IEnumerable<AssetFile> files, ContentPlan plan,
                                                               TransformerRequirements requirements)
        {
            foreach (var file in files)
            {
                var source = plan.FindForFile(file);
                var policies = requirements.PoliciesFor(file);

                while (policies.Any() && !policies.Peek().MustBeBatched())
                {
                    var policy = policies.Dequeue();
                    source = plan.ApplyTransform(source, policy.TransformerType);
                }
            }
        }
示例#12
0
 private static void combineWhateverIsLeft(ContentPlan plan)
 {
     plan.CombineAll();
 }
示例#13
0
        public void SetUp()
        {
            files = new AssetFile[]{
                new AssetFile("something.js"){FullPath = "something.js"},
                new AssetFile("something2.js"){FullPath = "something2.js"},
                new AssetFile("something3.js"){FullPath = "something3.js"},
                new AssetFile("something4.js"){FullPath = "something4.js"},
            };

            thePlan = new ContentPlan("a plan", files);
            theCombination = thePlan.Combine(new[] { thePlan.GetAllSources().ElementAt(0), thePlan.GetAllSources().ElementAt(1) });
        }
        public void try_it_against_a_3_deep_hierarchy()
        {
            var theFiles = new AssetFile[]{
                new AssetFile("a.js"){FullPath = "a.js"},
                new AssetFile("b.js"){FullPath = "b.js"},
                new AssetFile("c.js"){FullPath = "c.js"},
                new AssetFile("d.js"){FullPath = "d.js"},
            };

            var plan = new ContentPlan("something", theFiles);
            var read0 = plan.GetAllSources().ElementAt(0);
            var read1 = plan.GetAllSources().ElementAt(1);
            var read2 = plan.GetAllSources().ElementAt(2);
            var read3 = plan.GetAllSources().ElementAt(3);

            var combo1 = plan.Combine(new IContentSource[] { read1, read2 });
            var combo2 = plan.Combine(new IContentSource[] { read0, combo1, read3 });

            var previewer = new ContentPlanPreviewer();
            plan.AcceptVisitor(previewer);

            previewer.WriteToDebug();

            var expected = new StringBuilder()
                .AppendLine("Combination")
                .AppendLine("  FileRead:a.js")
                .AppendLine("  Combination")
                .AppendLine("    FileRead:b.js")
                .AppendLine("    FileRead:c.js")
                .Append("  FileRead:d.js");

            previewer.ToFullDescription().ShouldEqual(expected);
        }
 public ContentPlanShouldBeExpression(ContentPlan plan)
 {
     _plan = plan;
 }
 private static void combineWhateverIsLeft(ContentPlan plan)
 {
     plan.CombineAll();
 }
示例#17
0
        public void SetUp()
        {
            files = new AssetFile[]{
                new AssetFile("something.js"){FullPath = "something.js"},
                new AssetFile("something2.js"){FullPath = "something2.js"},
                new AssetFile("something3.js"){FullPath = "something3.js"},
                new AssetFile("something4.js"){FullPath = "something4.js"},
            };

            thePlan = new ContentPlan("a plan", files);
            theReadFileSource = thePlan.GetAllSources().ElementAt(2);
            theTransformerNode = thePlan.ApplyTransform(theReadFileSource, typeof(StubTransformer));
        }