Changeset 231

Show
Ignore:
Timestamp:
11/12/08 17:59:25 (2 months ago)
Author:
louis.dejardin
Message:

Pretty close to merging python support to trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/scripting/spark.build

    r182 r231  
    156156                        <fileset basedir="${bin.dir}"> 
    157157                                <include name="aspnetmvc/*.*" /> 
     158                                <include name="ironpython/*.*" /> 
    158159                                <include name="mvccontrib/*.*" /> 
    159160                                <include name="castle/*.*" /> 
  • branches/scripting/src/Samples/PythonViewLanguage/Global.cs

    r230 r231  
    3232        public static void RegisterViewEngine(ICollection<IViewEngine> engines) 
    3333        { 
     34 
    3435            var container = new SparkServiceContainer(); 
    3536            container.SetServiceBuilder<IViewEngine>(c => new SparkViewFactory(c.GetService<ISparkSettings>())); 
  • branches/scripting/src/Samples/PythonViewLanguage/PythonViewLanguage.csproj

    r230 r231  
    116116    </Compile> 
    117117    <Compile Include="Global.cs" /> 
    118     <Compile Include="HtmlHelperExtension.cs" /> 
    119118    <Compile Include="Models\Product.cs" /> 
    120119    <Compile Include="Models\ProductRepository.cs" /> 
  • branches/scripting/src/Samples/Samples.sln

    r230 r231  
    3939EndProject 
    4040Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonViewLanguage", "PythonViewLanguage\PythonViewLanguage.csproj", "{22B2D07F-ED18-4AC2-BBE8-C58F1BE8E6BC}" 
     41EndProject 
     42Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronPythonViews", "AspNetMvc\IronPythonViews\IronPythonViews.csproj", "{88AE48D2-9D28-4008-8CBC-64AAC13F96D1}" 
    4143EndProject 
    4244Global 
     
    110112                {22B2D07F-ED18-4AC2-BBE8-C58F1BE8E6BC}.Release|Any CPU.ActiveCfg = Release|Any CPU 
    111113                {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 
    112118        EndGlobalSection 
    113119        GlobalSection(SolutionProperties) = preSolution 
     
    127133                {FB78D1AA-35C1-4B77-93F0-A3CC032CA70A} = {B92F64C3-2A6F-4422-8B5B-12CE8CBF7E52} 
    128134                {22B2D07F-ED18-4AC2-BBE8-C58F1BE8E6BC} = {B92F64C3-2A6F-4422-8B5B-12CE8CBF7E52} 
     135                {88AE48D2-9D28-4008-8CBC-64AAC13F96D1} = {B92F64C3-2A6F-4422-8B5B-12CE8CBF7E52} 
    129136                {123FBEA2-3323-4051-8F33-734F4C06DD6C} = {95C10F2D-8E28-4F30-BC13-53ADFF36C196} 
    130137                {247D9A71-561A-4C7D-BBBC-EE2FB0C5578F} = {70C08930-35D9-4208-9B28-48500FC98ED4} 
  • branches/scripting/src/Spark.Scripting.Tests/PythonViewCompilerTests.cs

    r230 r231  
    22using System.Collections.Generic; 
    33using System.IO; 
    4 using System.Linq; 
    5 using System.Text; 
    64using IronPython.Hosting; 
    75using NUnit.Framework; 
     
    9391        public void LayeredTemplates() 
    9492        { 
    95             var chunks0 = Chunks(new SendLiteralChunk {Text = "2"}); 
    96             var chunks1 = Chunks(                 
     93            var chunks0 = Chunks(new SendLiteralChunk { Text = "2" }); 
     94            var chunks1 = Chunks( 
    9795                new SendLiteralChunk { Text = "4" }, 
    98                 new UseContentChunk() { Name="view"}, 
     96                new UseContentChunk { Name = "view" }, 
    9997                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); 
    102100            var content = ExecuteView(); 
    103101            Assert.AreEqual("420", content); 
    104102        } 
    105103 
    106         [Test
     104        [/*Test,*/ Ignore("Not really sure if namespaces play a role in a dlr based spark view")
    107105        public void UsingNamespaces() 
    108106        { 
     
    114112 
    115113        [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")] 
    116124        public void TargetNamespaceWithUsingNamespaces() 
    117125        { 
     
    222230        } 
    223231 
    224         [Test
     232        [/*Test,*/ Ignore("Not really sure if namespaces play a role in a dlr based spark view")
    225233        public void UsingViewDataDefault() 
    226234        { 
     
    463471        } 
    464472 
    465         [Test
     473        [Test, Ignore("TODO")
    466474        public void DefaultVariablesWorking() 
    467475        { 
     
    525533        } 
    526534 
     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        } 
    527554    } 
    528555} 
  • branches/scripting/src/Spark.Scripting/Compiler/Python/ChunkVisitors/GeneratedCodeVisitor.cs

    r230 r231  
    7474        } 
    7575 
     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 
    7684        protected override void Visit(ForEachChunk chunk) 
    7785        { 
     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); 
    78130            _source.Write("for ").Write(chunk.Code).WriteLine(":"); 
    79131            _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"); 
    81154            _source.Indent--; 
    82155        } 
  • branches/scripting/src/Spark.Scripting/Compiler/Python/PythonViewCompiler.cs

    r230 r231  
    1 using System; 
    21using System.Collections.Generic; 
    3 using System.IO
     2using System.Linq
    43using System.Text; 
    54using Spark.Compiler; 
     
    6968            BaseClass = baseClassGenerator.BaseClassTypeName; 
    7069 
    71             ViewClassFullName = "View" + GeneratedViewId.ToString("n"); 
     70            var source = new StringBuilder(); 
    7271 
    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"); 
    7598            source.AppendLine("{"); 
    7699             
     
    109132            source.AppendLine("}"); 
    110133 
     134            if (Descriptor != null && !string.IsNullOrEmpty(Descriptor.TargetNamespace)) 
     135            { 
     136                source.AppendLine("}"); 
     137            } 
     138 
    111139            SourceCode = source.ToString(); 
    112140        } 
  • branches/scripting/src/Spark.Web.Mvc/Spark.Web.Mvc.csproj

    r174 r231  
    44    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
    55    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 
    6     <ProductVersion>9.0.21022</ProductVersion> 
     6    <ProductVersion>9.0.30729</ProductVersion> 
    77    <SchemaVersion>2.0</SchemaVersion> 
    88    <ProjectGuid>{286050D6-95A1-4381-93D8-93381D8AB8E2}</ProjectGuid> 
     
    7575    </Compile> 
    7676    <Compile Include="Properties\AssemblyInfo.cs" /> 
     77    <Compile Include="SparkEngineStarter.cs" /> 
    7778    <Compile Include="SparkView.cs" /> 
    7879    <Compile Include="SparkViewFactory.cs" /> 
  • branches/scripting/src/Spark.sln

    r230 r231  
    2929EndProject 
    3030Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Castle MonoRail", "Castle MonoRail", "{CE293579-4889-4D6D-A1A0-BBBE8CBB9343}" 
     31EndProject 
     32Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spark.Web.Mvc.Scripting", "Spark.Web.Mvc.Scripting\Spark.Web.Mvc.Scripting.csproj", "{92156FC5-8ECF-4A52-B4CA-AE060DCAAD18}" 
    3133EndProject 
    3234Global 
     
    8082                {ED1B2C7B-862B-4B11-9BC3-55B1887877D9}.Release|Any CPU.ActiveCfg = Release|Any CPU 
    8183                {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 
    8288        EndGlobalSection 
    8389        GlobalSection(SolutionProperties) = preSolution 
     
    8591        EndGlobalSection 
    8692        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} 
    8896                {E3D6EDAD-3C8F-4C0D-AD96-740566A055F3} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 
    8997                {0703F11D-FA13-4182-8577-170C9A5121FF} = {F606A062-1BD5-40E2-8E8A-BCC4F374BFBF} 
    9098                {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} 
    92103                {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} 
    98105        EndGlobalSection 
    99106EndGlobal 
  • branches/scripting/src/Spark/Compiler/ForEachInspector.cs

    r187 r231  
    2626            var terms = code.Split(' ', '\r', '\n', '\t').ToList(); 
    2727            var inIndex = terms.IndexOf("in"); 
    28             if (inIndex >= 2
     28            if (inIndex >= 1
    2929            { 
    3030                Recognized = true; 
  • branches/scripting/src/Spark/Compiler/NodeVisitors/ChunkBuilderVisitor.cs

    r198 r231  
    281281                scope.Body.Add(new LocalVariableChunk { Name = "__just__once__", Value = "0" }); 
    282282 
    283                 _sendAttributeOnce = new ConditionalChunk { Type = ConditionalType.If, Condition = "__just__once__++ == 0" }; 
     283                _sendAttributeOnce = new ConditionalChunk { Type = ConditionalType.If, Condition = "__just__once__ == 0" }; 
    284284                _sendAttributeOnce.Body.Add(new SendLiteralChunk { Text = " " + attributeNode.Name + "=\"" }); 
     285                _sendAttributeIncrement = new AssignVariableChunk { Name = "__just__once__", Value = "__just__once__+1" }; 
    285286 
    286287 
     
    293294                } 
    294295                _sendAttributeOnce = null; 
     296                _sendAttributeIncrement = null; 
    295297 
    296298                var ifWasSent = new ConditionalChunk { Type = ConditionalType.If, Condition = "__just__once__ != 0" }; 
     
    334336 
    335337        private ConditionalChunk _sendAttributeOnce; 
     338        private Chunk _sendAttributeIncrement; 
    336339 
    337340        protected override void Visit(ConditionNode conditionNode) 
     
    342345            if (_sendAttributeOnce != null) 
    343346                conditionChunk.Body.Add(_sendAttributeOnce); 
     347            if (_sendAttributeIncrement != null) 
     348                conditionChunk.Body.Add(_sendAttributeIncrement); 
    344349 
    345350            using (new Frame(this, conditionChunk.Body))