Changeset 231
- Timestamp:
- 11/12/08 17:59:25 (2 months ago)
- Files:
-
- branches/scripting/spark.build (modified) (1 diff)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/App_Data (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/App_Data/Products.xml (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Controllers (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Controllers/HomeController.cs (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Default.aspx (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Global.asax (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Global.asax.cs (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Global.cs (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/IronPythonViews.csproj (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Models (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Models/Product.cs (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Models/ProductRepository.cs (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Properties (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Properties/AssemblyInfo.cs (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Views (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Views/Home (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Views/Home/Index.spark (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Views/Layouts (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Views/Layouts/Application.spark (added)
- branches/scripting/src/Samples/AspNetMvc/IronPythonViews/Web.config (added)
- branches/scripting/src/Samples/PythonViewLanguage/Global.cs (modified) (1 diff)
- branches/scripting/src/Samples/PythonViewLanguage/HtmlHelperExtension.cs (deleted)
- branches/scripting/src/Samples/PythonViewLanguage/PythonViewLanguage.csproj (modified) (1 diff)
- branches/scripting/src/Samples/Samples.sln (modified) (3 diffs)
- branches/scripting/src/Spark.Scripting.Tests/PythonViewCompilerTests.cs (modified) (6 diffs)
- branches/scripting/src/Spark.Scripting/Compiler/Python/ChunkVisitors/GeneratedCodeVisitor.cs (modified) (1 diff)
- branches/scripting/src/Spark.Scripting/Compiler/Python/PythonViewCompiler.cs (modified) (3 diffs)
- branches/scripting/src/Spark.Web.Mvc.Scripting (added)
- branches/scripting/src/Spark.Web.Mvc.Scripting/Properties (added)
- branches/scripting/src/Spark.Web.Mvc.Scripting/Properties/AssemblyInfo.cs (added)
- branches/scripting/src/Spark.Web.Mvc.Scripting/ScriptingLanguageFactoryWithExtensions.cs (added)
- branches/scripting/src/Spark.Web.Mvc.Scripting/Spark.Web.Mvc.Scripting.csproj (added)
- branches/scripting/src/Spark.Web.Mvc.Scripting/SparkPythonEngineStarter.cs (added)
- branches/scripting/src/Spark.Web.Mvc/Spark.Web.Mvc.csproj (modified) (2 diffs)
- branches/scripting/src/Spark.Web.Mvc/SparkEngineStarter.cs (added)
- branches/scripting/src/Spark.sln (modified) (3 diffs)
- branches/scripting/src/Spark/Compiler/ForEachInspector.cs (modified) (1 diff)
- branches/scripting/src/Spark/Compiler/NodeVisitors/ChunkBuilderVisitor.cs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/scripting/spark.build
r182 r231 156 156 <fileset basedir="${bin.dir}"> 157 157 <include name="aspnetmvc/*.*" /> 158 <include name="ironpython/*.*" /> 158 159 <include name="mvccontrib/*.*" /> 159 160 <include name="castle/*.*" /> branches/scripting/src/Samples/PythonViewLanguage/Global.cs
r230 r231 32 32 public static void RegisterViewEngine(ICollection<IViewEngine> engines) 33 33 { 34 34 35 var container = new SparkServiceContainer(); 35 36 container.SetServiceBuilder<IViewEngine>(c => new SparkViewFactory(c.GetService<ISparkSettings>())); branches/scripting/src/Samples/PythonViewLanguage/PythonViewLanguage.csproj
r230 r231 116 116 </Compile> 117 117 <Compile Include="Global.cs" /> 118 <Compile Include="HtmlHelperExtension.cs" />119 118 <Compile Include="Models\Product.cs" /> 120 119 <Compile Include="Models\ProductRepository.cs" /> branches/scripting/src/Samples/Samples.sln
r230 r231 39 39 EndProject 40 40 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonViewLanguage", "PythonViewLanguage\PythonViewLanguage.csproj", "{22B2D07F-ED18-4AC2-BBE8-C58F1BE8E6BC}" 41 EndProject 42 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronPythonViews", "AspNetMvc\IronPythonViews\IronPythonViews.csproj", "{88AE48D2-9D28-4008-8CBC-64AAC13F96D1}" 41 43 EndProject 42 44 Global … … 110 112 {22B2D07F-ED18-4AC2-BBE8-C58F1BE8E6BC}.Release|Any CPU.ActiveCfg = Release|Any CPU 111 113 {22B2D07F-ED18-4AC2-BBE8-C58F1BE8E6BC}.Release|Any CPU.Build.0 = Release|Any CPU 114 {88AE48D2-9D28-4008-8CBC-64AAC13F96D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 115 {88AE48D2-9D28-4008-8CBC-64AAC13F96D1}.Debug|Any CPU.Build.0 = Debug|Any CPU 116 {88AE48D2-9D28-4008-8CBC-64AAC13F96D1}.Release|Any CPU.ActiveCfg = Release|Any CPU 117 {88AE48D2-9D28-4008-8CBC-64AAC13F96D1}.Release|Any CPU.Build.0 = Release|Any CPU 112 118 EndGlobalSection 113 119 GlobalSection(SolutionProperties) = preSolution … … 127 133 {FB78D1AA-35C1-4B77-93F0-A3CC032CA70A} = {B92F64C3-2A6F-4422-8B5B-12CE8CBF7E52} 128 134 {22B2D07F-ED18-4AC2-BBE8-C58F1BE8E6BC} = {B92F64C3-2A6F-4422-8B5B-12CE8CBF7E52} 135 {88AE48D2-9D28-4008-8CBC-64AAC13F96D1} = {B92F64C3-2A6F-4422-8B5B-12CE8CBF7E52} 129 136 {123FBEA2-3323-4051-8F33-734F4C06DD6C} = {95C10F2D-8E28-4F30-BC13-53ADFF36C196} 130 137 {247D9A71-561A-4C7D-BBBC-EE2FB0C5578F} = {70C08930-35D9-4208-9B28-48500FC98ED4} branches/scripting/src/Spark.Scripting.Tests/PythonViewCompilerTests.cs
r230 r231 2 2 using System.Collections.Generic; 3 3 using System.IO; 4 using System.Linq;5 using System.Text;6 4 using IronPython.Hosting; 7 5 using NUnit.Framework; … … 93 91 public void LayeredTemplates() 94 92 { 95 var chunks0 = Chunks(new SendLiteralChunk { Text = "2"});96 var chunks1 = Chunks( 93 var chunks0 = Chunks(new SendLiteralChunk { Text = "2" }); 94 var chunks1 = Chunks( 97 95 new SendLiteralChunk { Text = "4" }, 98 new UseContentChunk () { Name="view"},96 new UseContentChunk { Name = "view" }, 99 97 new SendLiteralChunk { Text = "0" }); 100 var chunks = new[] { chunks0[0], chunks1[0]};101 _compiler.CompileView(chunks, chunks);98 var chunks = new[] { chunks0[0], chunks1[0] }; 99 _compiler.CompileView(chunks, chunks); 102 100 var content = ExecuteView(); 103 101 Assert.AreEqual("420", content); 104 102 } 105 103 106 [ Test]104 [/*Test,*/ Ignore("Not really sure if namespaces play a role in a dlr based spark view")] 107 105 public void UsingNamespaces() 108 106 { … … 114 112 115 113 [Test] 114 public void TargetNamespace() 115 { 116 var chunks = Chunks(new SendLiteralChunk { Text = "blah" }); 117 118 _compiler.Descriptor = new SparkViewDescriptor { TargetNamespace = "TargetNamespace.ForThe.GeneratedView" }; 119 _compiler.GenerateSourceCode(chunks, chunks); 120 Assert.That(_compiler.SourceCode.Contains("namespace TargetNamespace.ForThe.GeneratedView")); 121 } 122 123 [/*Test,*/ Ignore("Not really sure if namespaces play a role in a dlr based spark view")] 116 124 public void TargetNamespaceWithUsingNamespaces() 117 125 { … … 222 230 } 223 231 224 [ Test]232 [/*Test,*/ Ignore("Not really sure if namespaces play a role in a dlr based spark view")] 225 233 public void UsingViewDataDefault() 226 234 { … … 463 471 } 464 472 465 [Test ]473 [Test, Ignore("TODO")] 466 474 public void DefaultVariablesWorking() 467 475 { … … 525 533 } 526 534 535 [Test] 536 public void ForLoopAutovariables() 537 { 538 var loop = Chunks( 539 new SendExpressionChunk { Code = "fooIndex" }, 540 new SendExpressionChunk { Code = "fooCount" }, 541 new SendExpressionChunk { Code = "fooIsFirst" }, 542 new SendExpressionChunk { Code = "fooIsLast" }); 543 544 var chunks = Chunks( 545 new ForEachChunk { Code = "foo in stuff", Body = loop[0] }); 546 547 _compiler.CompileView(chunks, chunks); 548 var contents = ExecuteView(new StubViewData 549 { 550 {"stuff", new[] {6, 2, 7, 4}} 551 }); 552 Assert.AreEqual("04TrueFalse14FalseFalse24FalseFalse34FalseTrue", contents); 553 } 527 554 } 528 555 } branches/scripting/src/Spark.Scripting/Compiler/Python/ChunkVisitors/GeneratedCodeVisitor.cs
r230 r231 74 74 } 75 75 76 //protected override void Visit(ForEachChunk chunk) 77 //{ 78 // _source.Write("for ").Write(chunk.Code).WriteLine(":"); 79 // _source.Indent++; 80 // Accept(chunk.Body); 81 // _source.Indent--; 82 //} 83 76 84 protected override void Visit(ForEachChunk chunk) 77 85 { 86 var forEach = new ForEachInspector(chunk.Code); 87 88 if (!forEach.Recognized) 89 { 90 _source.Write("for ").Write(chunk.Code).WriteLine(":"); 91 _source.Indent++; 92 Accept(chunk.Body); 93 _source.Indent--; 94 return; 95 } 96 97 var detect = new DetectCodeExpressionVisitor(OuterPartial); 98 var autoIndex = detect.Add(forEach.VariableName + "Index"); 99 var autoCount = detect.Add(forEach.VariableName + "Count"); 100 var autoIsFirst = detect.Add(forEach.VariableName + "IsFirst"); 101 var autoIsLast = detect.Add(forEach.VariableName + "IsLast"); 102 detect.Accept(chunk.Body); 103 104 if (autoIsLast.Detected) 105 { 106 autoIndex.Detected = true; 107 autoCount.Detected = true; 108 } 109 110 //_variables.PushScope(); 111 if (autoIndex.Detected) 112 { 113 //_variables.Declare(forEach.VariableName + "Index"); 114 _source.Write(forEach.VariableName).WriteLine("Index=0"); 115 } 116 if (autoIsFirst.Detected) 117 { 118 //_variables.Declare(forEach.VariableName + "IsFirst"); 119 _source.Write(forEach.VariableName).WriteLine("IsFirst=True"); 120 } 121 if (autoCount.Detected) 122 { 123 //_variables.Declare(forEach.VariableName + "Count"); 124 _source 125 .Write(forEach.VariableName).Write("Count=len([0 for ") 126 .Write(chunk.Code).WriteLine("])"); 127 } 128 //_variables.PushScope(); 129 //_variables.Declare(forEach.VariableName); 78 130 _source.Write("for ").Write(chunk.Code).WriteLine(":"); 79 131 _source.Indent++; 80 Accept(chunk.Body); 132 if (autoIsLast.Detected) 133 { 134 //bool {0}IsLast = ({0}Index == {0}Count - 1); 135 //_variables.Declare(forEach.VariableName + "IsLast"); 136 _source 137 .Write(forEach.VariableName).Write("IsLast=(") 138 .Write(forEach.VariableName).Write("Index==") 139 .Write(forEach.VariableName).WriteLine("Count - 1)"); 140 } 141 Accept(chunk.Body); 142 if (autoIndex.Detected) 143 { 144 //{0}Index={0}Index+1 145 _source 146 .Write(forEach.VariableName).Write("Index=") 147 .Write(forEach.VariableName).WriteLine("Index+1"); 148 } 149 if (autoIsFirst.Detected) 150 { 151 _source.Write(forEach.VariableName).WriteLine("IsFirst=False"); 152 } 153 _source.WriteLine("pass"); 81 154 _source.Indent--; 82 155 } branches/scripting/src/Spark.Scripting/Compiler/Python/PythonViewCompiler.cs
r230 r231 1 using System;2 1 using System.Collections.Generic; 3 using System. IO;2 using System.Linq; 4 3 using System.Text; 5 4 using Spark.Compiler; … … 69 68 BaseClass = baseClassGenerator.BaseClassTypeName; 70 69 71 ViewClassFullName = "View" + GeneratedViewId.ToString("n");70 var source = new StringBuilder(); 72 71 73 var source = new StringBuilder(); 74 source.Append("public class ").Append(ViewClassFullName).Append(" : ").Append(BaseClass).AppendLine(", global::Spark.Scripting.IScriptingSparkView"); 72 var viewClassName = "View" + GeneratedViewId.ToString("n"); 73 if (Descriptor != null && !string.IsNullOrEmpty(Descriptor.TargetNamespace)) 74 { 75 ViewClassFullName = Descriptor.TargetNamespace + "." + viewClassName; 76 source.Append("namespace ").AppendLine(Descriptor.TargetNamespace); 77 source.AppendLine("{"); 78 } 79 else 80 { 81 ViewClassFullName = viewClassName; 82 } 83 84 if (Descriptor != null) 85 { 86 // [SparkView] attribute 87 source.AppendLine("[global::Spark.SparkViewAttribute("); 88 if (TargetNamespace != null) 89 source.AppendFormat(" TargetNamespace=\"{0}\",", TargetNamespace).AppendLine(); 90 source.AppendLine(" Templates = new string[] {"); 91 source.Append(" ").AppendLine(string.Join(",\r\n ", 92 Descriptor.Templates.Select( 93 t => "\"" + t.Replace("\\", "\\\\") + "\"").ToArray())); 94 source.AppendLine(" })]"); 95 } 96 97 source.Append("public class ").Append(viewClassName).Append(" : ").Append(BaseClass).AppendLine(", global::Spark.Scripting.IScriptingSparkView"); 75 98 source.AppendLine("{"); 76 99 … … 109 132 source.AppendLine("}"); 110 133 134 if (Descriptor != null && !string.IsNullOrEmpty(Descriptor.TargetNamespace)) 135 { 136 source.AppendLine("}"); 137 } 138 111 139 SourceCode = source.ToString(); 112 140 } branches/scripting/src/Spark.Web.Mvc/Spark.Web.Mvc.csproj
r174 r231 4 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 5 5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 6 <ProductVersion>9.0. 21022</ProductVersion>6 <ProductVersion>9.0.30729</ProductVersion> 7 7 <SchemaVersion>2.0</SchemaVersion> 8 8 <ProjectGuid>{286050D6-95A1-4381-93D8-93381D8AB8E2}</ProjectGuid> … … 75 75 </Compile> 76 76 <Compile Include="Properties\AssemblyInfo.cs" /> 77 <Compile Include="SparkEngineStarter.cs" /> 77 78 <Compile Include="SparkView.cs" /> 78 79 <Compile Include="SparkViewFactory.cs" /> branches/scripting/src/Spark.sln
r230 r231 29 29 EndProject 30 30 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Castle MonoRail", "Castle MonoRail", "{CE293579-4889-4D6D-A1A0-BBBE8CBB9343}" 31 EndProject 32 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spark.Web.Mvc.Scripting", "Spark.Web.Mvc.Scripting\Spark.Web.Mvc.Scripting.csproj", "{92156FC5-8ECF-4A52-B4CA-AE060DCAAD18}" 31 33 EndProject 32 34 Global … … 80 82 {ED1B2C7B-862B-4B11-9BC3-55B1887877D9}.Release|Any CPU.ActiveCfg = Release|Any CPU 81 83 {ED1B2C7B-862B-4B11-9BC3-55B1887877D9}.Release|Any CPU.Build.0 = Release|Any CPU 84 {92156FC5-8ECF-4A52-B4CA-AE060DCAAD18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 85 {92156FC5-8ECF-4A52-B4CA-AE060DCAAD18}.Debug|Any CPU.Build.0 = Debug|Any CPU 86 {92156FC5-8ECF-4A52-B4CA-AE060DCAAD18}.Release|Any CPU.ActiveCfg = Release|Any CPU 87 {92156FC5-8ECF-4A52-B4CA-AE060DCAAD18}.Release|Any CPU.Build.0 = Release|Any CPU 82 88 EndGlobalSection 83 89 GlobalSection(SolutionProperties) = preSolution … … 85 91 EndGlobalSection 86 92 GlobalSection(NestedProjects) = preSolution 87 {31929D34-1A68-4A6B-9D8A-B93037163A5A} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 93 {AD93C831-E12E-45AE-B654-682F9EFAE314} = {CE293579-4889-4D6D-A1A0-BBBE8CBB9343} 94 {33D786A4-C95D-473E-B96F-06EC68527F66} = {CE293579-4889-4D6D-A1A0-BBBE8CBB9343} 95 {64CC97B3-6B9B-4D12-8A45-5CD3621E6471} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 88 96 {E3D6EDAD-3C8F-4C0D-AD96-740566A055F3} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 89 97 {0703F11D-FA13-4182-8577-170C9A5121FF} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 90 98 {ED1B2C7B-862B-4B11-9BC3-55B1887877D9} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 91 {64CC97B3-6B9B-4D12-8A45-5CD3621E6471} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 99 {31929D34-1A68-4A6B-9D8A-B93037163A5A} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 100 {C8E58F51-8630-4420-8630-8E634EC8900E} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179} 101 {0A2EFD84-C6E3-47EC-8DE8-B2087716C8E6} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179} 102 {63B2C862-484C-4AE3-A974-BE263B7116B0} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179} 92 103 {286050D6-95A1-4381-93D8-93381D8AB8E2} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179} 93 {C8E58F51-8630-4420-8630-8E634EC8900E} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179} 94 {63B2C862-484C-4AE3-A974-BE263B7116B0} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179} 95 {0A2EFD84-C6E3-47EC-8DE8-B2087716C8E6} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179} 96 {33D786A4-C95D-473E-B96F-06EC68527F66} = {CE293579-4889-4D6D-A1A0-BBBE8CBB9343} 97 {AD93C831-E12E-45AE-B654-682F9EFAE314} = {CE293579-4889-4D6D-A1A0-BBBE8CBB9343} 104 {92156FC5-8ECF-4A52-B4CA-AE060DCAAD18} = {F4E1F2B2-2BA6-4EFC-8082-ADBC14ECC179} 98 105 EndGlobalSection 99 106 EndGlobal branches/scripting/src/Spark/Compiler/ForEachInspector.cs
r187 r231 26 26 var terms = code.Split(' ', '\r', '\n', '\t').ToList(); 27 27 var inIndex = terms.IndexOf("in"); 28 if (inIndex >= 2)28 if (inIndex >= 1) 29 29 { 30 30 Recognized = true; branches/scripting/src/Spark/Compiler/NodeVisitors/ChunkBuilderVisitor.cs
r198 r231 281 281 scope.Body.Add(new LocalVariableChunk { Name = "__just__once__", Value = "0" }); 282 282 283 _sendAttributeOnce = new ConditionalChunk { Type = ConditionalType.If, Condition = "__just__once__ ++== 0" };283 _sendAttributeOnce = new ConditionalChunk { Type = ConditionalType.If, Condition = "__just__once__ == 0" }; 284 284 _sendAttributeOnce.Body.Add(new SendLiteralChunk { Text = " " + attributeNode.Name + "=\"" }); 285 _sendAttributeIncrement = new AssignVariableChunk { Name = "__just__once__", Value = "__just__once__+1" }; 285 286 286 287 … … 293 294 } 294 295 _sendAttributeOnce = null; 296 _sendAttributeIncrement = null; 295 297 296 298 var ifWasSent = new ConditionalChunk { Type = ConditionalType.If, Condition = "__just__once__ != 0" }; … … 334 336 335 337 private ConditionalChunk _sendAttributeOnce; 338 private Chunk _sendAttributeIncrement; 336 339 337 340 protected override void Visit(ConditionNode conditionNode) … … 342 345 if (_sendAttributeOnce != null) 343 346 conditionChunk.Body.Add(_sendAttributeOnce); 347 if (_sendAttributeIncrement != null) 348 conditionChunk.Body.Add(_sendAttributeIncrement); 344 349 345 350 using (new Frame(this, conditionChunk.Body))
