|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* laravel-assets: asset management for Laravel 5 |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2021 Greg Roach |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Fisharebest\LaravelAssets\Filters; |
|
22
|
|
|
|
|
23
|
|
|
use Fisharebest\LaravelAssets\Assets; |
|
24
|
|
|
use Fisharebest\LaravelAssets\SetStateTrait; |
|
25
|
|
|
|
|
26
|
|
|
class FinalNewline implements FilterInterface |
|
27
|
|
|
{ |
|
28
|
|
|
use SetStateTrait; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Force files to have a trailing end-of-line character. |
|
32
|
|
|
* |
|
33
|
|
|
* "x=3" is valid javascript. "y=4" is valid javascript. But concatentaing these |
|
34
|
|
|
* gives "x=3y=4" which is invalid. Therefore we must make sure that all JS files |
|
35
|
|
|
* end with an end-of-line. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $data The data to be filtered |
|
38
|
|
|
* @param string $asset_url The original URL for this data |
|
39
|
|
|
* @param Assets $assets The asset manager object, for access to its config settings and utilities |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
|
|
public function filter($data, $asset_url, $assets) |
|
44
|
|
|
{ |
|
45
|
|
|
if (substr($data, -1) === "\n") { |
|
46
|
|
|
return $data; |
|
47
|
|
|
} else { |
|
48
|
|
|
return $data . "\n"; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|