/// <summary> /// Selects the relevant elements. /// </summary> /// <param name="ids">The ids.</param> private void SelectRelevantElements(params string[] ids) { if (ids.Length == 0) { throw new InvalidOperationException("Must pass at least one id"); } CodeGenerator.Write("jQuery("); CodeGenerator.Write(AbstractHelper.Quote(string.Join(",", ids))); CodeGenerator.Write(")"); }
public void RedirectTo(object url) { string target; if (url is IDictionary) { target = jsCodeGenerator.UrlBuilder.BuildUrl( jsCodeGenerator.EngineContext.UrlInfo, url as IDictionary); } else { target = url.ToString(); } Assign("window.location.href", AbstractHelper.Quote(target)); }
/// <summary> /// Pendent /// </summary> /// <param name="position"></param> /// <param name="id"></param> /// <param name="renderOptions"></param> public override void InsertHtml(string position, string id, object renderOptions) { var pos = (Position)Enum.Parse(typeof(Position), position, true); position = pos.ToString(); var selector = id; var render = Render(renderOptions); if (pos == Position.appendTo || pos == Position.prependTo) { selector = render.ToString().Replace("\"", ""); render = AbstractHelper.Quote(id); } SelectRelevantElements(selector); CodeGenerator.Write("." + position); CodeGenerator.Write("(" + render + ");"); WriteNewLine(); }
/// <summary> /// Outputs the content using the renderOptions approach. /// <para> /// If the renderOptions is a string, the content is escaped and quoted. /// </para> /// <para> /// If the renderOptions is a dictionary, we extract the key <c>partial</c> /// and evaluate the template it points to. The content is escaped and quoted. /// </para> /// </summary> /// <param name="renderOptions">The render options.</param> /// <returns></returns> /// <example> /// The following example uses nvelocity syntax: /// <code> /// $page.Call('myJsFunction', $page.render("%{partial='shared/newmessage.vm'}") ) /// </code> /// <para> /// Which outputs: /// </para> /// <code> /// myJsFunction('the content from the newmessage partial view template') /// </code> /// </example> public object Render(object renderOptions) { if (renderOptions == null) { throw new ArgumentNullException("renderOptions", "renderOptions cannot be null. Must be a string or a dictionary"); } if (renderOptions is IDictionary) { var options = (IDictionary)renderOptions; var partialName = (String)options["partial"]; if (partialName == null) { throw new ArgumentNullException("renderOptions", "renderOptions, as a dictionary, must have a 'partial' " + "entry with the template name to render"); } try { var writer = new StringWriter(); viewEngineManager.ProcessPartial(partialName, writer, engineContext, controller, context); // Ideally we would call (less overhead and safer) // viewEngineManager.ProcessPartial(partialName, writer, engineContext, parameters); renderOptions = writer.ToString(); } catch (Exception ex) { throw new MonoRailException("Could not process partial " + partialName, ex); } } return(AbstractHelper.Quote(JsEscape(renderOptions.ToString()))); }
/// <summary> /// Quotes the specified content array. /// </summary> /// <param name="content">The content array.</param> /// <returns></returns> protected string[] Quote(object[] content) { return(AbstractHelper.Quote(content)); }
public void Alert(object message) { Call("alert", AbstractHelper.Quote(message)); }
/// <summary> /// Quotes the specified content. /// </summary> /// <param name="content">The content.</param> /// <returns></returns> protected string Quote(string content) { return(AbstractHelper.Quote(content)); }
/// <summary> /// Replaces the entire target element -- and not only its innerHTML -- /// by the content evaluated. /// </summary> /// <param name="id">The target element id</param> /// <param name="renderOptions">Defines what to render</param> /// <example> /// The following example uses nvelocity syntax: /// <code> /// $page.Replace('messagediv', "%{partial='shared/newmessage.vm'}") /// </code> /// </example> public override void Replace(String id, object renderOptions) { CodeGenerator.Call("Element.replace", AbstractHelper.Quote(id), Render(renderOptions)); }
/// <summary> /// Inserts a content snippet relative to the element specified by the <paramref name="id"/> /// <para> /// The supported positions are /// Top, After, Before, Bottom /// </para> /// </summary> /// <param name="position">The position to insert the content relative to the element id</param> /// <param name="id">The target element id</param> /// <param name="renderOptions">Defines what to render</param> /// <example> /// The following example uses nvelocity syntax: /// <code> /// $page.InsertHtml('Bottom', 'messagestable', "%{partial='shared/newmessage.vm'}") /// </code> /// </example> public override void InsertHtml(string position, string id, object renderOptions) { position = Enum.Parse(typeof(Position), position, true).ToString(); CodeGenerator.Call("new Insertion." + position, AbstractHelper.Quote(id), Render(renderOptions)); }
/// <summary> /// Toggles the display status of the specified elements. /// </summary> /// <param name="ids">The elements ids.</param> /// <remarks> /// The elements must exist. /// </remarks> /// <example> /// The following example uses nvelocity syntax: /// <code> /// $page.Toggle('div1', 'div2') /// </code> /// </example> public override void Toggle(params string[] ids) { CodeGenerator.Call("Element.toggle", AbstractHelper.Quote(ids)); }
/// <summary> /// Shows the specified elements. /// </summary> /// <param name="ids">The elements ids.</param> /// <remarks> /// The elements must exist. /// </remarks> /// <example> /// The following example uses nvelocity syntax: /// <code> /// $page.Show('div1', 'div2') /// </code> /// </example> public override void Show(params string[] ids) { CodeGenerator.Call("Element.show", AbstractHelper.Quote(ids)); }