Skip to content

Commit 278cde4

Browse files
committed
exporting modules to global courseware var
1 parent baf44ce commit 278cde4

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

controllers/courseware.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,26 @@ private function getMustacheTemplates()
199199
// add templates and load less files from block plugins
200200
$plugin_template_files = array();
201201

202-
foreach (\Courseware::$registered_blocks as $path) {
202+
foreach (\Courseware::$registered_blocks as $block) {
203203
$plugin_template_files = array_merge(
204204
$plugin_template_files,
205-
glob($path . '/*/templates/*.mustache')
205+
glob($block['path'] . '/templates/*.mustache')
206206
);
207207

208-
foreach (glob($path . '/*/css/*.less') as $source) {
209-
PageLayout::addHeadElement('style',
210-
['type' => 'text/less'], file_get_contents($source));
208+
// add stylesheets for block to page
209+
foreach (glob($block['path'] . '/css/*.less') as $source) {
210+
PageLayout::addHeadElement('link', [
211+
'rel' => 'stylesheet/less',
212+
'type' => 'text/css',
213+
'href' => UrlHelper::getURL($source, ['cid' => null])
214+
]);
211215
}
216+
217+
// add base js for block to page
218+
PageLayout::addHeadElement('script', [
219+
'src' => URLHelper::getUrl($block['path'] .'/js/'. basename($block['path']) .'.js'),
220+
'type' => 'module'
221+
], '');
212222
}
213223

214224
// add base templates, integrating plugin templates

models/mooc/ui/BlockFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public function getBlockClasses()
4646
if (!isset($classes)) {
4747
$classes = array_map("basename", glob($this->getPluginDir() . '/blocks/*'));
4848

49-
foreach (\Courseware::$registered_blocks as $path) {
50-
$classes = array_merge($classes, array_map("basename", glob($path . '/*')));
49+
foreach (\Courseware::$registered_blocks as $block) {
50+
$classes[] = basename($block['path']);
5151

5252
// load classes in blocks
53-
foreach (glob($path . '/*/*.php') as $class) {
53+
foreach (glob($block['path'] . '/*.php') as $class) {
5454
require_once($class);
5555
}
5656
}

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = {
1717
chunkFilename: '[name].chunk.js',
1818
filename: '[name].js',
1919
pathinfo: !isProd,
20-
publicPath: !isProd ? 'http://localhost:8081/' : undefined
20+
publicPath: !isProd ? 'http://localhost:8081/' : undefined,
21+
library: '[name]'
2122
},
2223
module: {
2324
rules: [

0 commit comments

Comments
 (0)