From 7348bff6d48b37ba48a2044637c316f61e05bb6e Mon Sep 17 00:00:00 2001 From: ayende Date: Sat, 9 Jun 2007 23:49:34 +0000 Subject: [PATCH] MR-262 - Dynamic components in brail using RenderComponent git-svn-id: https://svn.castleproject.org/svn/castle/trunk@3917 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- .../BrailBugsTestCase.cs | 9 +++++++++ MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs | 21 +++++++++++++++++++++ .../Macros/ComponentMacro.cs | 2 -- .../Controllers/UsingComponentsController.cs | 10 ++++++++++ MonoRail/TestSiteBrail/TestSiteBrail.csproj | 1 + .../Views/usingcomponents/dynamicComponents.brail | 7 +++++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 MonoRail/TestSiteBrail/Views/usingcomponents/dynamicComponents.brail diff --git a/MonoRail/Castle.MonoRail.Views.Brail.Tests/BrailBugsTestCase.cs b/MonoRail/Castle.MonoRail.Views.Brail.Tests/BrailBugsTestCase.cs index a2fb21703..9cafaed8e 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail.Tests/BrailBugsTestCase.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail.Tests/BrailBugsTestCase.cs @@ -29,5 +29,14 @@ namespace Castle.MonoRail.Views.Brail.Tests AssertSuccess(); AssertReplyEqualTo(""); } + + + [Test] + public void MR_262_DynamicComponents() + { + DoGet("usingcomponents/DynamicComponents.rails"); + AssertSuccess(); + AssertReplyEqualTo("default component view picked up automaticallyThis is a view used by a component"); + } } } diff --git a/MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs b/MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs index e80f04568..b829e68a3 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail/BrailBase.cs @@ -298,6 +298,27 @@ namespace Castle.MonoRail.Views.Brail return; viewComponentsParameters.Remove(propertiesToRemove); } + public void RenderComponent(string componentName) + { + RenderComponent(componentName, new Hashtable()); + } + public void RenderComponent(string componentName, IDictionary parameters) + { + BrailViewComponentContext componentContext = + new BrailViewComponentContext(this, null, componentName, OutputStream, + new Hashtable(StringComparer.InvariantCultureIgnoreCase)); + this.AddViewComponentProperties(componentContext.ComponentParameters); + IViewComponentFactory componentFactory = (IViewComponentFactory)this.context.GetService(typeof(IViewComponentFactory)); + ViewComponent component = componentFactory.Create(componentName); + component.Init(this.context, componentContext); + component.Render(); + if (componentContext.ViewToRender != null) + { + this.OutputSubView("/" + componentContext.ViewToRender, componentContext.ComponentParameters); + } + this.RemoveViewComponentProperties(componentContext.ComponentParameters); + + } /// /// Initialize all the properties that a script may need diff --git a/MonoRail/Castle.MonoRail.Views.Brail/Macros/ComponentMacro.cs b/MonoRail/Castle.MonoRail.Views.Brail/Macros/ComponentMacro.cs index 7a53f4e0e..29e1c4ae1 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail/Macros/ComponentMacro.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail/Macros/ComponentMacro.cs @@ -123,8 +123,6 @@ namespace Castle.MonoRail.Views.Brail removeProperties.Arguments.Add(AstUtil.CreateReferenceExpression("componentContext.ComponentParameters")); block.Add(removeProperties); - block.Add(removeProperties); - return block; } diff --git a/MonoRail/TestSiteBrail/Controllers/UsingComponentsController.cs b/MonoRail/TestSiteBrail/Controllers/UsingComponentsController.cs index 1e96976c1..f23615211 100644 --- a/MonoRail/TestSiteBrail/Controllers/UsingComponentsController.cs +++ b/MonoRail/TestSiteBrail/Controllers/UsingComponentsController.cs @@ -30,6 +30,16 @@ namespace Castle.MonoRail.Views.Brail.TestSite.Controllers this.LayoutName = "layout_with_captureFor"; } + public void DynamicComponents() + { + PropertyBag["components"] = new string[] + { + "SimpleInlineViewComponent3", + "SimpleInlineViewComponent2" + }; + + } + public void Index1() { } diff --git a/MonoRail/TestSiteBrail/TestSiteBrail.csproj b/MonoRail/TestSiteBrail/TestSiteBrail.csproj index 9de004ede..e805c8d52 100644 --- a/MonoRail/TestSiteBrail/TestSiteBrail.csproj +++ b/MonoRail/TestSiteBrail/TestSiteBrail.csproj @@ -163,6 +163,7 @@ + diff --git a/MonoRail/TestSiteBrail/Views/usingcomponents/dynamicComponents.brail b/MonoRail/TestSiteBrail/Views/usingcomponents/dynamicComponents.brail new file mode 100644 index 000000000..be40b123b --- /dev/null +++ b/MonoRail/TestSiteBrail/Views/usingcomponents/dynamicComponents.brail @@ -0,0 +1,7 @@ + \ No newline at end of file -- 2.11.4.GIT