// Copyright 2004-2008 Castle Project - http://www.castleproject.org/ // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Castle.MonoRail.Framework.JSGeneration.Prototype { using System; /// /// Implementation for the /// public class PrototypeElementGenerator : IJSElementGenerator { private readonly PrototypeGenerator generator; #region Constructor /// /// Initializes a new instance of the class. /// /// The generator. /// The root. public PrototypeElementGenerator(PrototypeGenerator generator, String root) { this.generator = generator; generator.CodeGenerator.Record("$('" + root + "')"); } #endregion /// /// Gets the parent generator. /// /// The parent generator. public IJSGenerator ParentGenerator { get { return generator; } } #region Dispatchable operations /// /// Replaces the content of the element. /// /// Defines what to render /// /// The following example uses nvelocity syntax: /// /// $page.el('elementid').ReplaceHtml("%{partial='shared/newmessage.vm'}") /// /// public void ReplaceHtml(object renderOptions) { generator.CodeGenerator.ReplaceTailByPeriod(); generator.CodeGenerator.Call("update", generator.Render(renderOptions)); } /// /// Replaces the entire element's content -- and not only its innerHTML -- /// by the content evaluated. /// /// Defines what to render /// /// The following example uses nvelocity syntax: /// /// $page.el('messagediv').Replace("%{partial='shared/newmessage.vm'}") /// /// public void Replace(object renderOptions) { generator.CodeGenerator.ReplaceTailByPeriod(); generator.CodeGenerator.Call("replace", generator.Render(renderOptions)); } #endregion } }