Added module loader for external modules

A simple module loader to load modules dropped into the modules folder.
This commit is contained in:
Paul-Vincent Roll 2016-01-27 15:51:36 +01:00
parent 5ca05a3e34
commit c7974e4fa0
6 changed files with 29 additions and 0 deletions

11
controllers/modules.php Normal file
View File

@ -0,0 +1,11 @@
<?php
$modules = array_filter(glob('modules/*'), 'is_dir');
foreach ($modules as &$module) {
//Add JS file of module
print_r('<script src="'.$module.'/main.js" type="text/javascript"></script>'."\xA");
//Add CSS file of module
print_r('<link rel="stylesheet" type="text/css" href="'.$module.'/style.css">'."\xA");
//Get and add HTML Elements
print_r(file_get_contents($module.'/elements.html'));
}
?>

View File

@ -36,5 +36,6 @@
<script src="js/news/news.js"></script> <script src="js/news/news.js"></script>
<script src="js/main.js?nocache=<?php echo md5(microtime()) ?>"></script> <script src="js/main.js?nocache=<?php echo md5(microtime()) ?>"></script>
<!-- <script src="js/socket.io.min.js"></script> --> <!-- <script src="js/socket.io.min.js"></script> -->
<?php include($_SERVER['DOCUMENT_ROOT'].'/controllers/modules.php');?>
</body> </body>
</html> </html>

15
modules/README.md Normal file
View File

@ -0,0 +1,15 @@
MagicMirror
===========
##Modules
A module has to contain three files: main.js, style.css and elements.html
Other files can be loaded from within those.
### elements.html
Put your custom divs and other html elements in this file (don't include any body or header tags)
### main.js
Your plugins JavaScript.
### style.css
CSS for your HTML elements.

View File

@ -0,0 +1 @@
<!--<div id="example"> </div>-->

View File

@ -0,0 +1 @@
console.log("Hello from test-module")

View File