|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Cache; |
|
4
|
|
|
|
|
5
|
1 |
|
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
|
1 |
|
if (!function_exists('twillAsset')) { |
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $file |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
function twillAsset($file) |
|
37
|
|
|
{ |
|
38
|
52 |
|
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
|
52 |
|
return json_decode(file_get_contents( |
|
58
|
52 |
|
public_path(config('twill.public_directory', 'twill')) |
|
59
|
52 |
|
. '/' |
|
60
|
52 |
|
. config('twill.manifest_file', 'twill-manifest.json') |
|
61
|
52 |
|
), true); |
|
62
|
52 |
|
}); |
|
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
|
52 |
|
if (isset($manifest[$file])) { |
|
68
|
52 |
|
return $manifest[$file]; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return '/' . config('twill.public_directory', 'twill') . '/' . $file; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
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
|
|
|
|
|
93
|
|
|
if (!function_exists('twillViewName')) { |
|
94
|
|
|
function twillViewName($module, $suffix) |
|
95
|
|
|
{ |
|
96
|
|
|
$view = "'admin.'.$module.'.{$suffix}'"; |
|
97
|
|
|
|
|
98
|
|
|
if (view()->exists($view)) { |
|
99
|
|
|
return $view; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
$prefix = app('twill.capsules.manager')->getCapsuleViewPrefix($module); |
|
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
return "{$prefix}.{$suffix}"; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|