From 35440216b3458e5609010a043dded4cc277765eb Mon Sep 17 00:00:00 2001 From: ayende Date: Sat, 9 Feb 2008 20:33:34 +0000 Subject: [PATCH] MR-395 - FileAssemblyViewSourceLoader includes hidden/source control files in operation git-svn-id: https://svn.castleproject.org/svn/castle/trunk@4787 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- .../Castle.MonoRail.Framework.Tests-vs2008.csproj | 3 +- .../Content/zdonotlist.bad | 1 + .../FileAssemblyViewSourceLoaderTestCase.cs | 26 +++++++++++- .../ViewEngines/ViewEngineBaseTestCase.cs | 15 +++---- .../NVelocityViewEngine.cs | 4 +- .../Helpers/FormHelper.cs | 22 ++++++++-- .../Castle.MonoRail.Framework/IViewSourceLoader.cs | 5 ++- .../Views/FileAssemblyViewSourceLoader.cs | 48 ++++++++++++++-------- .../Castle.MonoRail.Views.Brail/BooViewEngine.cs | 8 +++- 9 files changed, 98 insertions(+), 34 deletions(-) create mode 100644 MonoRail/Castle.MonoRail.Framework.Tests/Content/zdonotlist.bad diff --git a/MonoRail/Castle.MonoRail.Framework.Tests/Castle.MonoRail.Framework.Tests-vs2008.csproj b/MonoRail/Castle.MonoRail.Framework.Tests/Castle.MonoRail.Framework.Tests-vs2008.csproj index 129ee9287..b089ebe8c 100644 --- a/MonoRail/Castle.MonoRail.Framework.Tests/Castle.MonoRail.Framework.Tests-vs2008.csproj +++ b/MonoRail/Castle.MonoRail.Framework.Tests/Castle.MonoRail.Framework.Tests-vs2008.csproj @@ -144,6 +144,7 @@ + @@ -259,4 +260,4 @@ copy "$(ProjectDir)\App.config" "$(TargetPath).config" - \ No newline at end of file + diff --git a/MonoRail/Castle.MonoRail.Framework.Tests/Content/zdonotlist.bad b/MonoRail/Castle.MonoRail.Framework.Tests/Content/zdonotlist.bad new file mode 100644 index 000000000..81a3f7659 --- /dev/null +++ b/MonoRail/Castle.MonoRail.Framework.Tests/Content/zdonotlist.bad @@ -0,0 +1 @@ +? diff --git a/MonoRail/Castle.MonoRail.Framework.Tests/Services/FileAssemblyViewSourceLoaderTestCase.cs b/MonoRail/Castle.MonoRail.Framework.Tests/Services/FileAssemblyViewSourceLoaderTestCase.cs index ad7bd5907..7c2866e9e 100644 --- a/MonoRail/Castle.MonoRail.Framework.Tests/Services/FileAssemblyViewSourceLoaderTestCase.cs +++ b/MonoRail/Castle.MonoRail.Framework.Tests/Services/FileAssemblyViewSourceLoaderTestCase.cs @@ -62,10 +62,12 @@ namespace Castle.MonoRail.Framework.Tests.Services string[] views = loader.ListViews("Content"); Assert.IsNotNull(views); - Assert.AreEqual(3, views.Length); + Assert.AreEqual(4, views.Length); Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "contentinassembly.vm", views[0]); Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "notinassembly.vm", views[1]); - Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "contentinassembly.vm", views[2]); + Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "zdonotlist.bad", views[2]); + Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "contentinassembly.vm", views[3]); + foreach(string view in views) { @@ -73,6 +75,26 @@ namespace Castle.MonoRail.Framework.Tests.Services Assert.IsNotNull(loader.GetViewSource(view)); } } + [Test] + public void ListViewsWithOptionalFileExtensions() + { + loader.AddAssemblySource(new AssemblySourceInfo("Castle.MonoRail.Framework.Tests", "Castle.MonoRail.Framework.Tests")); + + string[] views = loader.ListViews("Content",".vm"); + + Assert.IsNotNull(views); + Assert.AreEqual(3, views.Length); + Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "contentinassembly.vm", views[0]); + Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "notinassembly.vm", views[1]); + Assert.AreEqual(@"Content" + Path.DirectorySeparatorChar + "contentinassembly.vm", views[2]); + + + foreach (string view in views) + { + Assert.IsTrue(loader.HasSource(view)); + Assert.IsNotNull(loader.GetViewSource(view)); + } + } } [TestFixture] diff --git a/MonoRail/Castle.MonoRail.Framework.Tests/ViewEngines/ViewEngineBaseTestCase.cs b/MonoRail/Castle.MonoRail.Framework.Tests/ViewEngines/ViewEngineBaseTestCase.cs index a08f4ea28..f9369d791 100644 --- a/MonoRail/Castle.MonoRail.Framework.Tests/ViewEngines/ViewEngineBaseTestCase.cs +++ b/MonoRail/Castle.MonoRail.Framework.Tests/ViewEngines/ViewEngineBaseTestCase.cs @@ -103,12 +103,13 @@ namespace Castle.MonoRail.Framework.Tests throw new NotImplementedException(); } - /// - /// Gets a list of views on the specified directory - /// - /// Directory name - /// - public string[] ListViews(string dirName) + /// + /// Gets a list of views on the specified directory + /// + /// Directory name + /// Optional fileExtensions to include in listing. + /// + public string[] ListViews(string dirName, params string[] fileExtensionsToInclude) { throw new NotImplementedException(); } @@ -279,4 +280,4 @@ namespace Castle.MonoRail.Framework.Tests throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/MonoRail/Castle.MonoRail.Framework.Views.NVelocity/NVelocityViewEngine.cs b/MonoRail/Castle.MonoRail.Framework.Views.NVelocity/NVelocityViewEngine.cs index 9eb95d4ee..0c72a5fbe 100644 --- a/MonoRail/Castle.MonoRail.Framework.Views.NVelocity/NVelocityViewEngine.cs +++ b/MonoRail/Castle.MonoRail.Framework.Views.NVelocity/NVelocityViewEngine.cs @@ -501,7 +501,7 @@ namespace Castle.MonoRail.Framework.Views.NVelocity private void LoadMacros(ExtendedProperties props) { - String[] macros = ViewSourceLoader.ListViews("macros"); + String[] macros = ViewSourceLoader.ListViews("macros",this.ViewFileExtension,this.JSGeneratorFileExtension); ArrayList macroList = new ArrayList(macros); @@ -524,4 +524,4 @@ namespace Castle.MonoRail.Framework.Views.NVelocity props.AddProperty(RuntimeConstants.VM_LIBRARY_AUTORELOAD, true); } } -} \ No newline at end of file +} diff --git a/MonoRail/Castle.MonoRail.Framework/Helpers/FormHelper.cs b/MonoRail/Castle.MonoRail.Framework/Helpers/FormHelper.cs index e2e2c13ff..554b701a4 100644 --- a/MonoRail/Castle.MonoRail.Framework/Helpers/FormHelper.cs +++ b/MonoRail/Castle.MonoRail.Framework/Helpers/FormHelper.cs @@ -1189,9 +1189,25 @@ namespace Castle.MonoRail.Framework.Helpers #endregion - #region LabelFor - - /// + #region LiteralFor + + ///Returns the value for specified target with no additional markup. If no value is obtained + /// an empty string is returned. + /// + ///The object to get the value from. + ///The value or an empty string if none is found. + public virtual string LiteralFor(string target) + { + target = RewriteTargetIfWithinObjectScope(target); + object value = ObtainValue(target); + if(value==null) + return string.Empty; + return value.ToString(); + } + #endregion + #region LabelFor + + /// /// Generates a label element. /// /// The object to get the value from and to be based on to create the element name. diff --git a/MonoRail/Castle.MonoRail.Framework/IViewSourceLoader.cs b/MonoRail/Castle.MonoRail.Framework/IViewSourceLoader.cs index 231f08ae6..5613c04c3 100644 --- a/MonoRail/Castle.MonoRail.Framework/IViewSourceLoader.cs +++ b/MonoRail/Castle.MonoRail.Framework/IViewSourceLoader.cs @@ -42,7 +42,8 @@ namespace Castle.MonoRail.Framework /// /// Directory name /// - String[] ListViews(String dirName); + /// Optional fileExtensions to include in listing. + String[] ListViews(String dirName, params string[] fileExtensionsToInclude); /// /// Gets/sets the root directory of views, obtained from the configuration. @@ -74,5 +75,7 @@ namespace Castle.MonoRail.Framework /// Raised when the view is changed. /// event FileSystemEventHandler ViewChanged; + + } } diff --git a/MonoRail/Castle.MonoRail.Framework/Views/FileAssemblyViewSourceLoader.cs b/MonoRail/Castle.MonoRail.Framework/Views/FileAssemblyViewSourceLoader.cs index 472ec16c8..df44f8481 100644 --- a/MonoRail/Castle.MonoRail.Framework/Views/FileAssemblyViewSourceLoader.cs +++ b/MonoRail/Castle.MonoRail.Framework/Views/FileAssemblyViewSourceLoader.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Text; + namespace Castle.MonoRail.Framework { using System; @@ -105,16 +107,17 @@ namespace Castle.MonoRail.Framework } } - /// - /// Gets a list of views on the specified directory - /// - /// Directory name - /// - public String[] ListViews(String dirName) + /// + /// Gets a list of views on the specified directory + /// + /// Directory name + /// Optional fileExtensions to include in listing. + /// + public String[] ListViews(String dirName,params string[] fileExtensionsToInclude) { ArrayList views = new ArrayList(); - CollectViewsOnFileSystem(dirName, views); + CollectViewsOnFileSystem(dirName, views,fileExtensionsToInclude); CollectViewsOnAssemblies(dirName, views); return (String[]) views.ToArray(typeof(String)); @@ -282,17 +285,28 @@ namespace Castle.MonoRail.Framework return null; } - private void CollectViewsOnFileSystem(string dirName, ArrayList views) + private void CollectViewsOnFileSystem(string dirName, ArrayList views,params string[] fileExtensionsToInclude) { DirectoryInfo dir = new DirectoryInfo(Path.Combine(ViewRootDir, dirName)); - - if (dir.Exists) - { - foreach(FileInfo file in dir.GetFiles("*.*")) - { - views.Add(Path.Combine(dirName, file.Name)); - } - } + if(!dir.Exists) + { + return; //early return + } + + + if(fileExtensionsToInclude ==null || fileExtensionsToInclude.Length==0) + { + fileExtensionsToInclude = new string[] {".*"}; + } + + foreach (string ext in fileExtensionsToInclude) + { + foreach (FileInfo file in dir.GetFiles("*" + ext)) + { + views.Add(Path.Combine(dirName, file.Name)); + } + } + } private void CollectViewsOnAssemblies(string dirName, ArrayList views) @@ -303,4 +317,4 @@ namespace Castle.MonoRail.Framework } } } -} \ No newline at end of file +} diff --git a/MonoRail/Castle.MonoRail.Views.Brail/BooViewEngine.cs b/MonoRail/Castle.MonoRail.Views.Brail/BooViewEngine.cs index 10b584304..6f12daee3 100644 --- a/MonoRail/Castle.MonoRail.Views.Brail/BooViewEngine.cs +++ b/MonoRail/Castle.MonoRail.Views.Brail/BooViewEngine.cs @@ -269,6 +269,12 @@ namespace Castle.MonoRail.Views.Brail private void OnViewChanged(object sender, FileSystemEventArgs e) { + + if (Path.GetExtension(e.FullPath).IndexOf(this.ViewFileExtension) == -1 && + Path.GetExtension(e.FullPath).IndexOf(this.JSGeneratorFileExtension) == -1) + { + return;//early return since only watching view extensions and jsgenerator extensions + } string path = e.FullPath.Substring(ViewRootDir.Length); if (path.Length > 0 && (path[0] == Path.DirectorySeparatorChar || path[0] == Path.AltDirectorySeparatorChar)) @@ -502,7 +508,7 @@ namespace Castle.MonoRail.Views.Brail // use the System.IO.Path to get the folder name even though // we are using the ViewSourceLoader to load the actual file string directory = Path.GetDirectoryName(filename); - foreach (string file in ViewSourceLoader.ListViews(directory)) + foreach (string file in ViewSourceLoader.ListViews(directory, this.ViewFileExtension, this.JSGeneratorFileExtension)) { ICompilerInput input = CreateInput(file); input2FileName.Add(input, file); -- 2.11.4.GIT