nystudio107 /
craft-twigpack
| 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/ |
||||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||||
| 9 | * @copyright Copyright (c) 2018 nystudio107 |
||||
|
0 ignored issues
–
show
|
|||||
| 10 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 11 | |||||
| 12 | namespace nystudio107\twigpack\variables; |
||||
| 13 | |||||
| 14 | use craft\helpers\Template; |
||||
| 15 | use nystudio107\twigpack\Twigpack; |
||||
| 16 | use Twig\Error\LoaderError; |
||||
| 17 | use Twig\Markup; |
||||
| 18 | use yii\web\NotFoundHttpException; |
||||
| 19 | |||||
| 20 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 21 | * @author nystudio107 |
||||
|
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||||
| 22 | * @package Twigpack |
||||
|
0 ignored issues
–
show
|
|||||
| 23 | * @since 1.0.0 |
||||
|
0 ignored issues
–
show
|
|||||
| 24 | */ |
||||
|
0 ignored issues
–
show
|
|||||
| 25 | class ManifestVariable |
||||
| 26 | { |
||||
| 27 | // Public Methods |
||||
| 28 | // ========================================================================= |
||||
| 29 | |||||
| 30 | /** |
||||
| 31 | * Returns the uglified loadCSS rel=preload Polyfill as per: |
||||
| 32 | * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example |
||||
| 33 | * |
||||
| 34 | * @return Markup |
||||
| 35 | */ |
||||
| 36 | public static function includeCssRelPreloadPolyfill(): Markup |
||||
| 37 | { |
||||
| 38 | return Template::raw( |
||||
| 39 | Twigpack::$plugin->manifest->getCssRelPreloadPolyfill() |
||||
| 40 | ); |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 44 | * @param string $moduleName |
||||
|
0 ignored issues
–
show
|
|||||
| 45 | * @param bool $async |
||||
|
0 ignored issues
–
show
|
|||||
| 46 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||
|
0 ignored issues
–
show
|
|||||
| 47 | * |
||||
| 48 | * @return Markup |
||||
| 49 | * @throws NotFoundHttpException |
||||
| 50 | */ |
||||
| 51 | public function includeCssModule(string $moduleName, bool $async = false, array $attributes = []): Markup |
||||
| 52 | { |
||||
| 53 | return Template::raw( |
||||
| 54 | Twigpack::$plugin->manifest->getCssModuleTags($moduleName, $async, null, $attributes) |
||||
| 55 | ); |
||||
| 56 | } |
||||
| 57 | |||||
| 58 | /** |
||||
| 59 | * Returns the CSS file in $path wrapped in <style></style> tags |
||||
| 60 | * |
||||
| 61 | * @param string $path |
||||
|
0 ignored issues
–
show
|
|||||
| 62 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||
|
0 ignored issues
–
show
|
|||||
| 63 | * |
||||
| 64 | * @return Markup |
||||
| 65 | */ |
||||
| 66 | public function includeInlineCssTags(string $path, array $attributes = []): Markup |
||||
| 67 | { |
||||
| 68 | return Template::raw( |
||||
| 69 | Twigpack::$plugin->manifest->getCssInlineTags($path, $attributes) |
||||
| 70 | ); |
||||
| 71 | } |
||||
| 72 | |||||
| 73 | /** |
||||
| 74 | * Returns the Critical CSS file for $template wrapped in <style></style> |
||||
| 75 | * tags |
||||
| 76 | * |
||||
| 77 | * @param null|string $name |
||||
|
0 ignored issues
–
show
|
|||||
| 78 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||
|
0 ignored issues
–
show
|
|||||
| 79 | * |
||||
| 80 | * @return Markup |
||||
| 81 | * @throws LoaderError |
||||
| 82 | */ |
||||
| 83 | public function includeCriticalCssTags(?string $name = null, array $attributes = []): Markup |
||||
| 84 | { |
||||
| 85 | return Template::raw( |
||||
| 86 | Twigpack::$plugin->manifest->getCriticalCssTags($name, null, $attributes) |
||||
| 87 | ); |
||||
| 88 | } |
||||
| 89 | |||||
| 90 | /** |
||||
|
0 ignored issues
–
show
|
|||||
| 91 | * @param string $moduleName |
||||
|
0 ignored issues
–
show
|
|||||
| 92 | * @param bool $async |
||||
|
0 ignored issues
–
show
|
|||||
| 93 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||
|
0 ignored issues
–
show
|
|||||
| 94 | * |
||||
| 95 | * @return Markup |
||||
| 96 | * @throws NotFoundHttpException |
||||
| 97 | */ |
||||
| 98 | public function includeJsModule(string $moduleName, bool $async = false, array $attributes = []): Markup |
||||
| 99 | { |
||||
| 100 | return Template::raw( |
||||
| 101 | Twigpack::$plugin->manifest->getJsModuleTags($moduleName, $async, null, $attributes) |
||||
| 102 | ); |
||||
| 103 | } |
||||
| 104 | |||||
| 105 | /** |
||||
| 106 | * Return the URI to a module |
||||
| 107 | * |
||||
| 108 | * @param string $moduleName |
||||
|
0 ignored issues
–
show
|
|||||
| 109 | * @param string $type |
||||
|
0 ignored issues
–
show
|
|||||
| 110 | * @param null $config |
||||
|
0 ignored issues
–
show
|
|||||
| 111 | * |
||||
| 112 | * @return Markup |
||||
| 113 | * @throws NotFoundHttpException |
||||
| 114 | */ |
||||
| 115 | public function getModuleUri(string $moduleName, string $type = 'modern', $config = null): Markup |
||||
| 116 | { |
||||
| 117 | return Template::raw( |
||||
| 118 | Twigpack::$plugin->manifest->getModule($moduleName, $type, $config) |
||||
|
0 ignored issues
–
show
It seems like
nystudio107\twigpack\Twi...leName, $type, $config) can also be of type null; however, parameter $value of craft\helpers\Template::raw() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 119 | ); |
||||
| 120 | } |
||||
| 121 | |||||
| 122 | /** |
||||
| 123 | * Return the HASH value from a module |
||||
| 124 | * |
||||
| 125 | * @param string $moduleName |
||||
|
0 ignored issues
–
show
|
|||||
| 126 | * @param string $type |
||||
|
0 ignored issues
–
show
|
|||||
| 127 | * @param null $config |
||||
|
0 ignored issues
–
show
|
|||||
| 128 | * |
||||
| 129 | * @return Markup |
||||
| 130 | * @throws NotFoundHttpException |
||||
| 131 | */ |
||||
| 132 | public function getModuleHash(string $moduleName, string $type = 'modern', $config = null): Markup |
||||
| 133 | { |
||||
| 134 | return Template::raw( |
||||
| 135 | Twigpack::$plugin->manifest->getModuleHash($moduleName, $type, $config) |
||||
| 136 | ); |
||||
| 137 | } |
||||
| 138 | |||||
| 139 | /** |
||||
| 140 | * Include the Safari 10.1 nomodule fix JavaScript |
||||
| 141 | * |
||||
| 142 | * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag |
||||
| 143 | * |
||||
| 144 | * @return Markup |
||||
| 145 | */ |
||||
| 146 | public function includeSafariNomoduleFix(array $attributes = []): Markup |
||||
| 147 | { |
||||
| 148 | return Template::raw( |
||||
| 149 | Twigpack::$plugin->manifest->getSafariNomoduleFix($attributes) |
||||
| 150 | ); |
||||
| 151 | } |
||||
| 152 | |||||
| 153 | /** |
||||
| 154 | * Returns the contents of a file from a URI path |
||||
| 155 | * |
||||
| 156 | * @param string $path |
||||
|
0 ignored issues
–
show
|
|||||
| 157 | * |
||||
| 158 | * @return Markup |
||||
| 159 | */ |
||||
| 160 | public function includeFile(string $path): Markup |
||||
| 161 | { |
||||
| 162 | return Template::raw( |
||||
| 163 | Twigpack::$plugin->manifest->getFile($path) |
||||
| 164 | ); |
||||
| 165 | } |
||||
| 166 | |||||
| 167 | /** |
||||
| 168 | * Returns the contents of a file from the $fileName in the manifest |
||||
| 169 | * |
||||
| 170 | * @param string $fileName |
||||
|
0 ignored issues
–
show
|
|||||
| 171 | * @param string $type |
||||
|
0 ignored issues
–
show
|
|||||
| 172 | * @param null $config |
||||
|
0 ignored issues
–
show
|
|||||
| 173 | * |
||||
| 174 | * @return Markup |
||||
| 175 | */ |
||||
| 176 | public function includeFileFromManifest(string $fileName, string $type = 'legacy', $config = null): Markup |
||||
| 177 | { |
||||
| 178 | return Template::raw( |
||||
| 179 | Twigpack::$plugin->manifest->getFileFromManifest($fileName, $type, $config) |
||||
| 180 | ); |
||||
| 181 | } |
||||
| 182 | } |
||||
| 183 |