Skip to content

Commit 5206642

Browse files
committed
add draft for getting snippets info from plain php files
1 parent 55f4ce5 commit 5206642

File tree

4 files changed

+91
-50
lines changed

4 files changed

+91
-50
lines changed

classes/snippets.php

+13-34
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,27 @@
2525
*/
2626
class snippets {
2727
/**
28-
* Definition of builtin snippets.
29-
* @var array
28+
* Get a snippet defined in the code based on key and domain.
29+
* @param string $key
30+
* @param string $domain
31+
* @return mixed
3032
*/
31-
const SNIPPETS = [
32-
'fix_border' => [
33-
'domain' => 'theme_boost_union',
34-
'title' => 'Fix Borders',
35-
'description' => 'Those borders are annoying',
36-
'scope' => 'global',
37-
'goal' => 'bug fix',
38-
'css' => '.border {radius: 4px;}',
39-
],
40-
'fix_font_color' => [
41-
'domain' => 'theme_boost_union',
42-
'title' => 'Fix font color',
43-
'scope' => 'login',
44-
'goal' => 'eye candy',
45-
'description' => 'Those borders are annoying',
46-
'css' => 'body {color: 4px;}',
47-
],
48-
'bigger_title' => [
49-
'domain' => 'theme_boost_union',
50-
'title' => 'Bigger title',
51-
'scope' => 'course',
52-
'description' => 'Make the course titles finally big enough!',
53-
'goal' => 'eye candy',
54-
'css' => 'h1 {font-size: 70px;}',
55-
],
56-
];
33+
public static function get_snippet($key, $domain = 'theme_boost_union') {
34+
if ('theme_boost_union' == $domain) {
35+
return require_once(__DIR__ . sprintf('/theme/boost_union/snippets/builtin/%s.php', $key));
36+
}
37+
}
5738

5839
/**
5940
* Compose snippets data.
6041
* @param mixed $snippets
6142
* @return void
6243
*/
6344
public static function compose_snippets_data($snippets) {
64-
foreach ($snippets as $row => $snippet) {
65-
if ('code' === $snippet->source) {
66-
$snippet->title = self::SNIPPETS[$snippet->key]['title'];
67-
$snippet->description = self::SNIPPETS[$snippet->key]['description'];
68-
$snippet->goal = self::SNIPPETS[$snippet->key]['goal'];
69-
$snippet->scope = self::SNIPPETS[$snippet->key]['scope'];
45+
foreach ($snippets as $row => $meta) {
46+
if ('code' === $meta->source) {
47+
$snippet = self::get_snippet($meta->key, $meta->domain);
48+
$snippets[$row] = array_merge($meta, $snippet);
7049
} else {
7150
unset($snippets[$row]);
7251
}

snippets/builtin/bigger_title.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* CSS Snippet for fixing the borders.
19+
*
20+
* @package theme_boost_union
21+
* @copyright 2024 University of Graz
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
return [
28+
'domain' => 'theme_boost_union',
29+
'title' => 'Bigger title',
30+
'scope' => 'course',
31+
'description' => 'Make the course titles finally big enough!',
32+
'goal' => 'eyecandy',
33+
'css' => 'h1 {font-size: 70px;}',
34+
];

snippets/builtin/fix_border.php

+10-16
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,13 @@
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
2424

25-
class Fix_Border {
26-
27-
public $source;
28-
29-
public $domain;
30-
31-
public $key;
32-
33-
public $title;
34-
35-
public $description;
36-
37-
public $css;
38-
39-
public $enabled;
40-
}
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
return [
28+
'domain' => 'theme_boost_union',
29+
'title' => 'Fix Borders',
30+
'description' => 'Those borders are annoying',
31+
'scope' => 'global',
32+
'goal' => 'bugfix',
33+
'css' => '.border {radius: 4px;}',
34+
];

snippets/builtin/fix_font.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* CSS Snippet for fixing the borders.
19+
*
20+
* @package theme_boost_union
21+
* @copyright 2024 University of Graz
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
return [
28+
'domain' => 'theme_boost_union',
29+
'title' => 'Fix font color',
30+
'scope' => 'login',
31+
'goal' => 'eyecandy',
32+
'description' => 'Those borders are annoying',
33+
'css' => 'body {color: 4px;}',
34+
];

0 commit comments

Comments
 (0)