Passed
Push — develop ( 4586d2...e2c6ed )
by Andrew
04:26
created

ManifestVariable::includeCssModule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace nystudio107\retour\variables;
4
5
use nystudio107\retour\helpers\Manifest as ManifestHelper;
6
use nystudio107\retour\assetbundles\retour\RetourAsset;
7
8
use Craft;
9
use craft\helpers\Template;
10
11
class ManifestVariable
12
{
13
    // Protected Static Properties
14
    // =========================================================================
15
16
    protected static $config = [
17
        // File system path
18
        'basePath'     => '',
19
        // Manifest names
20
        'manifest'     => [
21
            'legacy' => 'manifest-legacy.json',
22
            'modern' => 'manifest.json',
23
        ],
24
        // Public server config
25
        'server'       => [
26
            'publicPath' => '/',
27
        ],
28
        // If `devMode` is on, use webpack-dev-server to all for HMR (hot module reloading)
29
        'useDevServer' => true,
30
        // webpack-dev-server config
31
        'devServer'    => [
32
            'manifestPath' => 'http://127.0.0.1:8080',
33
            'publicPath' => '',
34
        ],
35
    ];
36
37
    // Public Methods
38
    // =========================================================================
39
40
    /**
41
     * ManifestVariable constructor.
42
     */
43
    public function __construct()
44
    {
45
        $bundle = new RetourAsset();
46
        self::$config['basePath'] = Craft::getAlias($bundle->sourcePath);
47
    }
48
49
    /**
50
     * @param string $moduleName
51
     * @param bool   $async
52
     *
53
     * @return \Twig_Markup
54
     */
55
    public function includeCssModule(string $moduleName, bool $async = false): \Twig_Markup
56
    {
57
        return Template::raw(
58
            ManifestHelper::getCssModuleTags(self::$config, $moduleName, $async)
59
        );
60
    }
61
62
    /**
63
     * @param string $moduleName
64
     * @param bool   $async
65
     *
66
     * @return \Twig_Markup
67
     */
68
    public function includeJsModule(string $moduleName, bool $async = false): \Twig_Markup
69
    {
70
        return Template::raw(
71
            ManifestHelper::getJsModuleTags(self::$config, $moduleName, $async)
72
        );
73
    }
74
75
    /**
76
     * @return \Twig_Markup
77
     */
78
    public function includeSafariNomoduleFix(): \Twig_Markup
79
    {
80
        return Template::raw(
81
            ManifestHelper::getSafariNomoduleFix()
82
        );
83
    }
84
}
85