@@ -98,16 +98,43 @@ protected function writeWith($parser, $path)
9898 $ parser ->write ($ path );
9999 }
100100
101- protected function getPathInfo ($ path , $ newExtension )
101+ /**
102+ * @param string $path
103+ * @param string $newExtension
104+ * @param string|null $relativePath
105+ *
106+ * @return string[]
107+ */
108+ protected function getPathInfo ($ path , $ newExtension , $ relativePath = null )
102109 {
103- $ source = new Path ( $ this ->assetDirectory , $ path );
110+ $ source = $ this ->getSourcePath ( $ path , $ relativePath );
104111 $ extension = pathinfo ($ path , PATHINFO_EXTENSION );
105112 $ path = substr ($ path , 0 , -strlen ($ extension )) . $ newExtension ;
106113 $ destination = $ this ->prepareDirectory (new Path ($ this ->outputDirectory , $ path ));
107114
108115 return array ($ extension , $ path , (string ) $ source , $ destination );
109116 }
110117
118+ /**
119+ * @param string $path
120+ * @param string|null $relativePath
121+ *
122+ * @return Path
123+ */
124+ protected function getSourcePath ($ path , $ relativePath = null )
125+ {
126+ if ($ relativePath ) {
127+ $ relativeSource = new Path ($ path );
128+ $ relativeSource = $ relativeSource ->relativeTo ($ relativePath );
129+
130+ if (file_exists ((string ) $ relativeSource )) {
131+ return $ relativeSource ;
132+ }
133+ }
134+
135+ return new Path ($ this ->assetDirectory , $ path );
136+ }
137+
111138 protected function needUpdate ($ source , $ destination )
112139 {
113140 return !$ this ->dev || !file_exists ($ destination ) || filemtime ($ source ) >= filemtime ($ destination );
@@ -134,9 +161,9 @@ protected function prepareSource($params)
134161 }
135162 }
136163
137- protected function parseScript ($ path )
164+ protected function parseScript ($ path, $ relativePath = null )
138165 {
139- list ($ extension , $ path , $ source , $ destination ) = $ this ->getPathInfo ($ path , 'js ' );
166+ list ($ extension , $ path , $ source , $ destination ) = $ this ->getPathInfo ($ path , 'js ' , $ relativePath );
140167 $ params = (object ) array (
141168 'extension ' => $ extension ,
142169 'type ' => 'script ' ,
@@ -162,9 +189,9 @@ protected function parseScript($path)
162189 return null ;
163190 }
164191
165- protected function parseStyle ($ path )
192+ protected function parseStyle ($ path, $ relativePath = null )
166193 {
167- list ($ extension , $ path , $ source , $ destination ) = $ this ->getPathInfo ($ path , 'css ' );
194+ list ($ extension , $ path , $ source , $ destination ) = $ this ->getPathInfo ($ path , 'css ' , $ relativePath );
168195 $ params = (object ) array (
169196 'extension ' => $ extension ,
170197 'type ' => 'style ' ,
@@ -314,10 +341,10 @@ private function triggerEventAction($action, $event, &$params = null)
314341 }
315342 }
316343
317- public function linkExtractor ($ href , $ rel )
344+ public function linkExtractor ($ href , $ rel, $ relativePath = null )
318345 {
319346 if ($ href && $ rel === 'stylesheet ' ) {
320- $ path = $ this ->parseStyle ($ href );
347+ $ path = $ this ->parseStyle ($ href, $ relativePath );
321348 if ($ this ->dev && $ path ) {
322349 return array (
323350 'href ' => $ path ,
@@ -326,10 +353,10 @@ public function linkExtractor($href, $rel)
326353 }
327354 }
328355
329- public function scriptExtractor ($ src )
356+ public function scriptExtractor ($ src, $ relativePath = null )
330357 {
331358 if ($ src ) {
332- $ path = $ this ->parseScript ($ src );
359+ $ path = $ this ->parseScript ($ src, $ relativePath );
333360 if ($ this ->dev && $ path ) {
334361 return array (
335362 'src ' => $ path ,
0 commit comments