Changeset 223
- Timestamp:
- 11/01/08 01:59:09 (2 months ago)
- Files:
-
- branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Controllers/HomeController.cs (modified) (1 diff)
- branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Views/Home/Index.spark (modified) (3 diffs)
- branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Views/Home/_Global.spark (modified) (1 diff)
- branches/codedom/src/Samples/AspNetMvc/PartialFiles/ViewPage.cs (modified) (1 diff)
- branches/codedom/src/Samples/AspNetMvc/PartialFiles/ViewUserControl.cs (modified) (1 diff)
- branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Home/Alternate.aspx (modified) (1 diff)
- branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Home/Index.spark (modified) (1 diff)
- branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/DefaultLayout.Master (modified) (1 diff)
- branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/DefaultLayout.spark (modified) (1 diff)
- branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/_global.spark (modified) (1 diff)
- branches/codedom/src/Samples/MonoRail/AdvancedPartials/Views/Home/About.spark (modified) (1 diff)
- branches/codedom/src/Samples/MonoRail/AdvancedPartials/Views/Shared/_RoundBox.spark (modified) (1 diff)
- branches/codedom/src/Spark.Tests/App.config (modified) (1 diff)
- branches/codedom/src/Spark.Tests/BooCodeDomViewCompilerTester.cs (added)
- branches/codedom/src/Spark.Tests/CodeDomViewCompilerTester.cs (deleted)
- branches/codedom/src/Spark.Tests/Spark.Tests.Views/Code/foreach.spark (modified) (1 diff)
- branches/codedom/src/Spark.Tests/Spark.Tests.csproj (modified) (2 diffs)
- branches/codedom/src/Spark.Tests/SparkExtensionTester.cs (modified) (2 diffs)
- branches/codedom/src/Spark.Tests/VbCodeDomViewCompilerTester.cs (added)
- branches/codedom/src/Spark/Compiler/CSharp/ChunkVisitors/GeneratedCodeVisitor.cs (modified) (1 diff)
- branches/codedom/src/Spark/Compiler/CodeDom/BooCodeDomViewCompiler.cs (added)
- branches/codedom/src/Spark/Compiler/CodeDom/ChunkVisitors/GeneratedCodeVisitor.cs (modified) (13 diffs)
- branches/codedom/src/Spark/Compiler/CodeDom/CodeDomViewCompiler.cs (modified) (7 diffs)
- branches/codedom/src/Spark/Spark.csproj (modified) (1 diff)
- branches/codedom/src/Spark/SparkViewDescriptor.cs (modified) (1 diff)
- branches/codedom/src/Spark/SparkViewEngine.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Controllers/HomeController.cs
r188 r223 53 53 } 54 54 55 public object Index( string ajax)55 public object Index() 56 56 { 57 57 ViewData["ajaxEnabled"] = (string) Session["ajax"] == "disabled" ? false : true; branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Views/Home/Index.spark
r174 r223 1 1 <h2>Client Rendering Views</h2> 2 2 <p> 3 Ajax <strong>${ajaxEnabled ? 'enabled' : 'disabled'}</strong>. 4 <a href="~/home/enableajax">enable</a> • <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> 5 9 </p> 10 6 11 <p> 7 12 This example shows how you can generate javascript code from a spark file. This js code can be … … 9 14 </p> 10 15 11 <viewdata products="IList[[Models.Product]]" ajaxEnabled="bool"/> 16 <viewdata 17 products="IList[[Models.Product]]" 18 ajaxEnabled="bool"/> 12 19 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> 21 26 22 27 <ul> … … 24 29 ${product.Name} 25 30 ${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> 27 32 </li> 28 33 </ul> 29 34 30 35 <content:subcontent> 31 <a class="refresh" href="~/home/index">Refresh</a> • <a class="cartajax" href="~/home/Reset">Reset cart</a> 36 <a class="refresh" href="~/home/index">Refresh</a> 37 • 38 <a class="cartajax" href="~/home/Reset">Reset cart</a> 32 39 <div id="cart"> 33 40 <ShowCart/> branches/codedom/src/Samples/AspNetMvc/ClientRenderingViews/Views/Home/_Global.spark
r174 r223 1 1 <use namespace="System.Collections.Generic"/> 2 <use namespace="System.Web.Mvc.Html"/> branches/codedom/src/Samples/AspNetMvc/PartialFiles/ViewPage.cs
r188 r223 13 13 // limitations under the License. 14 14 // 15 using System; 15 16 using System.IO; 17 using System.Web; 18 using System.Web.Mvc; 16 19 using System.Web.UI; 17 20 18 21 namespace PartialFiles 19 22 { 23 /// <summary> 24 /// Default ViewPage base class for aspx files in this project. 25 /// Set via system.web/pages/@pageBaseType 26 /// </summary> 27 public class ViewPage : System.Web.Mvc.ViewPage 28 { 29 30 20 31 /// <summary> 21 /// Default ViewPage base class for aspx files in this project.22 /// Set via system.web/pages/@pageBaseType32 /// Must substitute the ViewContext TextWriter, because 33 /// the native HttpContext.Current TextWriter will be used by default 23 34 /// </summary> 24 p ublic class ViewPage : System.Web.Mvc.ViewPage35 protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter tw) 25 36 { 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) 31 41 { 32 if (ViewContext != null)33 return base.CreateHtmlTextWriter(ViewContext.HttpContext.Response.Output);42 return base.CreateHtmlTextWriter(ViewContext.HttpContext.Response.Output); 43 } 34 44 35 return base.CreateHtmlTextWriter(tw); 36 } 45 return base.CreateHtmlTextWriter(tw); 37 46 } 38 47 } 48 } branches/codedom/src/Samples/AspNetMvc/PartialFiles/ViewUserControl.cs
r188 r223 13 13 // limitations under the License. 14 14 // 15 using System.Web; 15 16 using System.Web.UI; 16 17 17 18 namespace PartialFiles 18 19 { 20 /// <summary> 21 /// Default ViewUserControl base class for aspc files in this project. 22 /// Set via system.web/pages/@userControlBaseType 23 /// </summary> 24 public class ViewUserControl : System.Web.Mvc.ViewUserControl 25 { 19 26 /// <summary> 20 /// Default ViewUserControl base class for aspc files in this project.21 /// Set via system.web/pages/@userControlBaseType27 /// Must substitute the ViewContext TextWriter, because 28 /// the native HttpContext.Current TextWriter will be used by default 22 29 /// </summary> 23 public class ViewUserControl : System.Web.Mvc.ViewUserControl30 public override void RenderControl(HtmlTextWriter writer) 24 31 { 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); 33 34 34 base.RenderControl(writer); 35 } 35 if (mayReplace && ViewContext != null) 36 writer.InnerWriter = ViewContext.HttpContext.Response.Output; 37 38 base.RenderControl(writer); 36 39 } 37 40 } 41 } branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Home/Alternate.aspx
r128 r223 3 3 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 4 4 </asp:Content> 5 5 6 <asp:Content ID="Content2" ContentPlaceHolderID="view" runat="server"> 6 7 <p> branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Home/Index.spark
r128 r223 17 17 <Status/> 18 18 </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> 20 26 </div> branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/DefaultLayout.Master
r128 r223 13 13 <% Html.RenderPartial("_menu");%> 14 14 <div> 15 <asp:ContentPlaceHolder ID="view" runat="server"> 16 15 <asp:ContentPlaceHolder ID="view" runat="server"> 17 16 </asp:ContentPlaceHolder> 18 17 </div> branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/DefaultLayout.spark
r128 r223 10 10 <use:view/> 11 11 #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(" ", " ")}17 </code>18 12 </body> 19 13 </html> branches/codedom/src/Samples/AspNetMvc/PartialFiles/Views/Shared/_global.spark
r217 r223 1 1 <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 12 12 <strong>Note: </strong> Some of these techniques are practical, but some are very contrived and are only 13 13 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 16 15 of these ideas could be used appropriately. 17 16 </SmallBox> branches/codedom/src/Samples/MonoRail/AdvancedPartials/Views/Shared/_RoundBox.spark
r192 r223 1 1 <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"> 5 4 .zsnazzy {width:745px;} 6 5 .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 16 16 </pages> 17 17 </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> 18 23 </configuration> 19 24 branches/codedom/src/Spark.Tests/Spark.Tests.Views/Code/foreach.spark
r86 r223 12 12 } 13 13 } 14 branches/codedom/src/Spark.Tests/Spark.Tests.csproj
r221 r223 32 32 </PropertyGroup> 33 33 <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> 34 38 <Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> 35 39 <SpecificVersion>False</SpecificVersion> … … 55 59 </ItemGroup> 56 60 <ItemGroup> 57 <Compile Include="CodeDomViewCompilerTester.cs" /> 61 <Compile Include="BooCodeDomViewCompilerTester.cs" /> 62 <Compile Include="VbCodeDomViewCompilerTester.cs" /> 58 63 <Compile Include="Compiler\ExpressionBuilderTester.cs" /> 59 64 <Compile Include="Compiler\ForEachInspectorTester.cs" /> branches/codedom/src/Spark.Tests/SparkExtensionTester.cs
r187 r223 33 33 { 34 34 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 }; 37 39 } 38 40 … … 62 64 public void VisitNode(INodeVisitor visitor, IList<Node> body, IList<Chunk> chunks) 63 65 { 64 66 65 67 } 66 68 branches/codedom/src/Spark/Compiler/CSharp/ChunkVisitors/GeneratedCodeVisitor.cs
r221 r223 53 53 private void CodeDefault() 54 54 { 55 _source.AppendLine("#line default"); 55 //_source.AppendLine("#line default"); 56 _source.AppendLine("#line hidden"); 56 57 } 57 58 branches/codedom/src/Spark/Compiler/CodeDom/ChunkVisitors/GeneratedCodeVisitor.cs
r222 r223 55 55 protected override void Visit(CodeStatementChunk chunk) 56 56 { 57 Statements.Add(new CodeSnippetStatement(chunk.Code)); 57 Statements.Add( 58 new CodeExpressionStatement( 59 new CodeSnippetExpression(chunk.Code))); 58 60 } 59 61 … … 68 70 protected override void Visit(LocalVariableChunk chunk) 69 71 { 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") 73 88 { 74 89 // not normally supported 75 Statements.Add(_viewCompiler.LanguageSpecific_ImplicitLocalVariable( chunk.Name, chunk.Value));90 Statements.Add(_viewCompiler.LanguageSpecific_ImplicitLocalVariable(name, value)); 76 91 } 77 92 else … … 79 94 // type name = value; 80 95 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); 85 100 } 86 101 Statements.Add(declarationStatement); 87 102 } 88 103 } 89 90 104 protected override void Visit(UseContentChunk chunk) 91 105 { … … 107 121 var writeTo = new CodeExpressionStatement( 108 122 new CodeMethodInvokeExpression( 109 new CodeTypeReferenceExpression( typeof(TextWriterExtensions)),123 new CodeTypeReferenceExpression(new CodeTypeReference(typeof(TextWriterExtensions), CodeTypeReferenceOptions.GlobalReference)), 110 124 "WriteTo", 111 125 new CodeArrayIndexerExpression( … … 134 148 } 135 149 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 136 215 protected override void Visit(ScopeChunk chunk) 137 216 { … … 140 219 { 141 220 // 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. 143 222 144 223 var block = new CodeConditionStatement(new CodePrimitiveExpression(true)); … … 156 235 } 157 236 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 158 342 protected override void Visit(ForEachChunk chunk) 159 343 { 160 344 var forEach = new ForEachInspector(chunk.Code); 161 345 162 346 if (!forEach.Recognized) 163 347 { … … 180 364 autoCount.Detected = true; 181 365 } 182 366 183 367 _variables.PushScope(); 184 368 var scopeAutoVariables = new CodeConditionStatement(new CodePrimitiveExpression(true)); … … 191 375 Statements.Add( 192 376 new CodeVariableDeclarationStatement( 193 typeof (int),377 typeof(int), 194 378 forEach.VariableName + "Index", 195 379 new CodePrimitiveExpression(0))); … … 213 397 forEach.VariableName + "Count", 214 398 new CodeMethodInvokeExpression( 215 new CodeTypeReferenceExpression( typeof(CollectionUtility)),399 new CodeTypeReferenceExpression(new CodeTypeReference(typeof(CollectionUtility), CodeTypeReferenceOptions.GlobalReference)), 216 400 "Count", 217 401 new CodeSnippetExpression(forEach.CollectionCode)))); … … 228 412 Statements.Add( 229 413 new CodeVariableDeclarationStatement( 230 typeof (bool),414 typeof(bool), 231 415 forEach.VariableName + "IsLast", 232 416 new CodeBinaryOperatorExpression( … … 254 438 new CodePrimitiveExpression(1)))); 255 439 } 256 440 257 441 if (autoIsFirst.Detected) 258 442 { … … 284 468 } 285 469 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 286 486 protected override void Visit(MacroChunk chunk) 287 487 { 288 488 // macro declaration doesn't do anything at the point where it occurs 289 489 } 490 290 491 } 291 492 } branches/codedom/src/Spark/Compiler/CodeDom/CodeDomViewCompiler.cs
r221 r223 55 55 { 56 56 var renderViewLevel = new CodeMemberMethod { Name = "RenderViewLevel" + renderLevel }; 57 viewClass.Members.Add(renderViewLevel); 57 viewClass.Members.Add(renderViewLevel); 58 58 59 59 //TODO: bring variables back from globel members … … 66 66 67 67 // public void RenderView(TextWriter writer) 68 // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags68 // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags 69 69 var renderView = new CodeMemberMethod { Name = "RenderView", Attributes = MemberAttributes.Public | MemberAttributes.Override }; 70 // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags70 // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags 71 71 viewClass.Members.Add(renderView); 72 72 renderView.Parameters.Add(new CodeParameterDeclarationExpression(typeof(TextWriter), "writer")); … … 118 118 } 119 119 120 var options = new CodeGeneratorOptions { IndentString = "" }; 120 //var options = new CodeGeneratorOptions { IndentString = "" }; 121 var options = new CodeGeneratorOptions(); 121 122 var source = new StringBuilder(); 122 123 GetCodeDomProvider().GenerateCodeFromCompileUnit(compileUnit, new StringWriter(source), options); … … 162 163 baseClassGenerator.Accept(resource); 163 164 164 var viewBaseType = new CodeTypeReference(baseClassGenerator.BaseClass TypeName);165 var viewBaseType = new CodeTypeReference(baseClassGenerator.BaseClass); 165 166 if (!string.IsNullOrEmpty(baseClassGenerator.TModel)) 166 167 viewBaseType.TypeArguments.Add(baseClassGenerator.TModel); … … 178 179 private void AddSparkViewAttribute(CodeTypeMember viewClass) 179 180 { 180 var viewAttribute = new CodeAttributeDeclaration(new CodeTypeReference( "Spark.SparkViewAttribute"));181 var viewAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(SparkViewAttribute), CodeTypeReferenceOptions.GlobalReference)); 181 182 viewClass.CustomAttributes.Add(viewAttribute); 182 183 if (TargetNamespace != null) … … 193 194 private void AddGeneratedViewId(CodeTypeDeclaration viewClass) 194 195 { 195 // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags196 // ReSharper disable BitwiseOperatorOnEnumWihtoutFlags 196 197 var viewIdProperty = new CodeMemberProperty { Name = "GeneratedViewId", Type = new CodeTypeReference(typeof(Guid)), HasGet = true, Attributes = MemberAttributes.Override | MemberAttributes.Public }; 197 // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags198 // ReSharper restore BitwiseOperatorOnEnumWihtoutFlags 198 199 viewClass.Members.Add(viewIdProperty); 199 200 viewIdProperty.GetStatements.Add( … … 207 208 208 209 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 } 209 230 } 210 231 } branches/codedom/src/Spark/Spark.csproj
r221 r223 64 64 <Compile Include="Compiler\CodeDom\ChunkVisitors\UsingNamespaceVisitor.cs" /> 65 65 <Compile Include="Compiler\CodeDom\CodeDomViewCompiler.cs" /> 66 <Compile Include="Compiler\CodeDom\BooCodeDomViewCompiler.cs" /> 66 67 <Compile Include="Compiler\CodeDom\CsCodeDomViewCompiler.cs" /> 67 68 <Compile Include="Compiler\CodeDom\VbCodeDomViewCompiler.cs" /> branches/codedom/src/Spark/SparkViewDescriptor.cs
r218 r223 21 21 CSharp, 22 22 Javascript, 23 VisualBasic 23 VisualBasic, 24 Boo 24 25 } 25 26 branches/codedom/src/Spark/SparkViewEngine.cs
r221 r223 239 239 viewCompiler = new VbCodeDomViewCompiler(); 240 240 break; 241 case LanguageType.Boo: 242 viewCompiler = new BooCodeDomViewCompiler(); 243 break; 241 244 default: 242 245 throw new CompilerException(string.Format("Unknown language type {0}", descriptor.Language));
