13
13
14
14
use Assetic \Asset \AssetInterface ;
15
15
use Assetic \Factory \AssetFactory ;
16
+ use Assetic \Util \TraversableString ;
16
17
use Symfony \Component \Templating \Helper \Helper ;
17
18
18
19
/**
23
24
abstract class AsseticHelper extends Helper
24
25
{
25
26
protected $ factory ;
26
- protected $ debug ;
27
27
28
28
/**
29
29
* Constructor.
30
30
*
31
31
* @param AssetFactory $factory The asset factory
32
- * @param Boolean $debug The debug mode
33
32
*/
34
- public function __construct (AssetFactory $ factory, $ debug = false )
33
+ public function __construct (AssetFactory $ factory )
35
34
{
36
35
$ this ->factory = $ factory ;
37
- $ this ->debug = $ debug ;
38
36
}
39
37
40
38
/**
@@ -43,7 +41,7 @@ public function __construct(AssetFactory $factory, $debug = false)
43
41
public function javascripts ($ inputs = array (), $ filters = array (), array $ options = array ())
44
42
{
45
43
if (!isset ($ options ['output ' ])) {
46
- $ options ['output ' ] = 'js/* ' ;
44
+ $ options ['output ' ] = 'js/*.js ' ;
47
45
}
48
46
49
47
return $ this ->getAssetUrls ($ inputs , $ filters , $ options );
@@ -55,7 +53,7 @@ public function javascripts($inputs = array(), $filters = array(), array $option
55
53
public function stylesheets ($ inputs = array (), $ filters = array (), array $ options = array ())
56
54
{
57
55
if (!isset ($ options ['output ' ])) {
58
- $ options ['output ' ] = 'css/* ' ;
56
+ $ options ['output ' ] = 'css/*.css ' ;
59
57
}
60
58
61
59
return $ this ->getAssetUrls ($ inputs , $ filters , $ options );
@@ -109,31 +107,37 @@ private function getAssetUrls($inputs = array(), $filters = array(), array $opti
109
107
}
110
108
111
109
if (!isset ($ options ['debug ' ])) {
112
- $ options ['debug ' ] = $ this ->debug ;
110
+ $ options ['debug ' ] = $ this ->factory ->isDebug ();
111
+ }
112
+
113
+ if (!isset ($ options ['combine ' ])) {
114
+ $ options ['combine ' ] = !$ options ['debug ' ];
113
115
}
114
116
115
117
if (isset ($ options ['single ' ]) && $ options ['single ' ] && 1 < count ($ inputs )) {
116
118
$ inputs = array_slice ($ inputs , -1 );
117
119
}
118
120
119
121
if (!isset ($ options ['name ' ])) {
120
- $ options ['name ' ] = $ this ->factory ->generateAssetName ($ inputs , $ filters );
121
- }
122
-
123
- $ coll = $ this ->factory ->createAsset ($ inputs , $ filters , $ options );
124
-
125
- if (!$ options ['debug ' ]) {
126
- return array ($ this ->getAssetUrl ($ coll , $ options ));
122
+ $ options ['name ' ] = $ this ->factory ->generateAssetName ($ inputs , $ filters , $ options );
127
123
}
128
124
129
- $ urls = array ();
130
- foreach ($ coll as $ leaf ) {
131
- $ urls [] = $ this ->getAssetUrl ($ leaf , array_replace ($ options , array (
132
- 'name ' => $ options ['name ' ].'_ ' .count ($ urls ),
133
- )));
125
+ $ asset = $ this ->factory ->createAsset ($ inputs , $ filters , $ options );
126
+
127
+ $ one = $ this ->getAssetUrl ($ asset , $ options );
128
+ $ many = array ();
129
+ if ($ options ['combine ' ]) {
130
+ $ many [] = $ one ;
131
+ } else {
132
+ $ i = 0 ;
133
+ foreach ($ asset as $ leaf ) {
134
+ $ many [] = $ this ->getAssetUrl ($ leaf , array_replace ($ options , array (
135
+ 'name ' => $ options ['name ' ].'_ ' .$ i ++,
136
+ )));
137
+ }
134
138
}
135
139
136
- return $ urls ;
140
+ return new TraversableString ( $ one , $ many ) ;
137
141
}
138
142
139
143
/**
0 commit comments