* Generates the dom which needs to be displayed. This method is called by the MagicMirror² core. * This method can to be overridden if the module wants to display info on the mirror. * Alternatively, the getTemplate method could be overridden. * @returns {HTMLElement|Promise} The dom or a prom
()
| 84 | * @returns {HTMLElement|Promise} The dom or a promise with the dom to display. |
| 85 | */ |
| 86 | getDom () { |
| 87 | return new Promise((resolve) => { |
| 88 | const div = document.createElement("div"); |
| 89 | const template = this.getTemplate(); |
| 90 | const templateData = this.getTemplateData(); |
| 91 | |
| 92 | // Check to see if we need to render a template string or a file. |
| 93 | if ((/^.*((\.html)|(\.njk))$/).test(template)) { |
| 94 | // the template is a filename |
| 95 | this.nunjucksEnvironment().render(template, templateData, function (err, res) { |
| 96 | if (err) { |
| 97 | Log.error(err); |
| 98 | } |
| 99 | |
| 100 | div.innerHTML = res; |
| 101 | |
| 102 | resolve(div); |
| 103 | }); |
| 104 | } else { |
| 105 | // the template is a template string. |
| 106 | div.innerHTML = this.nunjucksEnvironment().renderString(template, templateData); |
| 107 | |
| 108 | resolve(div); |
| 109 | } |
| 110 | }); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Generates the header string which needs to be displayed if a user has a header configured for this module. |
no test coverage detected