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.markdown.part; 7 8 import diamond.markdown.type; 9 10 /// Wrapper around a markdown part. 11 final class MarkdownPart 12 { 13 private: 14 /// The type. 15 MarkdownType _type; 16 /// The content. 17 string _content; 18 /// The volume. 19 size_t _volume; 20 /// The metadata. 21 string[string] _metadata; 22 23 public: 24 final: 25 /** 26 * Creates a new markdown part. 27 * Params: 28 * type = The type of the markdown part. 29 */ 30 this(MarkdownType type) 31 { 32 _type = type; 33 } 34 35 @property 36 { 37 /// Gets the type of the markdown part. 38 MarkdownType type() { return _type; } 39 40 /// Gets the content of the markdown part. 41 string content() { return _content; } 42 43 /// Gets the volume of the markdown part. 44 size_t volume() { return _volume; } 45 46 package(diamond.markdown) 47 { 48 /// Sets the type of the markdown part. 49 void type(MarkdownType newType) 50 { 51 _type = newType; 52 } 53 54 /// Sets the content of the markdown part. 55 void content(string newContent) 56 { 57 _content = newContent; 58 } 59 60 /// Sets the volume of the markdown part. 61 void volume(size_t newVolume) 62 { 63 _volume = newVolume; 64 } 65 } 66 } 67 68 /** 69 * Gets a metadata value. 70 * Params: 71 * key = The key of the metadata to get. 72 * Returns: 73 * The metadata value if existing, null otherwise. 74 */ 75 string getMetadata(string key) 76 { 77 return _metadata.get(key, null); 78 } 79 80 /** 81 * Sets a metadata. 82 * Params: 83 * key = The key of the metadata. 84 * value = The value of the metadata. 85 */ 86 package(diamond.markdown) void setMetadata(string key, string value) 87 { 88 _metadata[key] = value; 89 } 90 }