1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Cache; |
4
|
|
|
|
5
|
|
|
if (!function_exists('revAsset')) { |
6
|
|
|
/** |
7
|
|
|
* @param string $file |
8
|
|
|
* @return string |
9
|
|
|
*/ |
10
|
|
|
function revAsset($file) |
11
|
|
|
{ |
12
|
|
|
if (!app()->environment('local', 'development')) { |
|
|
|
|
13
|
|
|
try { |
14
|
|
|
$manifest = Cache::rememberForever('rev-manifest', function () { |
15
|
|
|
return json_decode(file_get_contents(config('twill.frontend.rev_manifest_path')), true); |
16
|
|
|
}); |
17
|
|
|
|
18
|
|
|
if (isset($manifest[$file])) { |
19
|
|
|
return (rtrim(config('twill.frontend.dist_assets_path'), '/') . '/') . $manifest[$file]; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
} catch (\Exception $e) { |
23
|
|
|
return '/' . $file; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return (rtrim(config('twill.frontend.dev_assets_path'), '/') . '/') . $file; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
if (!function_exists('twillAsset')) { |
32
|
|
|
/** |
33
|
|
|
* @param string $file |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
function twillAsset($file) |
37
|
|
|
{ |
38
|
49 |
|
if (app()->environment('local', 'development') && config('twill.dev_mode', false)) { |
39
|
|
|
$devServerUrl = config('twill.dev_mode_url', 'http://localhost:8080'); |
40
|
|
|
|
41
|
|
|
try { |
42
|
|
|
$manifest = json_decode(file_get_contents( |
43
|
|
|
$devServerUrl |
44
|
|
|
. '/' |
45
|
|
|
. config('twill.manifest_file', 'twill-manifest.json') |
46
|
|
|
), true); |
47
|
|
|
|
48
|
|
|
} catch (\Exception $e) { |
49
|
|
|
throw new \Exception('Twill dev assets manifest is missing. Make sure you are running the npm run serve command inside Twill.'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $devServerUrl . ($manifest[$file] ?? ('/' . $file)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
try { |
56
|
|
|
$manifest = Cache::rememberForever('twill-manifest', function () { |
57
|
49 |
|
return json_decode(file_get_contents( |
58
|
49 |
|
public_path(config('twill.public_directory', 'twill')) |
59
|
49 |
|
. '/' |
60
|
49 |
|
. config('twill.manifest_file', 'twill-manifest.json') |
61
|
49 |
|
), true); |
62
|
49 |
|
}); |
63
|
|
|
} catch (\Exception $e) { |
64
|
|
|
throw new \Exception('Twill assets manifest is missing. Make sure you published/updated Twill assets using the "php artisan twill:update" command.'); |
65
|
|
|
} |
66
|
|
|
|
67
|
49 |
|
if (isset($manifest[$file])) { |
68
|
49 |
|
return $manifest[$file]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return '/' . config('twill.public_directory', 'twill') . '/' . $file; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (!function_exists('icon')) { |
76
|
|
|
/** |
77
|
|
|
* ARIA roles memo: 'presentation' means merely decoration. Otherwise, use role="img". |
78
|
|
|
* |
79
|
|
|
* @param string $name |
80
|
|
|
* @param array $opts |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
function icon($name, $opts = []) |
84
|
|
|
{ |
85
|
|
|
$title = isset($opts['title']) ? ' title="' . htmlentities($opts['title'], ENT_QUOTES, 'UTF-8') . '" ' : ''; |
86
|
|
|
$role = isset($opts['role']) ? ' role="' . htmlentities($opts['role'], ENT_QUOTES, 'UTF-8') . '" ' : ' role="presentation" '; |
87
|
|
|
$css_class = isset($opts['css_class']) ? htmlentities($opts['css_class'], ENT_QUOTES, 'UTF-8') : ''; |
88
|
|
|
$svg_link = config('twill.frontend.svg_sprites_use_hash_only') ? "#icon--$name" : revAsset(config('twill.frontend.svg_sprites_path')) . "#icon--$name"; |
89
|
|
|
return "<svg class=\"icon--$name $css_class\" $title $role><use xlink:href=\"" . $svg_link . "\"></use></svg>"; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|