1 /**
2 * Copyright © DiamondMVC 2019
3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module diamond.dom.domattribute;
7 
8 import std..string : strip, toLower;
9 
10 import diamond.errors.checks;
11 
12 /// A dom attribute.
13 final class DomAttribute
14 {
15   private:
16   /// The name of the attribute.
17   string _name;
18   /// The value of the attribute.
19   string _value;
20 
21   public:
22   /**
23   * Creates a new dom attribute.
24   * Params:
25   *   name = The name.
26   *   value = The value.
27   */
28   this(string name, string value) @safe
29   {
30     enforce(name !is null, "The name cannot be null.");
31 
32     _name = name.strip().toLower();
33     _value = value ? value.strip() : null;
34   }
35 
36   @property
37   {
38     /// Gets the name of the attribute.
39     string name() @safe { return _name; }
40 
41     /// Sets the name of the attribute.
42     void name(string newName) @safe
43     {
44       enforce(name !is null, "The name cannot be null.");
45 
46       _name = newName.strip().toLower();
47     }
48 
49     /// Gets the value of the attribute.
50     string value() @safe { return _value; }
51 
52     /// Sets the value of the attribute.
53     void value(string newValue) @safe
54     {
55       _value = newValue ? newValue.strip() : null;
56     }
57   }
58 }