|
2 | 2 |
|
3 | 3 | use \Illuminate\Filesystem\Filesystem as Filesystem;
|
4 | 4 | use \Illuminate\Support\Facades\Config as Config;
|
| 5 | +use \Illuminate\Support\Facades\HTML; |
5 | 6 |
|
6 | 7 | class Manager {
|
7 | 8 |
|
@@ -29,49 +30,85 @@ public function __construct(Filesystem $files)
|
29 | 30 | }
|
30 | 31 |
|
31 | 32 | /**
|
32 |
| - * Get HTML for all stylesheets of the bundle |
33 |
| - * |
34 |
| - * @param string $bundle |
35 |
| - * @return string |
| 33 | + * Get HTML for stylesheet of the bundle |
| 34 | + * |
| 35 | +*@param $bundle |
| 36 | + * @param string $folder |
| 37 | + * @param array $option ['index' => 0, 'name'=>'style.name'] |
| 38 | + * Important: name should not contain '-'. |
| 39 | + * |
| 40 | + * @return string stylesheet html |
36 | 41 | */
|
37 |
| - public function styles($bundle) |
| 42 | + public function styles($bundle, $folder = 'css', $option = ['index' => 0]) |
38 | 43 | {
|
39 | 44 | // If we didn't parse the file before, then do it now
|
40 | 45 | if (!$this->data)
|
41 | 46 | {
|
42 | 47 | $this->parseVersionsFile();
|
43 | 48 | }
|
44 |
| - |
45 |
| - // Create link tags for all stylesheets |
46 |
| - foreach ($this->data[$bundle.'.styles'] as $style) |
47 |
| - { |
48 |
| - $styles[] = '<link rel="stylesheet" href="/css/'.$style.'" />'.PHP_EOL; |
| 49 | + // Parser style file with bundle |
| 50 | + $style = ''; |
| 51 | + if (array_key_exists('index', $option)) { |
| 52 | + $index = intval($option['index']); |
| 53 | + $filename = $this->data[$bundle.'.styles'][$index]; |
| 54 | + $style = HTML::style($folder.'/'.$filename); |
| 55 | + } |
| 56 | + else if (array_key_exists('name', $option)) { |
| 57 | + $name = strval($option['name']); |
| 58 | + foreach ($this->data[$bundle.'.styles'] as $filename) { |
| 59 | + $pieces = explode('-', $filename); |
| 60 | + if ($name == $pieces[0]) { |
| 61 | + $style = HTML::style($folder.'/'.$filename); |
| 62 | + break; |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + else { |
| 67 | + $style = HTML::style($folder.'/'.$this->data[$bundle.'.styles'][0]); |
49 | 68 | }
|
50 | 69 |
|
51 |
| - return join(PHP_EOL, $styles); |
| 70 | + return $style.PHP_EOL; |
52 | 71 | }
|
53 | 72 |
|
54 | 73 | /**
|
55 |
| - * Get HTML for all JavaScripts of the bundle |
56 |
| - * |
57 |
| - * @param string $bundle |
58 |
| - * @return string |
| 74 | + * Get HTML for javascript of the bundle |
| 75 | + * @param $bundle |
| 76 | + * @param string $folder |
| 77 | + * @param array $option ['index' => 0, 'name'=>'script.name'] |
| 78 | + * Important: name should not contain '-'. |
| 79 | + * |
| 80 | + * @return string javascript html |
59 | 81 | */
|
60 |
| - public function scripts($bundle) |
| 82 | + public function scripts($bundle, $folder = 'css', $option = ['index' => 0]) |
61 | 83 | {
|
62 | 84 | // If we didn't parse the file before, then do it now
|
63 | 85 | if (!$this->data)
|
64 | 86 | {
|
65 | 87 | $this->parseVersionsFile();
|
66 | 88 | }
|
67 | 89 |
|
68 |
| - // Create script tags for all JavaScripts |
69 |
| - foreach ($this->data[$bundle.'.scripts'] as $script) |
70 |
| - { |
71 |
| - $scripts[] = '<script src="/js/'.$script.'"></script>'.PHP_EOL; |
| 90 | + // Parser script file with bundle |
| 91 | + $script = ''; |
| 92 | + if (array_key_exists('index', $option)) { |
| 93 | + $index = intval($option['index']); |
| 94 | + $filename = $this->data[$bundle.'.scripts'][$index]; |
| 95 | + $script = HTML::script($folder.'/'.$filename); |
| 96 | + } |
| 97 | + else if (array_key_exists('name', $option)) { |
| 98 | + $name = strval($option['name']); |
| 99 | + foreach ($this->data[$bundle.'.styles'] as $filename) { |
| 100 | + $pieces = explode('-', $filename); |
| 101 | + if ($name == $pieces[0]) { |
| 102 | + $script = HTML::script($folder.'/'.$filename); |
| 103 | + break; |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + else { |
| 108 | + $script = HTML::script($folder.'/'.$this->data[$bundle.'.scripts'][0]); |
72 | 109 | }
|
73 | 110 |
|
74 |
| - return join(PHP_EOL, $scripts); |
| 111 | + return $script.PHP_EOL; |
75 | 112 | }
|
76 | 113 |
|
77 | 114 | /**
|
|
0 commit comments