File tree Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Original file line number Diff line number Diff line change 22
33All notable changes to this project will be documented in this file. The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ ) .
44
5+ ## [ 1.2.0] - 2020-02-03
6+
7+ ### Added
8+
9+ - Added the ability to handle array values and auto templates. Thanks [ @iv-agatha ] ( https://github.com/iv-agatha )
10+
511## [ 1.1.1] - 2019-02-20
612
713### Changed
Original file line number Diff line number Diff line change @@ -51,10 +51,18 @@ The `mix()` helper function reads the `mix-manifest.json` file and returns the r
5151<head >
5252 <!-- ... -->
5353 <?php echo mix('/main.css') ?>
54+ <?php echo mix([
55+ '/additional.css',
56+ '@autocss'
57+ ]) ?>
5458</head >
5559<body >
5660 <!-- ... -->
5761 <?php echo mix('/main.js') ?>
62+ <?php echo mix([
63+ '/additional.js',
64+ '@autojs'
65+ ]) ?>
5866</body >
5967</html >
6068```
Original file line number Diff line number Diff line change 1515 */
1616 function mix ($ path )
1717 {
18+ // Handle arrays
19+ if (is_array ($ path )) {
20+ $ assets = [];
21+
22+ foreach ($ path as $ p ) {
23+ $ assets [] = mix ($ p );
24+ }
25+
26+ return implode (PHP_EOL , $ assets ) . PHP_EOL ;
27+ }
28+
1829 static $ manifest = [];
1930
31+ $ isAuto = Str::contains ($ path , '@auto ' );
32+
2033 // Get the correct $path
21- if (!Str::startsWith ($ path , '/ ' )) {
34+ if (!Str::startsWith ($ path , '/ ' ) && ! $ isAuto ) {
2235 $ path = "/ {$ path }" ;
2336 }
2437
@@ -36,7 +49,7 @@ function mix($path)
3649 if (!$ manifest ) {
3750 if (! F::exists ($ manifestPath )) {
3851 if (option ('debug ' )) {
39- throw new Exception ('The Mix manifest does not exists . ' );
52+ throw new Exception ('The Mix manifest does not exist . ' );
4053 } else {
4154 return false ;
4255 }
@@ -45,9 +58,26 @@ function mix($path)
4558 $ manifest = json_decode (F::read ($ manifestPath ), 'json ' );
4659 }
4760
61+ // Get auto templates
62+ if ($ isAuto ) {
63+ if ($ path == '@autocss ' ) {
64+ $ type = 'css ' ;
65+ } else if ($ path == '@autojs ' ) {
66+ $ type = 'js ' ;
67+ } else {
68+ if (option ('debug ' )) {
69+ throw new Exception ("File type not recognized " );
70+ } else {
71+ return false ;
72+ }
73+ }
74+
75+ $ path = '/ ' .$ type .'/templates/ ' .kirby ()->site ()->page ()->intendedTemplate ().'. ' .$ type ;
76+ }
77+
4878 // Check if the manifest contains the given $path
49- if (! array_key_exists ($ path , $ manifest )) {
50- if (option ('debug ' )) {
79+ if (!array_key_exists ($ path , $ manifest )) {
80+ if (option ('debug ' ) && ! $ isAuto ) {
5181 throw new Exception ("Unable to locate Mix file: {$ path }. " );
5282 } else {
5383 return false ;
Original file line number Diff line number Diff line change 22 "name" : " laravel-mix-kirby" ,
33 "description" : " Laravel Mix helper for the Kirby CMS" ,
44 "author" :
" Robert Cordes <[email protected] >" ,
5- "version" : " 1.0 .0" ,
5+ "version" : " 1.2 .0" ,
66 "type" : " kirby-plugin" ,
77 "license" : " MIT"
88}
You can’t perform that action at this time.
0 commit comments