public void CompoundPropertyIsEmpty() { XElement element = new XElement("Foo", new XElement("bar") ); MarkupControlInstance control = new MarkupControlInstance(element); Assert.Contains("bar", control.Properties.Keys); Assert.AreEqual(String.Empty, ((MarkupHtmlElement)control.Properties["bar"]).Html); }
/// <summary> /// Elevate the specific control instance to a control class declaration. /// </summary> /// <remarks> /// The simplest way to parse the class definition is to parse it just /// like an instance of a control, then pull out specific properties /// for the name, prototype, script, and style. /// /// The script and style properties are those which were separated out /// by the preprocessor before the control instance was parsed. These /// must now be folded into the control class declaration. /// </remarks> public MarkupControlClass(MarkupControlInstance c, string script, string style) { // Copy over the script and style separated out by the preprocessor. Script = script; Style = style; // Read the explicitly defined class properties. ExtractExplicitClassProperties(c); VerifyProperties(); }
public void ControlContainsHtml() { XElement element = new XElement("Foo", new XElement("h1", "heading"), new XElement("p", "paragraph") ); MarkupControlInstance control = new MarkupControlInstance(element); Assert.IsInstanceOf<MarkupHtmlElement>(control.Properties["content"]); Assert.AreEqual("<h1>heading</h1><p>paragraph</p>", ((MarkupHtmlElement)control.Properties["content"]).Html); }
public void CompoundPropertyContainsText() { XElement element = new XElement("Foo", new XElement("bar", "Compound property value"), new XElement("p", "paragraph") ); MarkupControlInstance control = new MarkupControlInstance(element); Assert.Contains("bar", control.Properties.Keys); Assert.AreEqual("Compound property value", ((MarkupHtmlElement)control.Properties["bar"]).Html); Assert.AreEqual("<p>paragraph</p>", ((MarkupHtmlElement)control.Properties["content"]).Html); }
/// <summary> /// Parse the Quick markup document. /// </summary> public static MarkupControlClass Compile(string markup) { // Preprocess to extract any script and/or style tags. string script; string style; string processed = PreprocessMarkup(markup, out script, out style); // Parse the remaining (processed) source. XElement controlElement = GetControlElement(processed); MarkupControlInstance controlInstance = new MarkupControlInstance(controlElement); MarkupControlClass controlClass = new MarkupControlClass(controlInstance, script, style); return controlClass; }
public void Control() { MarkupControlInstance control = new MarkupControlInstance() { ClassName = "Simple", Id = "foo" }; control.Properties.Add("id", new MarkupHtmlElement("foo")); control.Properties.Add("content", new MarkupHtmlElement("Hello")); Assert.AreEqual( "this._define(\"$foo\", Simple.create({\n" + "\t\"content\": \"Hello\",\n" + "\t\"id\": \"foo\"\n" + "}))", control.JavaScript()); }
public void Control() { MarkupControlInstance control = new MarkupControlInstance() { ClassName = "Simple", Id = "foo" }; control.Properties.Add("id", new MarkupHtmlElement("foo")); control.Properties.Add("content", new MarkupHtmlElement("Hello")); Assert.AreEqual( "{\n" + " control: \"Simple\",\n" + " id: \"foo\",\n" + " content: \"Hello\"\n" + "}", control.JavaScript()); }
/// <summary> /// Parse the Quick markup document. /// </summary> public static MarkupControlClass Compile(string markup) { // Preprocess to extract any script and/or style tags. string script; string style; string processed = PreprocessMarkup(markup, out script, out style); // Parse the remaining (processed) source. XDocument document = GetDocument(processed); IEnumerable<XComment> comments = GetComments(document); XElement controlElement = GetControlElement(document); MarkupControlInstance controlInstance = new MarkupControlInstance(controlElement); MarkupControlClass controlClass = new MarkupControlClass(controlInstance, script, style); AddCommentsToClass(controlClass, comments); return controlClass; }
public MarkupControlClass(MarkupControlInstance control) : this(control, null, null) { }
/// <summary> /// Extract explicitly declared class properties. /// </summary> /// <remarks> /// The parser will read a .qui file as if the whole thing were an instance /// of a class called Control with properties like "name" and "prototype". /// We translate those key properties into the relevant members of the /// ControlClass type. /// /// Note: At this point, the script and style tags are highly unlikely /// to appear, having been previously separated out by the preprocessor. /// However, for completeness, we check here for those properties. The /// only way they could get this far were if they were set as attributes /// of the top-level Control node: <Control script="alert('Hi');"/> which /// would be pretty odd. /// </remarks> private void ExtractExplicitClassProperties(MarkupControlInstance control) { foreach (string propertyName in control.Properties.Keys) { MarkupNode node = control.Properties[propertyName]; string text = (node is MarkupHtmlElement) ? ((MarkupHtmlElement) node).Html : null; switch (propertyName) { case "name": VerifyPropertyIsNull(propertyName, this.Name); this.Name = text; break; case "content": VerifyPropertyIsNull(propertyName, this.Content); this.Content = node; break; case "prototype": VerifyPropertyIsNull(propertyName, this.Prototype); this.Prototype = VerifyPrototype(node); break; case "script": VerifyPropertyIsNull(propertyName, this.Script); this.Script = text; break; case "style": VerifyPropertyIsNull(propertyName, this.Style); this.Style = text; break; case "tag": VerifyPropertyIsNull(propertyName, this.Tag); this.Tag = text; break; default: throw new CompilerException( String.Format("Unknown class definition element: \"{0}\".", propertyName)); } } }
public void ControlPropertyIsReservedWord() { MarkupControlInstance control = new MarkupControlInstance() { ClassName = "Foo", Id = "foo" }; control.Properties.Add("id", new MarkupHtmlElement("foo")); control.Properties.Add("class", new MarkupHtmlElement("bar")); Assert.AreEqual( "{\n" + " control: \"Foo\",\n" + " id: \"foo\",\n" + " \"class\": \"bar\"\n" + "}", control.JavaScript()); }
public void ControlWithAttribute() { XElement element = new XElement("Foo", new XAttribute("bar", "Attribute property value") ); MarkupControlInstance control = new MarkupControlInstance(element); Assert.Contains("bar", control.Properties.Keys); Assert.AreEqual("Attribute property value", ((MarkupHtmlElement)control.Properties["bar"]).Html); }
/// <summary> /// Extract explicitly declared class properties. /// </summary> /// <remarks> /// The parser will read a .qui file as if the whole thing were an instance /// of a class called Control with properties like "name" and "prototype". /// We translate those key properties into the relevant members of the /// ControlClass type. /// /// Note: At this point, the script and style tags are highly unlikely /// to appear, having been previously separated out by the preprocessor. /// However, for completeness, we check here for those properties. The /// only way they could get this far were if they were set as attributes /// of the top-level Control node: <Control script="alert('Hi');"/> which /// would be pretty odd. /// </remarks> private void ExtractExplicitClassProperties(MarkupControlInstance control) { foreach (string propertyName in control.Properties.Keys) { MarkupNode node = control.Properties[propertyName]; string text = (node is MarkupHtmlElement) ? ((MarkupHtmlElement) node).Html : null; switch (propertyName) { case "className": VerifyPropertyIsNull(propertyName, this.Name); this.Name = text; break; case "content": VerifyPropertyIsNull(propertyName, this.Content); this.Content = node; break; case "generic": VerifyPropertyIsNull(propertyName, this.Generic); this.Generic = text; break; case "prototype": VerifyPropertyIsNull(propertyName, this.Prototype); this.Prototype = VerifyPrototype(node); break; case "script": VerifyPropertyIsNull(propertyName, this.Script); this.Script = text; break; case "style": VerifyPropertyIsNull(propertyName, this.Style); this.Style = text; break; case "tag": VerifyPropertyIsNull(propertyName, this.Tag); this.Tag = text; break; default: throw new CompilerException( String.Format("Unknown class definition element: \"{0}\".", propertyName)); } } /* If generic property was set, copy it to prototype. */ if (!String.IsNullOrEmpty(this.Generic)) { if (this.Prototype == null) { this.Prototype = new MarkupControlInstance(); this.Prototype.ClassName = "Control"; if (this.Content != null) { /* Move content over to new prototype as well. */ this.Prototype.Properties["content"] = this.Content; this.Content = null; } } this.Prototype.Properties["generic"] = new MarkupHtmlElement(this.Generic); } }