Skip to content

Commit aac47b9

Browse files
committed
exporting modules to global courseware var
1 parent 10ea33e commit aac47b9

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
@@ -192,16 +192,26 @@ private function getMustacheTemplates()
192192
// add templates and load less files from block plugins
193193
$plugin_template_files = array();
194194

195-
foreach (\Courseware::$registered_blocks as $path) {
195+
foreach (\Courseware::$registered_blocks as $block) {
196196
$plugin_template_files = array_merge(
197197
$plugin_template_files,
198-
glob($path . '/*/templates/*.mustache')
198+
glob($block['path'] . '/templates/*.mustache')
199199
);
200200

201-
foreach (glob($path . '/*/css/*.less') as $source) {
202-
PageLayout::addHeadElement('style',
203-
['type' => 'text/less'], file_get_contents($source));
201+
// add stylesheets for block to page
202+
foreach (glob($block['path'] . '/css/*.less') as $source) {
203+
PageLayout::addHeadElement('link', [
204+
'rel' => 'stylesheet/less',
205+
'type' => 'text/css',
206+
'href' => UrlHelper::getURL($source, ['cid' => null])
207+
]);
204208
}
209+
210+
// add base js for block to page
211+
PageLayout::addHeadElement('script', [
212+
'src' => URLHelper::getUrl($block['path'] .'/js/'. basename($block['path']) .'.js'),
213+
'type' => 'module'
214+
], '');
205215
}
206216

207217
// 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)