| 
									
										
										
										
											2022-07-24 15:30:19 +02:00
										 |  |  | import * as plugins from './smarthbs.plugins.js'; | 
					
						
							| 
									
										
										
										
											2017-03-19 17:14:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * registers a directory of partials to make them available within handlebars compilation | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-05-01 16:57:53 +02:00
										 |  |  | export let registerPartialDir = (dirPathArg: string): Promise<any> => { | 
					
						
							| 
									
										
										
										
											2018-08-27 23:04:15 +02:00
										 |  |  |   let done = plugins.smartpromise.defer(); | 
					
						
							| 
									
										
										
										
											2022-07-24 15:30:19 +02:00
										 |  |  |   plugins.smartfile.fs.listFileTree(dirPathArg, '**/*.hbs').then((hbsFileArrayArg) => { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:14:28 +01:00
										 |  |  |     for (let hbsFilePath of hbsFileArrayArg) { | 
					
						
							| 
									
										
										
										
											2018-08-27 23:04:15 +02:00
										 |  |  |       let parsedPath = plugins.path.parse(hbsFilePath); | 
					
						
							|  |  |  |       let hbsFileString = plugins.smartfile.fs.toStringSync( | 
					
						
							|  |  |  |         plugins.path.join(dirPathArg, hbsFilePath) | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2017-05-11 14:51:20 +02:00
										 |  |  |       if (parsedPath.dir === '/') { | 
					
						
							| 
									
										
										
										
											2018-08-27 23:04:15 +02:00
										 |  |  |         parsedPath.dir = ''; | 
					
						
							| 
									
										
										
										
											2017-03-19 17:14:28 +01:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-05-11 14:51:20 +02:00
										 |  |  |       if (parsedPath.dir !== '') { | 
					
						
							| 
									
										
										
										
											2018-08-27 23:04:15 +02:00
										 |  |  |         parsedPath.dir = parsedPath.dir + '/'; | 
					
						
							| 
									
										
										
										
											2017-05-11 14:51:20 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-08-27 23:04:15 +02:00
										 |  |  |       let partialName = `partials/${parsedPath.dir}${parsedPath.name}`; | 
					
						
							|  |  |  |       plugins.handlebars.registerPartial(partialName, hbsFileString); | 
					
						
							|  |  |  |       done.resolve(); | 
					
						
							| 
									
										
										
										
											2017-03-19 17:14:28 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-27 23:04:15 +02:00
										 |  |  |   }); | 
					
						
							|  |  |  |   return done.promise; | 
					
						
							|  |  |  | }; |