Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCordes committed Feb 3, 2020
2 parents 1f2fd97 + c3d8239 commit eed6aa8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [1.2.0] - 2020-02-03

### Added

- Added the ability to handle array values and auto templates. Thanks [@iv-agatha](https://github.com/iv-agatha)

## [1.1.1] - 2019-02-20

### Changed
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ The `mix()` helper function reads the `mix-manifest.json` file and returns the r
<head>
<!-- ... -->
<?php echo mix('/main.css') ?>
<?php echo mix([
'/additional.css',
'@autocss'
]) ?>
</head>
<body>
<!-- ... -->
<?php echo mix('/main.js') ?>
<?php echo mix([
'/additional.js',
'@autojs'
]) ?>
</body>
</html>
```
Expand Down
38 changes: 34 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@
*/
function mix($path)
{
// Handle arrays
if (is_array($path)) {
$assets = [];

foreach($path as $p) {
$assets[] = mix($p);
}

return implode(PHP_EOL, $assets) . PHP_EOL;
}

static $manifest = [];

$isAuto = Str::contains($path, '@auto');

// Get the correct $path
if (!Str::startsWith($path, '/')) {
if (!Str::startsWith($path, '/') && !$isAuto) {
$path = "/{$path}";
}

Expand All @@ -36,7 +49,7 @@ function mix($path)
if (!$manifest) {
if (! F::exists($manifestPath)) {
if (option('debug')) {
throw new Exception('The Mix manifest does not exists.');
throw new Exception('The Mix manifest does not exist.');
} else {
return false;
}
Expand All @@ -45,9 +58,26 @@ function mix($path)
$manifest = json_decode(F::read($manifestPath), 'json');
}

// Get auto templates
if ($isAuto) {
if ($path == '@autocss') {
$type = 'css';
} else if($path == '@autojs') {
$type = 'js';
} else {
if(option('debug')) {
throw new Exception("File type not recognized");
} else {
return false;
}
}

$path = '/'.$type.'/templates/'.kirby()->site()->page()->intendedTemplate().'.'.$type;
}

// Check if the manifest contains the given $path
if (! array_key_exists($path, $manifest)) {
if (option('debug')) {
if (!array_key_exists($path, $manifest)) {
if (option('debug') && !$isAuto) {
throw new Exception("Unable to locate Mix file: {$path}.");
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "laravel-mix-kirby",
"description": "Laravel Mix helper for the Kirby CMS",
"author": "Robert Cordes <[email protected]>",
"version": "1.0.0",
"version": "1.2.0",
"type": "kirby-plugin",
"license": "MIT"
}

0 comments on commit eed6aa8

Please sign in to comment.