Passed
Push — develop ( 6f08cb...267f63 )
by Andrew
03:33
created

ManifestVariable::includeCssRelPreloadPolyfill()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Twigpack plugin for Craft CMS 3.x
4
 *
5
 * Twigpack is the conduit between Twig and webpack, with manifest.json &
6
 * webpack-dev-server HMR support
7
 *
8
 * @link      https://nystudio107.com/
9
 * @copyright Copyright (c) 2018 nystudio107
10
 */
11
12
namespace nystudio107\twigpack\variables;
13
14
use nystudio107\twigpack\Twigpack;
15
16
use craft\helpers\Template;
17
18
/**
19
 * @author    nystudio107
20
 * @package   Twigpack
21
 * @since     1.0.0
22
 */
23
class ManifestVariable
24
{
25
    // Public Methods
26
    // =========================================================================
27
28
    /**
29
     * @param string     $moduleName
30
     * @param bool       $async
31
     * @param null|array $config
32
     *
33
     * @return null|\Twig_Markup
34
     * @throws \yii\web\NotFoundHttpException
35
     */
36
    public function includeCssModule(string $moduleName, bool $async = false, $config = null)
37
    {
38
        return Template::raw(
39
            Twigpack::$plugin->manifest->getCssModuleTags($moduleName, $async, $config)
40
        );
41
    }
42
43
    /**
44
     * Returns the uglified loadCSS rel=preload Polyfill as per:
45
     * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
46
     *
47
     * @return string
48
     */
49
    public static function includeCssRelPreloadPolyfill(): string
50
    {
51
        return Template::raw(
52
            Twigpack::$plugin->manifest->getCssRelPreloadPolyfill()
53
        );
54
    }
55
56
    /**
57
     * @param string     $moduleName
58
     * @param bool       $async
59
     * @param null|array $config
60
     *
61
     * @return null|\Twig_Markup
62
     * @throws \yii\web\NotFoundHttpException
63
     */
64
    public function includeJsModule(string $moduleName, bool $async = false, $config = null)
65
    {
66
        return Template::raw(
67
            Twigpack::$plugin->manifest->getJsModuleTags($moduleName, $async, $config)
68
        );
69
    }
70
71
    /**
72
     * Return the URI to a module
73
     *
74
     * @param string $moduleName
75
     * @param string $type
76
     * @param null   $config
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $config is correct as it would always require null to be passed?
Loading history...
77
     *
78
     * @return null|\Twig_Markup
79
     * @throws \yii\web\NotFoundHttpException
80
     */
81
    public function getModuleUri(string $moduleName, string $type = 'modern', $config = null)
82
    {
83
        return Template::raw(
84
            Twigpack::$plugin->manifest->getModule($moduleName, $type, $config)
85
        );
86
    }
87
88
    /**
89
     * Include the Safari 10.1 nomodule fix JavaScript
90
     *
91
     * @return \Twig_Markup
92
     */
93
    public function includeSafariNomoduleFix(): \Twig_Markup
94
    {
95
        return Template::raw(
96
            Twigpack::$plugin->manifest->getSafariNomoduleFix()
97
        );
98
    }
99
}
100