Changeset 223

Show
Ignore:
Timestamp:
11/01/08 01:59:09 (2 months ago)
Author:
louis.dejardin
Message:

More implementation of the CodeDom? generators. Added boo.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Controllers/HomeController.cs

    r188 r223  
    5353        } 
    5454 
    55         public object Index(string ajax
     55        public object Index(
    5656        { 
    5757            ViewData["ajaxEnabled"] = (string) Session["ajax"] == "disabled" ? false : true; 
  • branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Views/Home/Index.spark

    r174 r223  
    11<h2>Client Rendering Views</h2> 
    22<p> 
    3   Ajax <strong>${ajaxEnabled ? 'enabled' : 'disabled'}</strong>. 
    4   <a href="~/home/enableajax">enable</a> &bull; <a href="~/home/disableajax">disable</a>. 
     3  Ajax currently <strong>${ajaxEnabled ? 'enabled' : 'disabled'}</strong>. 
     4  <test if="ajaxEnabled"> 
     5    ${Html.ActionLink("Disable Ajax now", "disableajax", "home")} 
     6    <else/> 
     7    ${Html.ActionLink("Enable Ajax now", "enableajax", "home")} 
     8  </test> 
    59</p> 
     10 
    611<p> 
    712  This example shows how you can generate javascript code from a spark file. This js code can be 
     
    914</p> 
    1015 
    11 <viewdata products="IList[[Models.Product]]" ajaxEnabled="bool"/> 
     16<viewdata 
     17  products="IList[[Models.Product]]" 
     18  ajaxEnabled="bool"/> 
    1219 
    13 <test if="ajaxEnabled"> 
    14   <content:head> 
    15     <script type="text/javascript" src="~/Content/jquery-1.2.6.js"></script> 
    16     <script type="text/javascript" src="~/Content/jquery.livequery.js"></script> 
    17     <script type="text/javascript" src="~/Home/ShowCart"></script> 
    18     <script type="text/javascript" src="~/Content/home-index.js"></script> 
    19   </content:head> 
    20 </test> 
     20<content:head if="ajaxEnabled"> 
     21  <script type="text/javascript" src="~/Content/jquery-1.2.6.js" once="js-jquery"></script> 
     22  <script type="text/javascript" src="~/Content/jquery.livequery.js" once="js-livequery"></script> 
     23  <script type="text/javascript" src="~/Home/ShowCart"></script> 
     24  <script type="text/javascript" src="~/Content/home-index.js"></script> 
     25</content:head> 
    2126 
    2227<ul> 
     
    2429    ${product.Name} 
    2530    ${product.UnitPrice} 
    26     <a class="cartajax" href="~/home/addtocart/${product.Id}">Add to cart</a> 
     31    <a class="cartajax?{ajaxEnabled}" href="~/home/addtocart/${product.Id}">Add to cart</a> 
    2732  </li> 
    2833</ul> 
    2934 
    3035<content:subcontent> 
    31   <a class="refresh" href="~/home/index">Refresh</a> &bull; <a class="cartajax" href="~/home/Reset">Reset cart</a> 
     36  <a class="refresh" href="~/home/index">Refresh</a> 
     37  &bull; 
     38  <a class="cartajax" href="~/home/Reset">Reset cart</a> 
    3239  <div id="cart"> 
    3340    <ShowCart/> 
  • branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Views/Home/_Global.spark

    r174 r223  
    11<use namespace="System.Collections.Generic"/> 
     2<use namespace="System.Web.Mvc.Html"/> 
  • branches/codedom/src/Samples/AspNetMvc/PartialFiles/ViewPage.cs

    r188 r223  
    1313// limitations under the License. 
    1414//  
     15using System; 
    1516using System.IO; 
     17using System.Web; 
     18using System.Web.Mvc; 
    1619using System.Web.UI; 
    1720 
    1821namespace PartialFiles 
    1922{ 
     23/// <summary> 
     24/// Default ViewPage base class for aspx files in this project. 
     25/// Set via system.web/pages/@pageBaseType 
     26/// </summary> 
     27public class ViewPage : System.Web.Mvc.ViewPage 
     28{ 
     29  
     30 
    2031    /// <summary> 
    21     /// Default ViewPage base class for aspx files in this project. 
    22     /// Set via system.web/pages/@pageBaseType 
     32    /// Must substitute the ViewContext TextWriter, because  
     33    /// the native HttpContext.Current TextWriter will be used by default 
    2334    /// </summary> 
    24     public class ViewPage : System.Web.Mvc.ViewPage 
     35    protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter tw) 
    2536    { 
    26         /// <summary> 
    27         /// Must substitute the ViewContext TextWriter, because  
    28         /// the native HttpContext.Current TextWriter will be used by default 
    29         /// </summary> 
    30         protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter tw) 
     37        var mayReplace = HttpContext.Current == null || 
     38            ReferenceEquals(tw, HttpContext.Current.Response.Output); 
     39 
     40        if (mayReplace && ViewContext != null) 
    3141        { 
    32             if (ViewContext != null) 
    33                 return base.CreateHtmlTextWriter(ViewContext.HttpContext.Response.Output); 
     42            return base.CreateHtmlTextWriter(ViewContext.HttpContext.Response.Output); 
     43        } 
    3444 
    35             return base.CreateHtmlTextWriter(tw); 
    36         } 
     45        return base.CreateHtmlTextWriter(tw); 
    3746    } 
    3847} 
     48} 
  • branches/codedom/src/Samples/AspNetMvc/PartialFiles/ViewUserControl.cs

    r188 r223  
    1313// limitations under the License. 
    1414//  
     15using System.Web; 
    1516using System.Web.UI; 
    1617 
    1718namespace PartialFiles 
    1819{ 
     20/// <summary> 
     21/// Default ViewUserControl base class for aspc files in this project. 
     22/// Set via system.web/pages/@userControlBaseType 
     23/// </summary> 
     24public class ViewUserControl : System.Web.Mvc.ViewUserControl 
     25{ 
    1926    /// <summary> 
    20     /// Default ViewUserControl base class for aspc files in this project. 
    21     /// Set via system.web/pages/@userControlBaseType 
     27    /// Must substitute the ViewContext TextWriter, because  
     28    /// the native HttpContext.Current TextWriter will be used by default 
    2229    /// </summary> 
    23     public class ViewUserControl : System.Web.Mvc.ViewUserControl 
     30    public override void RenderControl(HtmlTextWriter writer) 
    2431    { 
    25         /// <summary> 
    26         /// Must substitute the ViewContext TextWriter, because  
    27         /// the native HttpContext.Current TextWriter will be used by default 
    28         /// </summary> 
    29         public override void RenderControl(HtmlTextWriter writer) 
    30         { 
    31             if (ViewContext != null) 
    32                 writer.InnerWriter = ViewContext.HttpContext.Response.Output; 
     32        var mayReplace = HttpContext.Current == null || 
     33            ReferenceEquals(writer.InnerWriter, HttpContext.Current.Response.Output); 
    3334 
    34             base.RenderControl(writer); 
    35         } 
     35        if (mayReplace && ViewContext != null) 
     36            writer.InnerWriter = ViewContext.HttpContext.Response.Output; 
     37 
     38        base.RenderControl(writer); 
    3639    } 
    3740} 
     41} 
  • branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Home/Alternate.aspx

    r128 r223  
    33<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
    44</asp:Content> 
     5 
    56<asp:Content ID="Content2" ContentPlaceHolderID="view" runat="server"> 
    67    <p> 
  • branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Home/Index.spark

    r128 r223  
    1717    <Status/> 
    1818  </div> 
    19   <p>Bottom of the view</p> 
     19 
     20  <div style="border:solid 1px grey"> 
     21    <p>Html encoding macro with partials</p> 
     22    ${Html.Encode(HeaderFooterHtml())} 
     23  </div> 
     24 
     25<p>Bottom of the view</p> 
    2026</div> 
  • branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/DefaultLayout.Master

    r128 r223  
    1313    <% Html.RenderPartial("_menu");%> 
    1414    <div> 
    15         <asp:ContentPlaceHolder ID="view" runat="server"> 
    16          
     15        <asp:ContentPlaceHolder ID="view" runat="server">         
    1716        </asp:ContentPlaceHolder> 
    1817    </div> 
  • branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/DefaultLayout.spark

    r128 r223  
    1010    <use:view/> 
    1111    #Html.RenderPartial("footer"); 
    12  
    13     <hr/> 
    14     <code> 
    15       <var entry="Spark.CompiledViewHolder.Current.Lookup(GeneratedViewId)"/> 
    16       ${H(entry.Compiler.SourceCode).Replace("\r\n", "<br/>").Replace(" ", "&nbsp;")} 
    17     </code> 
    1812  </body> 
    1913</html> 
  • branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/_global.spark

    r217 r223  
    11<use namespace="System.Web.Mvc.Html" /> 
     2 
     3 
     4<macro name="HeaderFooterHtml"> 
     5  #Html.RenderPartial("header"); 
     6  #Html.RenderPartial("footer"); 
     7 
     8  # using(Html.BeginForm()) { 
     9  <p>Hello form</p> 
     10  # } 
     11</macro> 
  • branches/codedom/src/Samples/MonoRail/AdvancedPartials/Views/Home/About.spark

    r137 r223  
    1212    <strong>Note: </strong> Some of these techniques are practical, but some are very contrived and are only 
    1313    present to show what you can do with certain Spark features. In otherwords you will see some 
    14     over-kill in here. As always 
    15     this best practices document so use your best judgement about where some 
     14    over-kill in here. As always use your best judgement about where some 
    1615    of these ideas could be used appropriately. 
    1716  </SmallBox> 
  • branches/codedom/src/Samples/MonoRail/AdvancedPartials/Views/Shared/_RoundBox.spark

    r192 r223  
    11<div class="xsnazzy" style="margin-bottom:20px;"> 
    2   <content:head> 
    3     <global type="int" _boxes_once_="0"/> 
    4     <style type="text/css" if="++_boxes_once_==1"> 
     2  <content:head once="snazzy-css">     
     3    <style type="text/css"> 
    54      .zsnazzy {width:745px;} 
    65      .xsnazzy h1, .zsnazzy h1 {margin:0; font-size:1.2em; padding:0 10px 5px 10px; border-bottom:1px solid #444;} 
  • branches/codedom/src/Spark.Tests/App.config

    r89 r223  
    1616    </pages> 
    1717  </spark> 
     18  <system.codedom> 
     19    <compilers> 
     20      <compiler extension=".boo" type="Boo.Lang.CodeDom.BooCodeProvider, Boo.Lang.CodeDom, Version=2.0." language="boo" /> 
     21    </compilers> 
     22  </system.codedom> 
    1823</configuration> 
    1924 
  • branches/codedom/src/Spark.Tests/Spark.Tests.Views/Code/foreach.spark

    r86 r223  
    1212        } 
    1313} 
     14   
  • branches/codedom/src/Spark.Tests/Spark.Tests.csproj

    r221 r223  
    3232  </PropertyGroup> 
    3333  <ItemGroup> 
     34    <Reference Include="Boo.Lang.CodeDom, Version=2.0.0.0, Culture=neutral, PublicKeyToken=32c39770e9a21a67, processorArchitecture=MSIL"> 
     35      <SpecificVersion>False</SpecificVersion> 
     36      <HintPath>..\..\bin\castle\Boo.Lang.CodeDom.dll</HintPath> 
     37    </Reference> 
    3438    <Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> 
    3539      <SpecificVersion>False</SpecificVersion> 
     
    5559  </ItemGroup> 
    5660  <ItemGroup> 
    57     <Compile Include="CodeDomViewCompilerTester.cs" /> 
     61    <Compile Include="BooCodeDomViewCompilerTester.cs" /> 
     62    <Compile Include="VbCodeDomViewCompilerTester.cs" /> 
    5863    <Compile Include="Compiler\ExpressionBuilderTester.cs" /> 
    5964    <Compile Include="Compiler\ForEachInspectorTester.cs" /> 
  • branches/codedom/src/Spark.Tests/SparkExtensionTester.cs

    r187 r223  
    3333        { 
    3434            engine = new SparkViewEngine(new SparkSettings().SetPageBaseType("Spark.Tests.Stubs.StubSparkView")) 
    35                          {ViewFolder = new FileSystemViewFolder("Spark.Tests.Views")}; 
    36             engine.ExtensionFactory = new StubExtensionFactory(); 
     35                         { 
     36                             ViewFolder = new FileSystemViewFolder("Spark.Tests.Views"), 
     37                             ExtensionFactory = new StubExtensionFactory() 
     38                         }; 
    3739        } 
    3840 
     
    6264        public void VisitNode(INodeVisitor visitor, IList<Node> body, IList<Chunk> chunks) 
    6365        { 
    64              
     66 
    6567        } 
    6668 
  • branches/codedom/src/Spark/Compiler/CSharp/ChunkVisitors/GeneratedCodeVisitor.cs

    r221 r223  
    5353        private void CodeDefault() 
    5454        { 
    55             _source.AppendLine("#line default"); 
     55            //_source.AppendLine("#line default"); 
     56            _source.AppendLine("#line hidden"); 
    5657        } 
    5758 
  • branches/codedom/src/Spark/Compiler/CodeDom/ChunkVisitors/GeneratedCodeVisitor.cs

    r222 r223  
    5555        protected override void Visit(CodeStatementChunk chunk) 
    5656        { 
    57             Statements.Add(new CodeSnippetStatement(chunk.Code)); 
     57            Statements.Add( 
     58                new CodeExpressionStatement( 
     59                    new CodeSnippetExpression(chunk.Code))); 
    5860        } 
    5961 
     
    6870        protected override void Visit(LocalVariableChunk chunk) 
    6971        { 
    70             _variables.Declare(chunk.Name); 
    71  
    72             if (chunk.Type == "var") 
     72            DeclareVariable(chunk.Type, chunk.Name, chunk.Value); 
     73        } 
     74 
     75        protected override void Visit(DefaultVariableChunk chunk) 
     76        { 
     77            if (_variables.IsDeclared(chunk.Name)) 
     78                return; 
     79 
     80            DeclareVariable(chunk.Type, chunk.Name, chunk.Value); 
     81        } 
     82 
     83        void DeclareVariable(string type, string name, string value) 
     84        { 
     85            _variables.Declare(name); 
     86 
     87            if (type == "var") 
    7388            { 
    7489                // not normally supported 
    75                 Statements.Add(_viewCompiler.LanguageSpecific_ImplicitLocalVariable(chunk.Name, chunk.Value)); 
     90                Statements.Add(_viewCompiler.LanguageSpecific_ImplicitLocalVariable(name, value)); 
    7691            } 
    7792            else 
     
    7994                // type name = value; 
    8095 
    81                 var declarationStatement = new CodeVariableDeclarationStatement(CodeDomUtility.TypeReference(chunk.Type), chunk.Name); 
    82                 if (!string.IsNullOrEmpty(chunk.Value)) 
    83                 { 
    84                     declarationStatement.InitExpression = new CodeSnippetExpression(chunk.Value); 
     96                var declarationStatement = new CodeVariableDeclarationStatement(CodeDomUtility.TypeReference(type), name); 
     97                if (!string.IsNullOrEmpty(value)) 
     98                { 
     99                    declarationStatement.InitExpression = new CodeSnippetExpression(value); 
    85100                } 
    86101                Statements.Add(declarationStatement); 
    87102            } 
    88103        } 
    89  
    90104        protected override void Visit(UseContentChunk chunk) 
    91105        { 
     
    107121                var writeTo = new CodeExpressionStatement( 
    108122                    new CodeMethodInvokeExpression( 
    109                         new CodeTypeReferenceExpression(typeof(TextWriterExtensions)), 
     123                        new CodeTypeReferenceExpression(new CodeTypeReference(typeof(TextWriterExtensions), CodeTypeReferenceOptions.GlobalReference)), 
    110124                        "WriteTo", 
    111125                        new CodeArrayIndexerExpression( 
     
    134148        } 
    135149 
     150        protected override void Visit(ContentSetChunk chunk) 
     151        { 
     152            //using(OutputScope(new System.IO.StringWriter())) 
     153 
     154            var prior = Statements; 
     155            try 
     156            { 
     157                _statements = _viewCompiler.BuildUsingStatement( 
     158                    Statements, 
     159                    new CodeMethodInvokeExpression( 
     160                        new CodeThisReferenceExpression(), 
     161                        "OutputScope", 
     162                        new CodeObjectCreateExpression( 
     163                            typeof(StringWriter)))); 
     164 
     165                _variables.PushScope(); 
     166                Accept(chunk.Body); 
     167                _variables.PopScope(); 
     168 
     169                // Output.ToString() 
     170                var outputToString = 
     171                    new CodeMethodInvokeExpression( 
     172                        new CodePropertyReferenceExpression( 
     173                            new CodeThisReferenceExpression(), 
     174                            "Output"), 
     175                        "ToString"); 
     176 
     177                switch (chunk.AddType) 
     178                { 
     179                    case ContentAddType.AppendAfter: 
     180                        //"{0} = {0} + Output.ToString();"; 
     181                        Statements.Add( 
     182                            new CodeAssignStatement( 
     183                                new CodeVariableReferenceExpression(chunk.Variable), 
     184                                new CodeBinaryOperatorExpression( 
     185                                    new CodeVariableReferenceExpression(chunk.Variable), 
     186                                    CodeBinaryOperatorType.Add, 
     187                                    outputToString))); 
     188                        break; 
     189                    case ContentAddType.InsertBefore: 
     190                        //"{0} = Output.ToString() + {0};"; 
     191                        Statements.Add( 
     192                            new CodeAssignStatement( 
     193                                new CodeVariableReferenceExpression(chunk.Variable), 
     194                                new CodeBinaryOperatorExpression( 
     195                                    outputToString, 
     196                                    CodeBinaryOperatorType.Add, 
     197                                    new CodeVariableReferenceExpression(chunk.Variable)))); 
     198                        break; 
     199                    default: 
     200                        //"{0} = Output.ToString();"; 
     201                        Statements.Add( 
     202                            new CodeAssignStatement( 
     203                                new CodeVariableReferenceExpression(chunk.Variable), 
     204                                outputToString)); 
     205                        break; 
     206                } 
     207            } 
     208            finally 
     209            { 
     210                _statements = prior; 
     211            } 
     212 
     213        } 
     214 
    136215        protected override void Visit(ScopeChunk chunk) 
    137216        { 
     
    140219            { 
    141220                // using an if(true) because codedom doesn't have 
    142                 // a universal block-with-nothing-in-it concept. 
     221                // a universal block-with-stuff-in-it concept. 
    143222 
    144223                var block = new CodeConditionStatement(new CodePrimitiveExpression(true)); 
     
    156235        } 
    157236 
     237        protected override void Visit(ContentChunk chunk) 
     238        { 
     239            var prior = _statements; 
     240            try 
     241            { 
     242                //using(OutputScope(name)) 
     243 
     244                _statements = _viewCompiler.BuildUsingStatement( 
     245                    Statements, 
     246                    new CodeMethodInvokeExpression( 
     247                        new CodeThisReferenceExpression(), 
     248                        "OutputScope", 
     249                        new CodePrimitiveExpression(chunk.Name))); 
     250 
     251                _variables.PushScope(); 
     252                Accept(chunk.Body); 
     253                _variables.PopScope(); 
     254            } 
     255            finally 
     256            { 
     257                _statements = prior; 
     258            } 
     259        } 
     260 
     261        protected override void Visit(ConditionalChunk chunk) 
     262        { 
     263            var prior = _statements; 
     264            try 
     265            { 
     266                switch (chunk.Type) 
     267                { 
     268                    case ConditionalType.If: 
     269                        { 
     270                            AddConditionAndFocusTrueStatements(chunk.Condition); 
     271                        } 
     272                        break; 
     273                    case ConditionalType.ElseIf: 
     274                        { 
     275                            FindConditionsFocusFalseStatements(); 
     276                            AddConditionAndFocusTrueStatements(chunk.Condition); 
     277                        } 
     278                        break; 
     279                    case ConditionalType.Else: 
     280                        { 
     281                            FindConditionsFocusFalseStatements(); 
     282                        } 
     283                        break; 
     284                    case ConditionalType.Once: 
     285                        { 
     286                            var conditionStatement = 
     287                                new CodeConditionStatement( 
     288                                    new CodeMethodInvokeExpression( 
     289                                        new CodeThisReferenceExpression(), 
     290                                        "Once", 
     291                                        new CodeSnippetExpression(chunk.Condition))); 
     292                            Statements.Add(conditionStatement); 
     293                            _statements = conditionStatement.TrueStatements; 
     294                        } 
     295                        break; 
     296                } 
     297                _variables.PushScope(); 
     298                Accept(chunk.Body); 
     299                _variables.PopScope(); 
     300            } 
     301            finally 
     302            { 
     303                _statements = prior; 
     304            } 
     305        } 
     306 
     307        private void AddConditionAndFocusTrueStatements(string condition) 
     308        { 
     309            var conditionStatement = 
     310                new CodeConditionStatement( 
     311                    new CodeSnippetExpression(condition)); 
     312            Statements.Add(conditionStatement); 
     313            _statements = conditionStatement.TrueStatements; 
     314        } 
     315 
     316        private void FindConditionsFocusFalseStatements() 
     317        { 
     318            var last = Statements.Cast<CodeStatement>().LastOrDefault() as CodeConditionStatement; 
     319 
     320            while (last != null) 
     321            { 
     322                if (last.FalseStatements.Count == 0) 
     323                { 
     324                    // This is the final empty "else" condition 
     325                    // focus on it and return. 
     326                    _statements = last.FalseStatements; 
     327                    return; 
     328                } 
     329 
     330                // drop out to throw exception  if the trailing else isn't a  
     331                // single code condition. 
     332                if (last.FalseStatements.Count != 1) 
     333                { 
     334                    break; 
     335                } 
     336 
     337                last = last.FalseStatements[0] as CodeConditionStatement; 
     338            } 
     339            throw new CompilerException("An else condition must follow an if or elseif"); 
     340        } 
     341 
    158342        protected override void Visit(ForEachChunk chunk) 
    159343        { 
    160344            var forEach = new ForEachInspector(chunk.Code); 
    161              
     345 
    162346            if (!forEach.Recognized) 
    163347            { 
     
    180364                    autoCount.Detected = true; 
    181365                } 
    182                  
     366 
    183367                _variables.PushScope(); 
    184368                var scopeAutoVariables = new CodeConditionStatement(new CodePrimitiveExpression(true)); 
     
    191375                    Statements.Add( 
    192376                        new CodeVariableDeclarationStatement( 
    193                             typeof (int),  
     377                            typeof(int), 
    194378                            forEach.VariableName + "Index", 
    195379                            new CodePrimitiveExpression(0))); 
     
    213397                            forEach.VariableName + "Count", 
    214398                            new CodeMethodInvokeExpression( 
    215                                 new CodeTypeReferenceExpression(typeof(CollectionUtility)), 
     399                                new CodeTypeReferenceExpression(new CodeTypeReference(typeof(CollectionUtility), CodeTypeReferenceOptions.GlobalReference)), 
    216400                                "Count", 
    217401                                new CodeSnippetExpression(forEach.CollectionCode)))); 
     
    228412                    Statements.Add( 
    229413                        new CodeVariableDeclarationStatement( 
    230                             typeof (bool), 
     414                            typeof(bool), 
    231415                            forEach.VariableName + "IsLast", 
    232416                            new CodeBinaryOperatorExpression( 
     
    254438                                new CodePrimitiveExpression(1)))); 
    255439                } 
    256                  
     440 
    257441                if (autoIsFirst.Detected) 
    258442                { 
     
    284468        } 
    285469 
     470        protected override void Visit(RenderSectionChunk chunk) 
     471        { 
     472            if (string.IsNullOrEmpty(chunk.Name)) 
     473            { 
     474                Accept(OuterPartial.Body); 
     475            } 
     476            else if (OuterPartial.Sections.ContainsKey(chunk.Name)) 
     477            { 
     478                Accept(OuterPartial.Sections[chunk.Name]); 
     479            } 
     480            else 
     481            { 
     482                Accept(chunk.Default); 
     483            } 
     484        } 
     485 
    286486        protected override void Visit(MacroChunk chunk) 
    287487        { 
    288488            // macro declaration doesn't do anything at the point where it occurs 
    289489        } 
     490 
    290491    } 
    291492} 
  • branches/codedom/src/Spark/Compiler/CodeDom/CodeDomViewCompiler.cs

    r221 r223  
    5555            { 
    5656                var renderViewLevel = new CodeMemberMethod { Name = "RenderViewLevel" + renderLevel }; 
    57                 viewClass.Members.Add(renderViewLevel);                 
     57                viewClass.Members.Add(renderViewLevel); 
    5858 
    5959                //TODO: bring variables back from globel members 
     
    6666 
    6767            // public void RenderView(TextWriter writer) 
    68 // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags 
     68            // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags 
    6969            var renderView = new CodeMemberMethod { Name = "RenderView", Attributes = MemberAttributes.Public | MemberAttributes.Override }; 
    70 // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags 
     70            // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags 
    7171            viewClass.Members.Add(renderView); 
    7272            renderView.Parameters.Add(new CodeParameterDeclarationExpression(typeof(TextWriter), "writer")); 
     
    118118            } 
    119119 
    120             var options = new CodeGeneratorOptions { IndentString = "" }; 
     120            //var options = new CodeGeneratorOptions { IndentString = "" }; 
     121            var options = new CodeGeneratorOptions(); 
    121122            var source = new StringBuilder(); 
    122123            GetCodeDomProvider().GenerateCodeFromCompileUnit(compileUnit, new StringWriter(source), options); 
     
    162163                baseClassGenerator.Accept(resource); 
    163164 
    164             var viewBaseType = new CodeTypeReference(baseClassGenerator.BaseClassTypeName); 
     165            var viewBaseType = new CodeTypeReference(baseClassGenerator.BaseClass); 
    165166            if (!string.IsNullOrEmpty(baseClassGenerator.TModel)) 
    166167                viewBaseType.TypeArguments.Add(baseClassGenerator.TModel); 
     
    178179        private void AddSparkViewAttribute(CodeTypeMember viewClass) 
    179180        { 
    180             var viewAttribute = new CodeAttributeDeclaration(new CodeTypeReference("Spark.SparkViewAttribute")); 
     181            var viewAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(SparkViewAttribute), CodeTypeReferenceOptions.GlobalReference)); 
    181182            viewClass.CustomAttributes.Add(viewAttribute); 
    182183            if (TargetNamespace != null) 
     
    193194        private void AddGeneratedViewId(CodeTypeDeclaration viewClass) 
    194195        { 
    195 // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags 
     196            // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags 
    196197            var viewIdProperty = new CodeMemberProperty { Name = "GeneratedViewId", Type = new CodeTypeReference(typeof(Guid)), HasGet = true, Attributes = MemberAttributes.Override | MemberAttributes.Public }; 
    197 // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags 
     198            // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags 
    198199            viewClass.Members.Add(viewIdProperty); 
    199200            viewIdProperty.GetStatements.Add( 
     
    207208 
    208209        public abstract CodeStatement LanguageSpecific_ForEachEnd(); 
     210 
     211        private int _usingDisposableCount; 
     212        public CodeStatementCollection BuildUsingStatement(CodeStatementCollection statements, CodeExpression expression) 
     213        { 
     214            //IDisposable __using__disposable1__ = expression; 
     215            //try { *returned collection* } 
     216            //finally {__using__disposable1__.Dispose();} 
     217            statements.Add( 
     218                new CodeVariableDeclarationStatement( 
     219                    typeof(IDisposable), 
     220                    "__using__disposable" + (++_usingDisposableCount), 
     221                    expression)); 
     222            var tryFinally = new CodeTryCatchFinallyStatement(); 
     223            statements.Add(tryFinally); 
     224            tryFinally.FinallyStatements.Add( 
     225                new CodeMethodInvokeExpression( 
     226                    new CodeVariableReferenceExpression("__using__disposable" + (_usingDisposableCount)), 
     227                    "Dispose")); 
     228            return tryFinally.TryStatements; 
     229        }         
    209230    } 
    210231} 
  • branches/codedom/src/Spark/Spark.csproj

    r221 r223  
    6464    <Compile Include="Compiler\CodeDom\ChunkVisitors\UsingNamespaceVisitor.cs" /> 
    6565    <Compile Include="Compiler\CodeDom\CodeDomViewCompiler.cs" /> 
     66    <Compile Include="Compiler\CodeDom\BooCodeDomViewCompiler.cs" /> 
    6667    <Compile Include="Compiler\CodeDom\CsCodeDomViewCompiler.cs" /> 
    6768    <Compile Include="Compiler\CodeDom\VbCodeDomViewCompiler.cs" /> 
  • branches/codedom/src/Spark/SparkViewDescriptor.cs

    r218 r223  
    2121        CSharp, 
    2222        Javascript, 
    23         VisualBasic 
     23        VisualBasic, 
     24        Boo 
    2425    } 
    2526 
  • branches/codedom/src/Spark/SparkViewEngine.cs

    r221 r223  
    239239                    viewCompiler = new VbCodeDomViewCompiler(); 
    240240                    break; 
     241                case LanguageType.Boo: 
     242                    viewCompiler = new BooCodeDomViewCompiler(); 
     243                    break; 
    241244                default: 
    242245                    throw new CompilerException(string.Format("Unknown language type {0}", descriptor.Language));