/// <summary> /// Aplica a propriedade à saída de um controle. /// </summary> /// <param name="target">Controle alvo</param> /// <param name="property">Propriedade sendo aplicada</param> /// <param name="value">Valor da propriedade sendo aplicada</param> /// <param name="result">Resultado da saida da renderização atual.</param> public void ApplyProperty(HtmlObject target, ControlProperty property, object value, ControlPropertyApplyResult result) { var thickness = value as Thickness; if (value != null && thickness.IsSetted()) { if (thickness.AllValuesIsSetted()) { result.Styles[CssAttribute] = thickness.GetAllValuesString(); } else { var str = CssAttribute.ToString().ToLower(); if (thickness.Top.HasValue) { result.Styles[CssConfig.GetEnumItemFromCssName <CssProperty>(str + "-top")] = thickness.GetTopStringValue(); } if (thickness.Bottom.HasValue) { result.Styles[CssConfig.GetEnumItemFromCssName <CssProperty>(str + "-bottom")] = thickness.GetBottomStringValue(); } if (thickness.Left.HasValue) { result.Styles[CssConfig.GetEnumItemFromCssName <CssProperty>(str + "-left")] = thickness.GetLeftStringValue(); } if (thickness.Right.HasValue) { result.Styles[CssConfig.GetEnumItemFromCssName <CssProperty>(str + "-right")] = thickness.GetRightStringValue(); } } } }
public void MixedCaseRuleValue_RetainsCasing() { var attribute = CssAttribute.FromRule(" color: rED"); Assert.AreEqual("color", attribute.Style); Assert.AreEqual("rED", attribute.Value); }
void Validate(IEnumerable <CssRule> rules) { if (rules == null || rules.Count() == 0) { return; } foreach (var rule in rules) { CssAttribute attr = rule as CssAttribute; if (attr != null) { if (attr.IsValid) { attr.IsValid = Validate(attr); } continue; } CssImport import = rule as CssImport; if (import != null) { import.IsValid = EmbedStyleSheets; } ICssRulesContainer container = rule as ICssRulesContainer; if (container != null) { Validate(container.Selectors); } } }
public void MixedCaseRule_RetainsCasing() { var attribute = CssAttribute.FromRule("Margin-bottom: 10px"); Assert.AreEqual("Margin-bottom", attribute.Style); Assert.AreEqual("10px", attribute.Value); }
public void StandandUnimportantRule_ReturnsAttribute() { var attribute = CssAttribute.FromRule("color: red"); Assert.AreEqual("color", attribute.Style); Assert.AreEqual("red", attribute.Value); }
public void SingleAttribute_ShouldNotAppendSemiColonToString() { var clazz = new StyleClass(); clazz.Attributes["color"] = CssAttribute.FromRule("color: red"); Assert.AreEqual("color: red", clazz.ToString()); }
public void ImportantRule_EmitsImportantAttributeOnlyWhenSpecified() { var attribute = CssAttribute.FromRule("color: red !important"); Assert.Equal("color: red", attribute.ToString()); Assert.Equal("color: red", attribute.ToString(emitImportant: false)); Assert.Equal("color: red !important", attribute.ToString(emitImportant: true)); }
public void ImportantRule_ReturnsValidCssWithoutWhitespaces() { var attribute = CssAttribute.FromRule("color:red!important"); Assert.Equal("color", attribute.Style); Assert.Equal("red", attribute.Value); Assert.True(attribute.Important); }
public void ImportantRule_ReturnsImportantAttribute() { var attribute = CssAttribute.FromRule("color: red !important"); Assert.AreEqual("color", attribute.Style); Assert.AreEqual("red", attribute.Value); Assert.IsTrue(attribute.Important); }
public void MultipleAttributes_ShouldJoinAttributesWithSemiColonInString() { var clazz = new StyleClass(); clazz.Attributes["color"] = CssAttribute.FromRule("color: red"); clazz.Attributes["height"] = CssAttribute.FromRule("height: 100%"); Assert.AreEqual("color: red;height: 100%", clazz.ToString()); }
public void Merge_ShouldEmitImportantOnlyWhenSpecified() { var clazz = new StyleClass(); clazz.Attributes["color"] = CssAttribute.FromRule("color: red !important"); Assert.Equal("color: red", clazz.ToString()); Assert.Equal("color: red", clazz.ToString(emitImportant: false)); Assert.Equal("color: red !important", clazz.ToString(emitImportant: true)); }
/// <summary> /// Initializes a new CssSize. /// </summary> /// <param name="element">The element.</param> /// <param name="width">The width CSS property.</param> /// <param name="height">The height CSS property.</param> public CssSize(HtmlControlBase element, CssAttribute width, CssAttribute height) : base() { _mhe = element; _cssProperties = new CssAttribute[] { width, height }; }
/// <summary> /// Initializes a new CssBox type with the specified CSS property names. /// </summary> /// <param name="element">The parent managed HTML element.</param> /// <param name="top">The top property.</param> /// <param name="right">The right property.</param> /// <param name="bottom">The bottom property.</param> /// <param name="left">The left property.</param> public CssBox(HtmlControlBase element, CssAttribute top, CssAttribute right, CssAttribute bottom, CssAttribute left) : base() { _mhe = element; _cssProperties = new CssAttribute[] { top, right, bottom, left }; }
/// <summary> /// Sets the style property. /// </summary> /// <param name="style">The style enum name.</param> /// <param name="value">The new value.</param> private void SetStyleProperty(CssAttribute style, Unit value) { if (value == null) { _mhe.RemoveStyleAttribute(style); } else { _mhe.SetStyleAttribute(style, value.ToString()); } }
/// <summary> /// Sets a style property. /// </summary> /// <param name="style">The style name.</param> /// <param name="value">The value to set.</param> protected void SetStyleProperty(CssAttribute style, Unit value) { if (value == null || value.IsEmpty) { _mhe.RemoveStyleAttribute(style); } else { _mhe.SetStyleAttribute(style, value); } }
public void FindEquivalentStyles() { var tableDomObject = CQ.CreateFragment("<td id=\"tabletest\" class=\"test\" bgcolor=\"\"></td>"); var nodewithoutselector = tableDomObject.FirstElement(); var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssStyleEquivalence.FindEquivalent(nodewithoutselector, clazz); Assert.AreEqual(1, result.Count); }
public void Merge_ShouldAddNonExistingAttributesToClass() { var target = new StyleClass(); var donator = new StyleClass(); target.Attributes["color"] = CssAttribute.FromRule("color: red"); donator.Attributes["height"] = CssAttribute.FromRule("height: 100%"); target.Merge(donator, true); Assert.IsTrue(target.Attributes.ContainsKey("height")); Assert.AreEqual("100%", target.Attributes["height"].Value); }
/// <summary> /// Gets a CSS value. /// </summary> /// <param name="property">The property name.</param> /// <returns>Returns the actual value as a string.</returns> private string GetCssValue(CssAttribute property) { string val = null; try { string str = _owner.GetStyleAttribute(property); val = str; } catch (ArgumentException) { } return val; }
public void FindEquivalentStyles() { var tableDomObject = new HtmlParser().Parse("<table id=\"tabletest\" class=\"test\" bgcolor=\"\"></table>"); var nodewithoutselector = (IElement)tableDomObject.Body.FirstChild; var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssStyleEquivalence.FindEquivalent(nodewithoutselector, clazz); Assert.AreEqual(1, result.Count); }
public void Merge_ShouldNotOverrideExistingEntriesIfNotSpecified() { var target = new StyleClass(); var donator = new StyleClass(); target.Attributes["color"] = CssAttribute.FromRule("color: red"); target.Attributes["height"] = CssAttribute.FromRule("height: 50%"); donator.Attributes["height"] = CssAttribute.FromRule("height: 100%"); target.Merge(donator, false); Assert.IsTrue(target.Attributes.ContainsKey("height")); Assert.AreEqual("50%", target.Attributes["height"].Value); }
/// <summary> /// Gets a CSS value. /// </summary> /// <param name="property">The property name.</param> /// <returns>Returns the actual value as a string.</returns> private string GetCssValue(CssAttribute property) { string val = null; try { string str = _owner.GetStyleAttribute(property); val = str; } catch (ArgumentException) { } return(val); }
public void Merge_ShouldOverrideExistingImportantEntriesIfNewEntryIsImportant() { var target = new StyleClass(); var donator = new StyleClass(); target.Attributes["color"] = CssAttribute.FromRule("color: red"); target.Attributes["height"] = CssAttribute.FromRule("height: 50% !important"); donator.Attributes["height"] = CssAttribute.FromRule("height: 100% !important"); target.Merge(donator, true); Assert.IsTrue(target.Attributes.ContainsKey("height")); Assert.AreEqual("100%", target.Attributes["height"].Value); }
public void Merge_ShouldOverrideExistingEntriesIfSpecifiedIgnoringCasing() { var target = new StyleClass(); var donator = new StyleClass(); target.Attributes["color"] = CssAttribute.FromRule("color: red"); target.Attributes["HEight"] = CssAttribute.FromRule("height: 50%"); donator.Attributes["height"] = CssAttribute.FromRule("height: 100%"); target.Merge(donator, true); Assert.True(target.Attributes.ContainsKey("height")); Assert.Equal("100%", target.Attributes["height"].Value); }
public void GetAllStylesForElement() { var tableDomObject = new HtmlParser().ParseDocument("<table id=\"tabletest\" class=\"test\" bgcolor=\"\"></table>"); var nodewithoutselector = (IElement)tableDomObject.Body.FirstChild; var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssElementStyleResolver.GetAllStyles(nodewithoutselector, clazz); Assert.AreEqual(2, result.Count()); Assert.AreEqual("style", result.ElementAt(0).AttributeName); Assert.AreEqual("bgcolor", result.ElementAt(1).AttributeName); }
public void GetAllStylesForElement() { var tableDomObject = CQ.CreateFragment("<td id=\"tabletest\" class=\"test\" bgcolor=\"\"></td>"); var nodewithoutselector = tableDomObject.FirstElement(); var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssElementStyleResolver.GetAllStyles(nodewithoutselector, clazz); Assert.AreEqual(2, result.Count()); Assert.AreEqual("style", result.ElementAt(0).AttributeName); Assert.AreEqual("bgcolor", result.ElementAt(1).AttributeName); }
public void ApplyInlineStylesWithoutImportant() { var document = new HtmlParser().ParseDocument("<div></div>"); var clazz = new StyleClass(); clazz.Attributes["color"] = CssAttribute.FromRule("color: #000 !important"); var elementDictionary = new Dictionary <IElement, StyleClass> { { document.Body.FirstElementChild, clazz } }; var result = StyleClassApplier.ApplyAllStyles(elementDictionary); Assert.Equal("<div style=\"color: #000\"></div>", result.ElementAt(0).Key.OuterHtml); }
public void ApplyStylesToAllElements() { var elementDictionary = new Dictionary <IDomObject, StyleClass>(); var tableDomObject1 = CQ.CreateFragment("<td id=\"tabletest1\" class=\"test1\" bgcolor=\"\"></td>"); var tableDomObject2 = CQ.CreateFragment("<td id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"\"></td>"); var tableDomObject3 = CQ.CreateFragment("<td id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"\"></td>"); var tableDomObject4 = CQ.CreateFragment("<td id=\"tabletest4\" class=\"test4\" bgcolor=\"\" width=\"\"></td>"); var styleClassBgColor = new StyleClass(); styleClassBgColor.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008001"); var styleClassWidth = new StyleClass(); styleClassWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px"); var styleClassHeight = new StyleClass(); styleClassHeight.Attributes["height"] = CssAttribute.FromRule("height: 10px"); var styleClassBgAndWidth = new StyleClass(); styleClassBgAndWidth.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008003"); styleClassBgAndWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px"); elementDictionary.Add(tableDomObject1.FirstElement(), styleClassBgColor); elementDictionary.Add(tableDomObject2.FirstElement(), styleClassWidth); elementDictionary.Add(tableDomObject3.FirstElement(), styleClassHeight); elementDictionary.Add(tableDomObject4.FirstElement(), styleClassBgAndWidth); var result = StyleClassApplier.ApplyAllStyles(elementDictionary); Assert.AreEqual("<td class=\"test1\" style=\"background-color: #008001\" id=\"tabletest1\" bgcolor=\"#008001\"></td>", result.ElementAt(0).Key.ToString()); Assert.AreEqual("<td class=\"test2\" style=\"width: 10px\" id=\"tabletest2\" bgcolor width=\"10px\"></td>", result.ElementAt(1).Key.ToString()); Assert.AreEqual("<td class=\"test3\" style=\"height: 10px\" id=\"tabletest3\" bgcolor height=\"10px\"></td>", result.ElementAt(2).Key.ToString()); Assert.AreEqual("<td class=\"test4\" style=\"background-color: #008003;width: 10px\" id=\"tabletest4\" bgcolor=\"#008003\" width=\"10px\"></td>", result.ElementAt(3).Key.ToString()); }
public void ApplyStylesToAllElements() { var elementDictionary = new Dictionary <IElement, StyleClass>(); var tableDomObject1 = new HtmlParser().ParseDocument("<table id=\"tabletest1\" class=\"test1\" bgcolor=\"\"></table>"); var tableDomObject2 = new HtmlParser().ParseDocument("<table id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"\"></table>"); var tableDomObject3 = new HtmlParser().ParseDocument("<table id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"\"></table>"); var tableDomObject4 = new HtmlParser().ParseDocument("<table id=\"tabletest4\" class=\"test4\" bgcolor=\"\" width=\"\"></table>"); var styleClassBgColor = new StyleClass(); styleClassBgColor.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008001"); var styleClassWidth = new StyleClass(); styleClassWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px"); var styleClassHeight = new StyleClass(); styleClassHeight.Attributes["height"] = CssAttribute.FromRule("height: 10px"); var styleClassBgAndWidth = new StyleClass(); styleClassBgAndWidth.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008003"); styleClassBgAndWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px"); elementDictionary.Add(tableDomObject1.Body.FirstElementChild, styleClassBgColor); elementDictionary.Add(tableDomObject2.Body.FirstElementChild, styleClassWidth); elementDictionary.Add(tableDomObject3.Body.FirstElementChild, styleClassHeight); elementDictionary.Add(tableDomObject4.Body.FirstElementChild, styleClassBgAndWidth); var result = StyleClassApplier.ApplyAllStyles(elementDictionary); Assert.Equal("<table id=\"tabletest1\" class=\"test1\" bgcolor=\"#008001\" style=\"background-color: #008001\"></table>", result.ElementAt(0).Key.OuterHtml); Assert.Equal("<table id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"10px\" style=\"width: 10px\"></table>", result.ElementAt(1).Key.OuterHtml); Assert.Equal("<table id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"10px\" style=\"height: 10px\"></table>", result.ElementAt(2).Key.OuterHtml); Assert.Equal("<table id=\"tabletest4\" class=\"test4\" bgcolor=\"#008003\" width=\"10px\" style=\"background-color: #008003;width: 10px\"></table>", result.ElementAt(3).Key.OuterHtml); }
/// <summary> /// Set a value on the owning HtmlElement. /// </summary> /// <param name="property">The CSS property.</param> /// <param name="val">The value.</param> private void SetCssValue(CssAttribute property, string val) { _owner.SetStyleAttribute(property, val); }
/// <summary> /// Gets the style attribute. /// </summary> /// <param name="name">The attribute to get.</param> /// <returns>Returns the string value of the style attribute.</returns> public string GetStyleAttribute(CssAttribute name) { return GetStyleAttribute(name.ScriptPropertyName()); }
/// <summary> /// Remove a style attribute from the element. /// </summary> /// <param name="name">The style attribute name.</param> public void RemoveStyleAttribute(CssAttribute name) { RemoveStyleAttribute(name.ScriptPropertyName()); }
public void FromRule_OnlySplitsTheRuleAtTheFirstColonToSupportUrls() { var attribute = CssAttribute.FromRule("background: url('http://my.web.site.com/Content/email/content.png') repeat-y"); Assert.AreEqual("url('http://my.web.site.com/Content/email/content.png') repeat-y", attribute.Value); }
public void NonRule_ReturnsNull() { var attribute = CssAttribute.FromRule(" "); Assert.IsNull(attribute); }
/// <summary> /// Sets the style attribute. /// </summary> /// <param name="name">Attribute name.</param> /// <param name="value">The value to set the property to.</param> public void SetStyleAttribute(CssAttribute name, string value) { SetStyleAttribute(name.ScriptPropertyName(), value); }
/// <summary> /// Sets the style attribute. /// </summary> /// <param name="name">Attribute name.</param> /// <param name="unit">The value to set the property to.</param> public void SetStyleAttribute(CssAttribute name, Unit unit) { SetStyleAttribute(name, unit.ToString()); }
/// <summary> /// Sets the style attribute. /// </summary> /// <param name="name">Attribute name.</param> /// <param name="enumValue">The value to set the property to.</param> public void SetStyleAttribute(CssAttribute name, Enum enumValue) { SetStyleAttribute(name, enumValue.ScriptPropertyName()); }