1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Twigpack plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* Twigpack is the conduit between Twig and webpack, with manifest.json & webpack-dev-server HMR support |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com/ |
8
|
|
|
* @copyright Copyright (c) 2018 nystudio107 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace nystudio107\twigpack\variables; |
12
|
|
|
|
13
|
|
|
use nystudio107\twigpack\Twigpack; |
14
|
|
|
|
15
|
|
|
use craft\helpers\Template; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author nystudio107 |
19
|
|
|
* @package Twigpack |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
*/ |
22
|
|
|
class ManifestVariable |
23
|
|
|
{ |
24
|
|
|
// Public Methods |
25
|
|
|
// ========================================================================= |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $moduleName |
29
|
|
|
* @param bool $async |
30
|
|
|
* @param null|array $config |
31
|
|
|
* |
32
|
|
|
* @return null|\Twig_Markup |
33
|
|
|
* @throws \yii\web\NotFoundHttpException |
34
|
|
|
*/ |
35
|
|
|
public function includeCssModule(string $moduleName, bool $async = false, $config = null) |
36
|
|
|
{ |
37
|
|
|
return Template::raw( |
38
|
|
|
Twigpack::$plugin->manifest->getCssModuleTags($moduleName, $async, $config) |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $moduleName |
44
|
|
|
* @param bool $async |
45
|
|
|
* @param null|array $config |
46
|
|
|
* |
47
|
|
|
* @return null|\Twig_Markup |
48
|
|
|
* @throws \yii\web\NotFoundHttpException |
49
|
|
|
*/ |
50
|
|
|
public function includeJsModule(string $moduleName, bool $async = false, $config = null) |
51
|
|
|
{ |
52
|
|
|
return Template::raw( |
53
|
|
|
Twigpack::$plugin->manifest->getJsModuleTags($moduleName, $async, $config) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Return the URI to a module |
59
|
|
|
* |
60
|
|
|
* @param string $moduleName |
61
|
|
|
* @param string $type |
62
|
|
|
* @param null $config |
|
|
|
|
63
|
|
|
* |
64
|
|
|
* @return null|\Twig_Markup |
65
|
|
|
* @throws \yii\web\NotFoundHttpException |
66
|
|
|
*/ |
67
|
|
|
public function getModuleUri(string $moduleName, string $type = 'modern', $config = null) |
68
|
|
|
{ |
69
|
|
|
return Template::raw( |
70
|
|
|
Twigpack::$plugin->manifest->getModule($moduleName, $type, $config) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Include the Safari 10.1 nomodule fix JavaScript |
76
|
|
|
* |
77
|
|
|
* @return null|\Twig_Markup |
78
|
|
|
*/ |
79
|
|
|
public function includeSafariNomoduleFix(): \Twig_Markup |
80
|
|
|
{ |
81
|
|
|
return Template::raw( |
82
|
|
|
Twigpack::$plugin->manifest->getSafariNomoduleFix() |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|