|
3 | 3 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
4 | 4 | * obtain one at https://mozilla.org/MPL/2.0/ |
5 | 5 | * |
6 | | - * Copyright (C) 2005-2021, Peter Johnson (gravatar.com/delphidabbler). |
| 6 | + * Copyright (C) 2005-2022, Peter Johnson (gravatar.com/delphidabbler). |
7 | 7 | * |
8 | 8 | * Classes that help create and manage cascading style sheet code. |
9 | 9 | } |
@@ -46,12 +46,25 @@ TCSSSelector = class(TObject) |
46 | 46 | {Checks whether the selector is empty, i.e. contains no code. |
47 | 47 | @return True if selector is empty and false if not. |
48 | 48 | } |
49 | | - procedure AddProperty(const CSSProp: string); |
50 | | - {Adds a new CSS property to the selector. |
51 | | - @param CSSProp [in] CSS property to be added. |
52 | | - } |
| 49 | + /// <summary>Adds a new CSS property to the selector.</summary> |
| 50 | + /// <param name="CSSProp">string [in] Property definition.</param> |
| 51 | + /// <returns>TCSSSelector. Class instance returned to enable the method to |
| 52 | + /// be chained.</returns> |
| 53 | + function AddProperty(const CSSProp: string): TCSSSelector; |
| 54 | + /// <summary>Adds a new CSS property to the selector depending on a given |
| 55 | + /// condition.</summary> |
| 56 | + /// <param name="Condition">Boolean [in] Condition that determines which |
| 57 | + /// CSS property is added.</param> |
| 58 | + /// <param name="CSSPropTrue">string [in] CSS property that is added when |
| 59 | + /// Condition is True.</param> |
| 60 | + /// <param name="CSSPropFalse">string [in] CSS property that is added when |
| 61 | + /// Condition is False.</param> |
| 62 | + /// <returns>TCSSSelector. Class instance returned to enable the method to |
| 63 | + /// be chained.</returns> |
| 64 | + function AddPropertyIf(const Condition: Boolean; |
| 65 | + const CSSPropTrue: string; const CSSPropFalse: string = ''): TCSSSelector; |
| 66 | + /// <summary>Name of selector.</summary> |
53 | 67 | property Selector: string read fSelector; |
54 | | - {Name of selector} |
55 | 68 | end; |
56 | 69 |
|
57 | 70 | { |
@@ -112,12 +125,20 @@ implementation |
112 | 125 |
|
113 | 126 | { TCSSSelector } |
114 | 127 |
|
115 | | -procedure TCSSSelector.AddProperty(const CSSProp: string); |
116 | | - {Adds a new CSS property to the selector. |
117 | | - @param CSSProp [in] CSS property to be added. |
118 | | - } |
| 128 | +function TCSSSelector.AddProperty(const CSSProp: string): TCSSSelector; |
119 | 129 | begin |
120 | 130 | fProperties.Add(CSSProp); |
| 131 | + Result := Self; |
| 132 | +end; |
| 133 | + |
| 134 | +function TCSSSelector.AddPropertyIf(const Condition: Boolean; |
| 135 | + const CSSPropTrue: string; const CSSPropFalse: string): TCSSSelector; |
| 136 | +begin |
| 137 | + if Condition then |
| 138 | + AddProperty(CSSPropTrue) |
| 139 | + else if CSSPropFalse <> '' then |
| 140 | + AddProperty(CSSPropFalse); |
| 141 | + Result := Self; |
121 | 142 | end; |
122 | 143 |
|
123 | 144 | function TCSSSelector.AsString: string; |
|
0 commit comments