public void WildcardIncludeRules() { var batch = new SparkBatchDescriptor(); batch .For <StubController>().Layout("layout").Include("*") .For <StubController>().Layout("ajax").Include("_*"); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(3, descriptors.Count); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}layout.spark", Path.DirectorySeparatorChar)))); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}layout.spark", Path.DirectorySeparatorChar)))); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}_Widget.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}ajax.spark", Path.DirectorySeparatorChar)))); var assembly = _factory.Precompile(batch); Assert.IsNotNull(assembly); Assert.AreEqual(3, assembly.GetTypes().Length); }
private static void PrecompileViews(SparkViewFactory viewFactory) { var batch = new SparkBatchDescriptor(); batch .For<HomeController>(); viewFactory.Precompile(batch); }
private static void PrecompileViews(SparkViewFactory viewFactory) { var batch = new SparkBatchDescriptor(); batch.For <HomeController>().For <ManageController>(); viewFactory.Precompile(batch); }
public void BatchFromAssembly() { var batch = new SparkBatchDescriptor() .FromAssemblyNamed("Spark.Tests"); Assert.AreEqual(1, batch.Entries.Count(e => e.ControllerType == typeof(SimplePrecompileController))); Assert.AreEqual(3, batch.Entries.Count(e => e.ControllerType == typeof(ComplexPrecompileController))); }
public override void Install(IDictionary stateSaver) { // figure out all paths based on this assembly in the bin dir var assemblyPath = Parent.GetType().Assembly.Location; var targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll"); var webSitePath = Path.GetDirectoryName(Path.GetDirectoryName(assemblyPath)); var webBinPath = Path.Combine(webSitePath, "bin"); var webFileHack = Path.Combine(webSitePath, "web"); var viewsLocation = Path.Combine(webSitePath, "Views"); if (!string.IsNullOrEmpty(TargetAssemblyFile)) { targetPath = Path.Combine(webBinPath, TargetAssemblyFile); } ISparkSettings settings; if (SettingsInstantiator != null) { settings = SettingsInstantiator(); } else { // this hack enables you to open the web.config as if it was an .exe.config File.Create(webFileHack).Close(); var config = ConfigurationManager.OpenExeConfiguration(webFileHack); File.Delete(webFileHack); // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding AppDomain.CurrentDomain.AssemblyResolve += ((sender, e) => Assembly.LoadFile(Path.Combine(webBinPath, e.Name + ".dll"))); settings = (ISparkSettings)config.GetSection("spark"); } // Finally create an engine with the <spark> settings from the web.config var factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder(viewsLocation) }; // And generate all of the known view/master templates into the target assembly var batch = new SparkBatchDescriptor(targetPath); // create entries for controller attributes in the parent installer's assembly batch.FromAssembly(Parent.GetType().Assembly); // and give the containing installer a change to add entries if (DescribeBatch != null) { DescribeBatch(this, new DescribeBatchEventArgs { Batch = batch }); } factory.Precompile(batch); base.Install(stateSaver); }
public void batch_descriptor_with_multiple_layout_files() { var batch = new SparkBatchDescriptor(); batch.For<BatchController>().Layout("Layout").Layout("AnotherLayout").Include("Index").Include("List.spark"); var assembly = _factory.Precompile(batch); assembly.ShouldNotBeNull(); assembly.GetTypes().ShouldHaveCount(4); }
public List <SparkViewDescriptor> CreateDescriptors(SparkBatchDescriptor batch) { var descriptors = new List <SparkViewDescriptor>(); foreach (var entry in batch.Entries) { descriptors.AddRange(CreateDescriptors(entry)); } return(descriptors); }
public void FileWithoutSparkExtensionAreIgnored() { var batch = new SparkBatchDescriptor(); batch.For <StubController>(); var descriptors = _factory.CreateDescriptors(batch); // no templates Assert.That(descriptors.SelectMany(d => d.Templates).All(t => !t.Contains("Helper"))); }
public void ControllersWithHelpersGenerateAccessors() { var batch = new SparkBatchDescriptor(); batch.For<FooController>().Include("index"); _factory.Engine.ViewFolder = new InMemoryViewFolder { { string.Format("foo{0}index.spark", Path.DirectorySeparatorChar), "<p>foo</p>" } }; var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(1, descriptors.Count); Assert.AreEqual(1, descriptors[0].Accessors.Count); Assert.AreEqual(typeof(FooHelper).FullName + " Foo", descriptors[0].Accessors[0].Property); }
public void batch_descriptor_with_multiple_layout_files() { var batch = new SparkBatchDescriptor(); batch.For <BatchController>().Layout("Layout").Layout("AnotherLayout").Include("Index").Include("List.spark"); var assembly = _factory.Precompile(batch, "Batch"); assembly.ShouldNotBeNull(); assembly.GetTypes().ShouldHaveCount(4); }
public void BatchForControllerWithSimplePrecompileAttrib() { var batch = new SparkBatchDescriptor() .FromAttributes<SimplePrecompileController>(); Assert.AreEqual(1, batch.Entries.Count); Assert.AreSame(typeof(SimplePrecompileController), batch.Entries[0].ControllerType); Assert.AreEqual(0, batch.Entries[0].ExcludeViews.Count); Assert.AreEqual(0, batch.Entries[0].IncludeViews.Count); Assert.AreEqual(0, batch.Entries[0].LayoutNames.Count); }
private static IList<SparkViewDescriptor> AllKnownDescriptors(SparkViewFactory viewFactory) { //build the batch var batch = new SparkBatchDescriptor(); batch .For<HomeController>().Layout("Application") .For<FirstController>().Layout("Application") .For<SecondController>().Layout("Application") .For<ThirdController>().Layout("Application") .For<FourthController>().Layout("Application") .For<FifthController>().Layout("Application") .For<SixthController>().Layout("Application") .For<SeventhController>().Layout("Application") .For<EigthController>().Layout("Application") .For<NinthController>().Layout("Application") .For<TenthController>().Layout("Application"); //find all the custom themes var themeMasters = new List<string>(); var themePath = ThemeDirectory + "\\"; var themedMasterFiles = Directory.GetFiles(themePath, "index.html", SearchOption.AllDirectories); foreach (var master in themedMasterFiles) { var themeMasterName = master.Remove(0, themePath.Length); themeMasters.Add(themeMasterName); } //adjust the batch to precompile for each custom theme var generatedDescriptors = viewFactory.CreateDescriptors(batch); var allDescriptors = new List<SparkViewDescriptor>(); foreach (var descriptor in generatedDescriptors) { allDescriptors.Add(descriptor); var isAppMaster = descriptor.Templates.Any(x => x.Contains("Application")); if (!isAppMaster) continue; foreach (var themeMaster in themeMasters) { var themeDescriptor = new SparkViewDescriptor() .SetLanguage(descriptor.Language) .SetTargetNamespace(descriptor.TargetNamespace) .AddTemplate(descriptor.Templates[0]); themeDescriptor.AddTemplate(themeMaster); allDescriptors.Add(themeDescriptor); } } return allDescriptors; }
public void BatchForControllerWithSimplePrecompileAttrib() { var batch = new SparkBatchDescriptor() .FromAttributes <SimplePrecompileController>(); Assert.AreEqual(1, batch.Entries.Count); Assert.AreSame(typeof(SimplePrecompileController), batch.Entries[0].ControllerType); Assert.AreEqual(0, batch.Entries[0].ExcludeViews.Count); Assert.AreEqual(0, batch.Entries[0].IncludeViews.Count); Assert.AreEqual(0, batch.Entries[0].LayoutNames.Count); }
public void MultipleLayoutFiles() { var batch = new SparkBatchDescriptor(); batch .For <StubController>().Layout("default").Layout("alternate").Include("Index").Include("List.spark"); var assembly = _factory.Precompile(batch); Assert.IsNotNull(assembly); Assert.AreEqual(4, assembly.GetTypes().Length); }
private void DescribeCustomSparkViews(SparkBatchDescriptor batch, Assembly sourceAsm) { string rules = _arguments.Rules; if (rules != null) { var rulesTypeName = rules.Substring(0, rules.LastIndexOf('.')); var rulesMethodName = rules.Substring(rules.LastIndexOf('.') + 1); var rulesType = sourceAsm.GetType(rulesTypeName, true); rulesType.InvokeMember(rulesMethodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, new object[] {batch}); } }
public void can_compile_spark_batch_descriptor() { var batch = new SparkBatchDescriptor(); batch .For <BatchController>().Layout("Layout").Include("Index").Include("List.spark") .For <BatchController>().Layout("ElementLayout").Include("_row"); var assembly = _factory.Precompile(batch, "Batch"); Assert.IsNotNull(assembly); Assert.AreEqual(3, assembly.GetTypes().Length); }
public void CompileBatchDescriptor() { var batch = new SparkBatchDescriptor(); batch .For<StubController>().Layout("default").Include("Index").Include("List.spark") .For<StubController>().Layout("ajax").Include("_Widget"); var assembly = _factory.Precompile(batch); Assert.IsNotNull(assembly); Assert.AreEqual(3, assembly.GetTypes().Length); }
public void DefaultMatchingRules() { var batch = new SparkBatchDescriptor(); batch.For <StubController>(); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(2, descriptors.Count); Assert.AreEqual(1, descriptors[0].Templates.Count); Assert.AreEqual(1, descriptors[1].Templates.Count); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\Index.spark"))); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\List.spark"))); }
public void ExcludeRules() { var batch = new SparkBatchDescriptor(); batch.For<StubController>().Include("*").Include("_*").Exclude("In*"); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(2, descriptors.Count); Assert.AreEqual(1, descriptors[0].Templates.Count); Assert.AreEqual(1, descriptors[1].Templates.Count); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\_Widget.spark"))); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\List.spark"))); }
public void DefaultMatchingRules() { var batch = new SparkBatchDescriptor(); batch.For<StubController>(); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(2, descriptors.Count); Assert.AreEqual(1, descriptors[0].Templates.Count); Assert.AreEqual(1, descriptors[1].Templates.Count); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\Index.spark"))); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\List.spark"))); }
public void batch_descriptor_with_default_matching_rules() { var batch = new SparkBatchDescriptor(); batch.For <BatchController>(); var descriptors = _factory.CreateDescriptors(batch, "Batch"); descriptors.ShouldHaveCount(2); descriptors[0].Templates.ShouldHaveCount(1); descriptors[1].Templates.ShouldHaveCount(1); descriptors.Any(descriptor => descriptor.Templates.Contains("Batch\\Index.spark")).ShouldBeTrue(); descriptors.Any(descriptor => descriptor.Templates.Contains("Batch\\List.spark")).ShouldBeTrue(); }
public void CompileBatchDescriptor() { var batch = new SparkBatchDescriptor(); batch .For <StubController>().Layout("layout").Include("Index").Include("List.spark") .For <StubController>().Layout("ajax").Include("_Widget"); var assembly = _factory.Precompile(batch); Assert.IsNotNull(assembly); Assert.AreEqual(3, assembly.GetTypes().Length); }
public void batch_descriptor_with_exclude_rules() { var batch = new SparkBatchDescriptor(); batch.For <BatchController>().Include("*").Include("_*").Exclude("In*"); var descriptors = _factory.CreateDescriptors(batch, "Batch"); descriptors.ShouldHaveCount(2); descriptors[0].Templates.ShouldHaveCount(1); descriptors[1].Templates.ShouldHaveCount(1); descriptors.Any(descriptor => descriptor.Templates.Contains("Batch\\_row.spark")).ShouldBeTrue(); descriptors.Any(descriptor => descriptor.Templates.Contains("Batch\\List.spark")).ShouldBeTrue(); }
public void ExcludeRules() { var batch = new SparkBatchDescriptor(); batch.For <StubController>().Include("*").Include("_*").Exclude("In*"); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(2, descriptors.Count); Assert.AreEqual(1, descriptors[0].Templates.Count); Assert.AreEqual(1, descriptors[1].Templates.Count); Assert.That(descriptors.Any(d => d.Templates.Contains(string.Format("Stub{0}_Widget.spark", Path.DirectorySeparatorChar)))); Assert.That(descriptors.Any(d => d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)))); }
public void DefaultMatchingRules() { var batch = new SparkBatchDescriptor(); batch.For <StubController>(); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(2, descriptors.Count); Assert.AreEqual(1, descriptors[0].Templates.Count); Assert.AreEqual(1, descriptors[1].Templates.Count); Assert.That(descriptors.Any(d => d.Templates.Contains(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar)))); Assert.That(descriptors.Any(d => d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)))); }
public void ControllersWithHelpersGenerateAccessors() { var batch = new SparkBatchDescriptor(); batch.For <FooController>().Include("index"); _factory.Engine.ViewFolder = new InMemoryViewFolder { { string.Format("foo{0}index.spark", Path.DirectorySeparatorChar), "<p>foo</p>" } }; var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(1, descriptors.Count); Assert.AreEqual(1, descriptors[0].Accessors.Count); Assert.AreEqual(typeof(FooHelper).FullName + " Foo", descriptors[0].Accessors[0].Property); }
public void ExcludeRules() { var batch = new SparkBatchDescriptor(); batch.For <StubController>().Include("*").Include("_*").Exclude("In*"); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(2, descriptors.Count); Assert.AreEqual(2, descriptors[0].Templates.Count); Assert.AreEqual(2, descriptors[1].Templates.Count); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\_Widget.spark") && d.Templates.Contains("Shared\\ajax.spark"))); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\List.spark") && d.Templates.Contains("Shared\\default.spark"))); }
public void batch_descriptor_with_exclude_rules() { var batch = new SparkBatchDescriptor(); batch.For<BatchController>().Include("*").Include("_*").Exclude("In*"); var descriptors = _factory.CreateDescriptors(batch); descriptors.ShouldHaveCount(2); descriptors[0].Templates.ShouldHaveCount(1); descriptors[1].Templates.ShouldHaveCount(1); descriptors.Any(descriptor => descriptor.Templates.Contains("Batch\\_row.spark")).ShouldBeTrue(); descriptors.Any(descriptor => descriptor.Templates.Contains("Batch\\List.spark")).ShouldBeTrue(); }
public void batch_descriptor_with_default_matching_rules() { var batch = new SparkBatchDescriptor(); batch.For<BatchController>(); var descriptors = _factory.CreateDescriptors(batch); descriptors.ShouldHaveCount(2); descriptors[0].Templates.ShouldHaveCount(1); descriptors[1].Templates.ShouldHaveCount(1); descriptors.Any(descriptor => descriptor.Templates.Contains("Batch\\Index.spark")).ShouldBeTrue(); descriptors.Any(descriptor => descriptor.Templates.Contains("Batch\\List.spark")).ShouldBeTrue(); }
public void Precompile() { var settings = new SparkSettings(); var factory = new SparkViewFactory(settings) { ViewFolder = new FileSystemViewFolder("AspNetMvc.Tests.Views") }; var batch = new SparkBatchDescriptor(); batch.For <FailureController>(); factory.Precompile(batch); }
public void BatchForControllerWithComplexPrecompileAttrib() { var batch = new SparkBatchDescriptor() .FromAttributes <ComplexPrecompileController>(); Assert.AreEqual(3, batch.Entries.Count); var forDefault = batch.Entries.First(e => e.LayoutNames[0][0] == "Default"); var forAjax = batch.Entries.First(e => e.LayoutNames[0][0] == "Ajax"); var forShowing = batch.Entries.First(e => e.LayoutNames[0][0] == "Showing"); Assert.AreEqual(0, forDefault.IncludeViews.Count); Assert.AreEqual(1, forDefault.ExcludeViews.Count); Assert.AreEqual(2, forAjax.IncludeViews.Count); Assert.AreEqual(0, forAjax.ExcludeViews.Count); Assert.AreEqual(1, forShowing.IncludeViews.Count); Assert.AreEqual(0, forShowing.ExcludeViews.Count); }
public void BatchForControllerWithComplexPrecompileAttrib() { var batch = new SparkBatchDescriptor() .FromAttributes<ComplexPrecompileController>(); Assert.AreEqual(3, batch.Entries.Count); var forDefault = batch.Entries.First(e => e.LayoutNames[0][0] == "Default"); var forAjax = batch.Entries.First(e => e.LayoutNames[0][0] == "Ajax"); var forShowing = batch.Entries.First(e => e.LayoutNames[0][0] == "Showing"); Assert.AreEqual(0, forDefault.IncludeViews.Count); Assert.AreEqual(1, forDefault.ExcludeViews.Count); Assert.AreEqual(2, forAjax.IncludeViews.Count); Assert.AreEqual(0, forAjax.ExcludeViews.Count); Assert.AreEqual(1, forShowing.IncludeViews.Count); Assert.AreEqual(0, forShowing.ExcludeViews.Count); }
public void FileWithoutSparkExtensionAreIgnored() { _factory.ViewFolder = new InMemoryViewFolder { { string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar), "<p>index</p>" }, { string.Format("Stub{0}Helper.cs", Path.DirectorySeparatorChar), "// this is a code file" }, { string.Format("Layouts{0}Stub.spark", Path.DirectorySeparatorChar), "<p>layout</p><use:view/>" }, }; var batch = new SparkBatchDescriptor(); batch.For <StubController>(); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(1, descriptors.Count); Assert.AreEqual(2, descriptors[0].Templates.Count); Assert.AreEqual(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar), descriptors[0].Templates[0]); Assert.AreEqual(string.Format("Layouts{0}Stub.spark", Path.DirectorySeparatorChar), descriptors[0].Templates[1]); }
public void files_without_spark_extension_should_be_ignored() { _factory.ViewFolder = new InMemoryViewFolder { { "Batch\\Index.spark", "<p>index</p>" }, { "Batch\\Foo.cs", "// some c# code" }, { "Layouts\\Batch.spark", "<p>layout</p><use:view/>" }, }; var batch = new SparkBatchDescriptor(); batch.For <BatchController>(); var descriptors = _factory.CreateDescriptors(batch, "Batch"); descriptors.ShouldHaveCount(1); descriptors[0].Templates.ShouldHaveCount(2); descriptors[0].Templates[0].ShouldEqual("Batch\\Index.spark"); descriptors[0].Templates[1].ShouldEqual("Layouts\\Batch.spark"); }
public void batch_descriptor_with_wildcard_include_rules() { var batch = new SparkBatchDescriptor(); batch .For<BatchController>().Layout("Layout").Include("*") .For<BatchController>().Layout("ElementLayout").Include("_*"); var descriptors = _factory.CreateDescriptors(batch); descriptors.ShouldHaveCount(3); descriptors.Any(d => d.Templates.Contains("Batch\\Index.spark") && d.Templates.Contains("Shared\\Layout.spark")).ShouldBeTrue(); descriptors.Any(d => d.Templates.Contains("Batch\\List.spark") && d.Templates.Contains("Shared\\Layout.spark")).ShouldBeTrue(); descriptors.Any(d => d.Templates.Contains("Batch\\_row.spark") && d.Templates.Contains("Shared\\ElementLayout.spark")).ShouldBeTrue(); var assembly = _factory.Precompile(batch); assembly.ShouldNotBeNull(); assembly.GetTypes().ShouldHaveCount(3); }
private static IEnumerable<SparkViewDescriptor> RootThemableDescriptors(SparkViewFactory viewFactory) { var batch = new SparkBatchDescriptor(); batch //Guest Interface .For<SparkDynamicTheme.Controllers.HomeController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.FirstController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.SecondController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.ThirdController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.FourthController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.FifthController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.SixthController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.SeventhController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.EigthController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.NinthController>().Layout(ApplicationLayout) .For<SparkDynamicTheme.Controllers.TenthController>().Layout(ApplicationLayout); return viewFactory.CreateDescriptors(batch); }
public void batch_descriptor_with_wildcard_include_rules() { var batch = new SparkBatchDescriptor(); batch .For <BatchController>().Layout("Layout").Include("*") .For <BatchController>().Layout("ElementLayout").Include("_*"); var descriptors = _factory.CreateDescriptors(batch, "Batch"); descriptors.ShouldHaveCount(3); descriptors.Any(d => d.Templates.Contains("Batch\\Index.spark") && d.Templates.Contains("Shared\\Layout.spark")).ShouldBeTrue(); descriptors.Any(d => d.Templates.Contains("Batch\\List.spark") && d.Templates.Contains("Shared\\Layout.spark")).ShouldBeTrue(); descriptors.Any(d => d.Templates.Contains("Batch\\_row.spark") && d.Templates.Contains("Shared\\ElementLayout.spark")).ShouldBeTrue(); var assembly = _factory.Precompile(batch, "Batch"); assembly.ShouldNotBeNull(); assembly.GetTypes().ShouldHaveCount(3); }
public void WildcardIncludeRules() { var batch = new SparkBatchDescriptor(); batch .For <StubController>().Layout("default").Include("*") .For <StubController>().Layout("ajax").Include("_*"); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(3, descriptors.Count); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\Index.spark") && d.Templates.Contains("Shared\\default.spark"))); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\List.spark") && d.Templates.Contains("Shared\\default.spark"))); Assert.That(descriptors.Any(d => d.Templates.Contains("Stub\\_Widget.spark") && d.Templates.Contains("Shared\\ajax.spark"))); var assembly = _factory.Precompile(batch); Assert.IsNotNull(assembly); Assert.AreEqual(3, assembly.GetTypes().Length); }
public void DefaultEntryBehavior() { var batch = new SparkBatchDescriptor(); batch.For<StubController>(); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(2, descriptors.Count); Assert.AreEqual(2, descriptors[0].Templates.Count); Assert.AreEqual(2, descriptors[1].Templates.Count); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); }
public void Compile(Assembly sourceAsm) { var sparkViewFactory = new SparkViewFactory(GetSparkSettings()) { ViewFolder = new FileSystemViewFolder(EnsureDirectoryExists(_arguments.Views)) }; var batch = new SparkBatchDescriptor(GetOutputDllFullPath()); batch.FromAssembly(sourceAsm); DescribeSparkViews(batch, sourceAsm); DescribeCustomSparkViews(batch, sourceAsm); sparkViewFactory.DescriptorBuilder = new AutoMasterDescriptorBuilder(sparkViewFactory.Engine); try { sparkViewFactory.Precompile(batch); } catch (CompilerException e) { File.WriteAllText("arq.CompilerException.txt", e.Message); throw new CompilerException(e.Message.FirstLine() + "\nSee arq.CompilerException.txt for full description"); } }
public Assembly Precompile(SparkBatchDescriptor batch) { return(Engine.BatchCompilation(batch.OutputAssembly, CreateDescriptors(batch))); }
public Assembly Precompile(SparkBatchDescriptor batch, string viewLocatorName) { return(Engine.BatchCompilation(batch.OutputAssembly, CreateDescriptors(batch, viewLocatorName))); }
public void FileWithoutSparkExtensionAreIgnored() { var batch = new SparkBatchDescriptor(); batch.For<StubController>(); var descriptors = _factory.CreateDescriptors(batch); // no templates Assert.That(descriptors.SelectMany(d=>d.Templates).All(t=>!t.Contains("Helper"))); }
public void can_compile_spark_batch_descriptor() { var batch = new SparkBatchDescriptor(); batch .For<BatchController>().Layout("Layout").Include("Index").Include("List.spark") .For<BatchController>().Layout("ElementLayout").Include("_row"); var assembly = _factory.Precompile(batch); Assert.IsNotNull(assembly); Assert.AreEqual(3, assembly.GetTypes().Length); }
public List<SparkViewDescriptor> CreateDescriptors(SparkBatchDescriptor batch, Func<string, string> getActionName) { var descriptors = new List<SparkViewDescriptor>(); foreach (SparkBatchEntry entry in batch.Entries) descriptors.AddRange(CreateDescriptors(entry, getActionName)); return descriptors; }
public void ExcludeRules() { var batch = new SparkBatchDescriptor(); batch.For<StubController>().Include("*").Include("_*").Exclude("In*"); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(2, descriptors.Count); Assert.AreEqual(2, descriptors[0].Templates.Count); Assert.AreEqual(2, descriptors[1].Templates.Count); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}_Widget.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}ajax.spark", Path.DirectorySeparatorChar)))); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); }
public void files_without_spark_extension_should_be_ignored() { _factory.ViewFolder = new InMemoryViewFolder { {"Batch\\Index.spark", "<p>index</p>"}, {"Batch\\Foo.cs", "// some c# code"}, {"Layouts\\Batch.spark", "<p>layout</p><use:view/>"}, }; var batch = new SparkBatchDescriptor(); batch.For<BatchController>(); var descriptors = _factory.CreateDescriptors(batch); descriptors.ShouldHaveCount(1); descriptors[0].Templates.ShouldHaveCount(2); descriptors[0].Templates[0].ShouldEqual("Batch\\Index.spark"); descriptors[0].Templates[1].ShouldEqual("Layouts\\Batch.spark"); }
public Assembly Precompile(SparkBatchDescriptor batch, Func<string, string> getActionName) { return Engine.BatchCompilation(batch.OutputAssembly, CreateDescriptors(batch, getActionName)); }
public List<SparkViewDescriptor> CreateDescriptors(SparkBatchDescriptor batch, string viewLocatorName) { var descriptors = new List<SparkViewDescriptor>(); foreach (var entry in batch.Entries) { descriptors.AddRange(CreateDescriptors(entry, viewLocatorName)); } return descriptors; }
protected void Application_Start() { var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired(); builder.RegisterModelBinders(Assembly.GetExecutingAssembly()); builder.RegisterModule<DomainModule>(); builder.RegisterModule<MessagingModule>(); builder.RegisterModule<ServicesModule>(); builder.RegisterModule<SourceControlModule>(); _containerProvider = new ContainerProvider(builder.Build()); ControllerBuilder.Current.SetControllerFactory(new AutofacControllerFactory(_containerProvider)); var batch = new SparkBatchDescriptor(); batch.For<AccountController>() .For<DashboardController>() .For<ProjectController>(); var viewFactory = new SparkViewFactory(); viewFactory.Precompile(batch); ViewEngines.Engines.Add(viewFactory); AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes); }
public Assembly Precompile(SparkBatchDescriptor batch, string viewLocatorName) { return Engine.BatchCompilation(batch.OutputAssembly, CreateDescriptors(batch, viewLocatorName)); }
public override void Install(IDictionary stateSaver) { // figure out all paths based on this assembly in the bin dir var assemblyPath = Parent.GetType().Assembly.CodeBase.Replace("file:///", ""); var targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll"); var appBinPath = Path.GetDirectoryName(assemblyPath); var appBasePath = Path.GetDirectoryName(appBinPath); var viewPath = ViewPath; if (string.IsNullOrEmpty(viewPath)) { viewPath = "Views"; } if (!Directory.Exists(Path.Combine(appBasePath, viewPath)) && Directory.Exists(Path.Combine(appBinPath, viewPath))) { appBasePath = appBinPath; } var webFileHack = Path.Combine(appBasePath, "web"); var viewsLocation = Path.Combine(appBasePath, viewPath); if (!string.IsNullOrEmpty(TargetAssemblyFile)) { targetPath = Path.Combine(appBinPath, TargetAssemblyFile); } // this hack enables you to open the web.config as if it was an .exe.config File.Create(webFileHack).Close(); var config = ConfigurationManager.OpenExeConfiguration(webFileHack); File.Delete(webFileHack); // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding AppDomain.CurrentDomain.AssemblyResolve += ((sender, e) => Assembly.LoadFile(Path.Combine(appBinPath, e.Name + ".dll"))); var settings = (ISparkSettings)config.GetSection("spark"); var services = new StubMonoRailServices(); services.AddService(typeof(IViewSourceLoader), new FileAssemblyViewSourceLoader(viewsLocation)); services.AddService(typeof(ISparkViewEngine), new SparkViewEngine(settings)); services.AddService(typeof(IControllerDescriptorProvider), services.ControllerDescriptorProvider); var factory = new SparkViewFactory(); factory.Service(services); // And generate all of the known view/master templates into the target assembly var batch = new SparkBatchDescriptor(targetPath); // create entries for controller attributes in the parent installer's assembly batch.FromAssembly(Parent.GetType().Assembly); // and give the containing installer a change to add entries if (DescribeBatch != null) { DescribeBatch(this, new DescribeBatchEventArgs { Batch = batch }); } factory.Precompile(batch); base.Install(stateSaver); }
public static void Main(string[] args) { var location = typeof(AscendApplication).Assembly.Location; string target = Path.ChangeExtension(location, ".Views.dll"); string root = Path.GetDirectoryName(Path.GetDirectoryName(location)); //string webBinPath = Path.Combine (directoryName, "bin"); Console.WriteLine("Precompiling to target: {0}", target); Console.WriteLine("Root folder: {0}", root); try { var factory = new SparkViewFactory(AscendApplication.CreateSparkSettings()); factory.ViewFolder = new VirtualPathCompatableViewFolder(root); factory.Engine.ViewFolder = factory.ViewFolder; var builder = new DefaultDescriptorBuilder(factory.Engine); builder.Filters.Add(new Ascend.Web.AreaDescriptorFilter()); factory.DescriptorBuilder = builder; var batch = new SparkBatchDescriptor(target); batch.FromAssembly(typeof(AscendApplication).Assembly); var descriptors = new List <SparkViewDescriptor>(); foreach (var entry in batch.Entries) { var t = entry.ControllerType; var name = t.Name.Substring(0, t.Name.Length - ("Controller".Length)); var parts = t.Namespace.Split('.'); var area = parts[1 + Array.LastIndexOf(parts, "Areas")]; foreach (var view in factory.ViewFolder.ListViews(Path.Combine(root, "Areas", area, "Views", name))) { var locations = new List <string>(); var descriptor = factory.DescriptorBuilder.BuildDescriptor( new BuildDescriptorParams( t.Namespace, name, Path.GetFileNameWithoutExtension(view), null, true, new Dictionary <string, object> { { "area", area } }), locations); descriptors.Add(descriptor); } } var result = factory.Engine.BatchCompilation(target, descriptors); // var descriptors = factory.CreateDescriptors(batch); // factory.Precompile(batch); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }
public List<SparkViewDescriptor> CreateDescriptors(SparkBatchDescriptor batch) { var descriptors = new List<SparkViewDescriptor>(); foreach (var entry in batch.Entries) descriptors.AddRange(CreateDescriptors(entry)); return descriptors; }
private static void DescribeSparkViews(SparkBatchDescriptor batch, Assembly sourceAsm) { sourceAsm .GetTypes() .Where(type => type.IsSubclassOf(typeof (Controller))).ToList() .ForEach(controllerType => batch.For(controllerType)); }
public Assembly Precompile(SparkBatchDescriptor batch) { return Engine.BatchCompilation(batch.OutputAssembly, CreateDescriptors(batch)); }
public void WildcardIncludeRules() { var batch = new SparkBatchDescriptor(); batch .For<StubController>().Layout("default").Include("*") .For<StubController>().Layout("ajax").Include("_*"); var descriptors = _factory.CreateDescriptors(batch); Assert.AreEqual(3, descriptors.Count); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}Index.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}List.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}default.spark", Path.DirectorySeparatorChar)))); Assert.That( descriptors.Any( d => d.Templates.Contains(string.Format("Stub{0}_Widget.spark", Path.DirectorySeparatorChar)) && d.Templates.Contains(string.Format("Shared{0}ajax.spark", Path.DirectorySeparatorChar)))); var assembly = _factory.Precompile(batch); Assert.IsNotNull(assembly); Assert.AreEqual(3, assembly.GetTypes().Length); }