-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathplugin_builder.sh
66 lines (51 loc) · 1.7 KB
/
plugin_builder.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Check if the script is executed with the correct number of arguments
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <block_name>"
exit 1
fi
# Set the block name from the command line argument
block_name=$1
# Set the Moodle directory
moodle_dir="."
# Set the plugin directory
plugin_dir="${moodle_dir}/block_${block_name}"
# Create the plugin directory and necessary files
mkdir -p "${plugin_dir}" && cd "${plugin_dir}" || exit 1
touch version.php
touch block_${block_name}.php
mkdir -p lang/en
touch lang/en/block_${block_name}.php
# Populate version.php
cat <<EOL > version.php
<?php
defined('MOODLE_INTERNAL') || die();
\$plugin->version = 2023112200; // The current module version (Date: YYYYMMDDXX)
\$plugin->requires = 2019111200; // Requires this Moodle version
\$plugin->component = 'block_${block_name}'; // Full name of the plugin (used for diagnostics)
EOL
# Populate block_${block_name}.php
cat <<EOL > block_${block_name}.php
<?php
class block_${block_name} extends block_base {
public function init() {
\$this->title = get_string('pluginname', 'block_${block_name}');
}
public function get_content() {
if (\$this->content !== null) {
return \$this->content;
}
\$this->content = new stdClass();
\$this->content->text = 'The content of your block goes here.';
\$this->content->footer = 'Footer text here';
return \$this->content;
}
}
EOL
# Populate lang/en/block_${block_name}.php
cat <<EOL > lang/en/block_${block_name}.php
<?php
\$string['pluginname'] = '${block_name} block';
EOL
# Display success message
echo "Moodle block plugin structure and files generated successfully for ${block_name}."