Passed
Push — v1 ( 3bfaf6...d06392 )
by Andrew
10:02 queued 04:19
created

ManifestVariable::includeFile()   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 1
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 \Twig_Markup
34
     * @throws \yii\web\NotFoundHttpException
35
     */
36
    public function includeCssModule(string $moduleName, bool $async = false, $config = null): \Twig_Markup
37
    {
38
        return Template::raw(
39
            Twigpack::$plugin->manifest->getCssModuleTags($moduleName, $async, $config)
40
        );
41
    }
42
43
    /**
44
     * Returns the CSS file in $path wrapped in <style></style> tags
45
     *
46
     * @param string $path
47
     *
48
     * @return string
49
     */
50
    public function includeInlineCssTags(string $path): \Twig_Markup
51
    {
52
        return Template::raw(
53
            Twigpack::$plugin->manifest->getCssInlineTags($path)
54
        );
55
    }
56
57
    /**
58
     * Returns the Critical CSS file for $template wrapped in <style></style> tags
59
     *
60
     * @param null|string $name
61
     * @param null|array $config
62
     *
63
     * @return \Twig_Markup
64
     */
65
    public function includeCriticalCssTags($name = null, $config = null): \Twig_Markup
66
    {
67
        return Template::raw(
68
            Twigpack::$plugin->manifest->getCriticalCssTags($name, $config)
69
        );
70
    }
71
72
    /**
73
     * Returns the uglified loadCSS rel=preload Polyfill as per:
74
     * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
75
     *
76
     * @return \Twig_Markup
77
     */
78
    public static function includeCssRelPreloadPolyfill(): \Twig_Markup
79
    {
80
        return Template::raw(
81
            Twigpack::$plugin->manifest->getCssRelPreloadPolyfill()
82
        );
83
    }
84
85
    /**
86
     * @param string     $moduleName
87
     * @param bool       $async
88
     * @param null|array $config
89
     *
90
     * @return null|\Twig_Markup
91
     * @throws \yii\web\NotFoundHttpException
92
     */
93
    public function includeJsModule(string $moduleName, bool $async = false, $config = null)
94
    {
95
        return Template::raw(
96
            Twigpack::$plugin->manifest->getJsModuleTags($moduleName, $async, $config)
97
        );
98
    }
99
100
    /**
101
     * Return the URI to a module
102
     *
103
     * @param string $moduleName
104
     * @param string $type
105
     * @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...
106
     *
107
     * @return null|\Twig_Markup
108
     * @throws \yii\web\NotFoundHttpException
109
     */
110
    public function getModuleUri(string $moduleName, string $type = 'modern', $config = null)
111
    {
112
        return Template::raw(
113
            Twigpack::$plugin->manifest->getModule($moduleName, $type, $config)
114
        );
115
    }
116
117
    /**
118
     * Include the Safari 10.1 nomodule fix JavaScript
119
     *
120
     * @return \Twig_Markup
121
     */
122
    public function includeSafariNomoduleFix(): \Twig_Markup
123
    {
124
        return Template::raw(
125
            Twigpack::$plugin->manifest->getSafariNomoduleFix()
126
        );
127
    }
128
129
    /**
130
     * Returns the contents of a file from a URI path
131
     *
132
     * @param string $path
133
     *
134
     * @return \Twig_Markup
135
     */
136
    public function includeFile(string $path): \Twig_Markup
137
    {
138
        return Template::raw(
139
            Twigpack::$plugin->manifest->getFile($path)
140
        );
141
    }
142
143
    /**
144
     * Returns the contents of a file from the $fileName in the manifest
145
     *
146
     * @param string $fileName
147
     * @param string $type
148
     * @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...
149
     *
150
     * @return \Twig_Markup
151
     */
152
    public function includeFileFromManifest(string $fileName, string $type = 'legacy', $config = null): \Twig_Markup
153
    {
154
        return Template::raw(
155
            Twigpack::$plugin->manifest->getFileFromManifest($fileName, $type, $config)
156
        );
157
    }
158
}
159