@@ -170,37 +170,72 @@ private function childHasInterestingData(Frame $child): bool
170170 || !empty ($ child ->getChildren ());
171171 }
172172
173- private function writeFrame (Frame $ frame , ?string $ linkPrefix ): string
173+ private function writeFrame (Frame $ frame , ?string $ linkPrefix, ? string $ typeOverride = null ): string
174174 {
175175 $ data = '' ;
176+ $ globalChildrenWithParentKey = [];
176177 foreach ($ frame ->getChildren () as $ child ) {
177178 if ($ this ->childHasInterestingData ($ child )) {
178179 $ data .= $ this ->writeFrame ($ child , $ linkPrefix );
180+ if ($ child ->getName () && $ child ->getParentKey ()) {
181+ $ globalChildrenWithParentKey [$ child ->getParentKey ()] = $ child ->getName ();
182+ }
183+ }
184+ }
185+ $ inheritedKeyValues = [];
186+ foreach ($ frame ->getInherits () as $ templateName ) {
187+ $ template = $ this ->templateRegistry ->get ($ templateName );
188+ if (!$ template ) {
189+ continue ;
190+ }
191+ foreach ($ template ->getKeyValues () as $ key => $ value ) {
192+ $ inheritedKeyValues [$ key ] = $ value ;
193+ }
194+ foreach ($ template ->getChildren () as $ child ) {
195+ $ clone = $ child ->withParent ($ frame );
196+ if (!empty ($ clone ->getName ())) { // will create a global
197+ $ data .= $ this ->writeFrame (
198+ $ clone ,
199+ $ linkPrefix ,
200+ $ this ->childHasInterestingData ($ child ) ? $ child ->getClassName () : $ child ->getType (), // this must be $child rather than $clone
201+ );
202+ if ($ clone ->getParentKey ()) {
203+ $ inheritedKeyValues [$ clone ->getParentKey ()] = [$ clone ->getName ()];
204+ }
205+ }
179206 }
180207 }
181208
182209 if ($ linkPrefix ) {
183210 $ data .= "--- [Source]( $ linkPrefix#L " . $ frame ->getLineNumber () . ") \n" ;
184211 }
185212 if ($ frame ->getParent ()) {
186- $ data .= '--- child of ' . $ frame ->getParent ()->getName () . "\n" ;
213+ $ data .= '--- child of ' . $ frame ->getParent ()->getName ();
214+ if ($ frame ->getOriginalParent () && $ frame ->getOriginalParent () !== $ frame ->getParent ()) {
215+ $ data .= ' (created in template ' . $ frame ->getOriginalParent ()->getName () . ') ' ;
216+ }
217+ $ data .= "\n" ;
187218 }
188219 if ($ frame instanceof Intrinsic) {
189220 $ data .= "--- Intrinsic \n" ;
190221 } elseif ($ frame instanceof Template) {
191222 $ data .= "--- Template \n" ;
192223 }
193- $ data .= '--- @class ' . $ frame ->getClassName () . ' : ' . $ frame ->getType ();
194- foreach ($ frame ->getInherits () as $ inherit ) {
195- $ data .= ', ' . $ inherit ;
196- }
197- foreach ($ frame ->getMixins () as $ mixin ) {
198- $ data .= ', ' . $ mixin ;
224+ if ($ typeOverride ) {
225+ $ data .= '--- @type ' . $ typeOverride ;
226+ } else {
227+ $ data .= '--- @class ' . $ frame ->getClassName () . ' : ' . $ frame ->getType ();
228+ foreach ($ frame ->getInherits () as $ inherit ) {
229+ $ data .= ', ' . $ inherit ;
230+ }
231+ foreach ($ frame ->getMixins () as $ mixin ) {
232+ $ data .= ', ' . $ mixin ;
233+ }
199234 }
200235 $ data .= "\n" ;
201236
202237 foreach ($ frame ->getKeyValues () as $ key => $ value ) {
203- $ data .= '--- @field ' . $ key . ' ' . $ value . "\n" ;
238+ $ data .= '--- @field ' . $ key . ' ' . $ value[ 1 ] . ' # ' . $ value [ 0 ] . "\n" ;
204239 }
205240 foreach ($ frame ->getChildren () as $ child ) {
206241 if ($ child ->getParentKey ()) {
@@ -213,9 +248,15 @@ private function writeFrame(Frame $frame, ?string $linkPrefix): string
213248 }
214249 if ($ frame ->getName () && $ frame ->getRootNode ()::class === Frame::class) {
215250 $ data .= $ frame ->getName () . " = {} \n" ;
216- foreach ($ frame -> getKeyValues () as $ key => $ value ) {
251+ foreach ($ globalChildrenWithParentKey as $ key => $ value ) {
217252 $ data .= $ frame ->getName () . '[" ' . $ key . '"] = ' . $ value . "\n" ;
218253 }
254+ foreach ($ frame ->getKeyValues () as $ key => $ value ) {
255+ $ data .= $ frame ->getName () . '[" ' . $ key . '"] = ' . $ value [0 ] . "\n" ;
256+ }
257+ foreach ($ inheritedKeyValues as $ key => $ value ) {
258+ $ data .= $ frame ->getName () . '[" ' . $ key . '"] = ' . $ value [0 ] . " -- inherited \n" ;
259+ }
219260 }
220261
221262 return $ data . "\n" ;
0 commit comments