1 /** 2 * Copyright © Yurai Web Framework 2021 3 * License: MIT (https://github.com/YuraiWeb/yurai/blob/main/LICENSE) 4 * Author: Jacob Jensen (bausshf) 5 */ 6 module yurai.templates.templatedata; 7 8 import std.string : strip; 9 import std.array : split; 10 11 import yurai.templates.templatetype; 12 13 public interface ITemplateData 14 { 15 @property TemplateType templateType(); 16 } 17 18 public final class TemplateMeta : ITemplateData 19 { 20 private: 21 string _key; 22 string[] _values; 23 string _value; 24 25 public: 26 final: 27 this(string key, string value) 28 { 29 auto values = value && value.strip.length ? value.strip.split(" ") : []; 30 31 this(key, values); 32 } 33 34 this(string key, string[] values) 35 { 36 _key = key; 37 38 if (values && values.length) 39 { 40 _values = values; 41 _value = _values[0]; 42 } 43 } 44 45 @property 46 { 47 TemplateType templateType() { return TemplateType.meta; } 48 49 string key() { return _key; } 50 51 string[] values() { return _values; } 52 53 string value() { return _value; } 54 } 55 } 56 57 public final class TemplatePlaceholderValue : ITemplateData 58 { 59 private: 60 string _key; 61 string _value; 62 63 public: 64 final: 65 this(string key, string value) 66 { 67 _key = key; 68 _value = value; 69 } 70 71 @property 72 { 73 TemplateType templateType() { return TemplateType.placeholderValue; } 74 75 string key() { return _key; } 76 77 string value() { return _value; } 78 } 79 } 80 81 public final class TemplatePlaceholder : ITemplateData 82 { 83 private: 84 string _language; 85 string _key; 86 string _defaultText; 87 88 public: 89 final: 90 this(string language, string key, string defaultText) 91 { 92 _language = language; 93 _key = key; 94 _defaultText = defaultText; 95 } 96 97 this(string key, string defaultText) 98 { 99 _key = key; 100 _defaultText = defaultText; 101 } 102 103 this(string key) 104 { 105 _key = key; 106 } 107 108 @property 109 { 110 TemplateType templateType() { return TemplateType.placeholder; } 111 112 string language() { return _language; } 113 114 string key() { return _key; } 115 116 string defaultText() { return _defaultText; } 117 } 118 } 119 120 public final class TemplateMixinStatement : ITemplateData 121 { 122 private: 123 string _code; 124 125 public: 126 final: 127 this(string code) 128 { 129 _code = code; 130 } 131 132 @property 133 { 134 TemplateType templateType() { return TemplateType.mixinStatement; } 135 } 136 } 137 138 public final class TemplateMixinCodeBlock : ITemplateData 139 { 140 private: 141 string _code; 142 143 public: 144 final: 145 this(string code) 146 { 147 _code = code; 148 } 149 150 @property 151 { 152 TemplateType templateType() { return TemplateType.mixinCodeBlock; } 153 } 154 } 155 156 public final class TemplateMixinExpression : ITemplateData 157 { 158 private: 159 string _expression; 160 161 public: 162 final: 163 this(string expression) 164 { 165 _expression = expression; 166 } 167 168 @property 169 { 170 TemplateType templateType() { return TemplateType.mixinExpression; } 171 } 172 } 173 174 public final class TemplateMixinEscapeExpression : ITemplateData 175 { 176 private: 177 string _expression; 178 179 public: 180 final: 181 this(string expression) 182 { 183 _expression = expression; 184 } 185 186 @property 187 { 188 TemplateType templateType() { return TemplateType.mixinEscapeExpression; } 189 } 190 } 191 192 public final class TemplateContent : ITemplateData 193 { 194 private: 195 string _content; 196 197 public: 198 final: 199 this(string content) 200 { 201 _content = content; 202 } 203 204 @property 205 { 206 TemplateType templateType() { return TemplateType.content; } 207 } 208 }