Skip to content

Commit a37dd7e

Browse files
author
HyanCat
committedNov 28, 2014
edit manager for my project.
1 parent 228c690 commit a37dd7e

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed
 

‎src/Modbase/AssetManager/Manager.php

+58-21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use \Illuminate\Filesystem\Filesystem as Filesystem;
44
use \Illuminate\Support\Facades\Config as Config;
5+
use \Illuminate\Support\Facades\HTML;
56

67
class Manager {
78

@@ -29,49 +30,85 @@ public function __construct(Filesystem $files)
2930
}
3031

3132
/**
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
3641
*/
37-
public function styles($bundle)
42+
public function styles($bundle, $folder = 'css', $option = ['index' => 0])
3843
{
3944
// If we didn't parse the file before, then do it now
4045
if (!$this->data)
4146
{
4247
$this->parseVersionsFile();
4348
}
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]);
4968
}
5069

51-
return join(PHP_EOL, $styles);
70+
return $style.PHP_EOL;
5271
}
5372

5473
/**
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
5981
*/
60-
public function scripts($bundle)
82+
public function scripts($bundle, $folder = 'css', $option = ['index' => 0])
6183
{
6284
// If we didn't parse the file before, then do it now
6385
if (!$this->data)
6486
{
6587
$this->parseVersionsFile();
6688
}
6789

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]);
72109
}
73110

74-
return join(PHP_EOL, $scripts);
111+
return $script.PHP_EOL;
75112
}
76113

77114
/**

‎src/config/config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22

33
return [
4-
'file' => 'assets.json',
4+
'file' => 'asset_manifest.json',
55
];

0 commit comments

Comments
 (0)
Please sign in to comment.