| 
									
										
										
										
											2017-07-06 12:17:57 +01:00
										 |  |  | module.exports = function getExampleRegion(exampleMap, createDocMessage, collectExamples) { | 
					
						
							| 
									
										
										
										
											2017-03-23 12:54:29 +00:00
										 |  |  |   return function getExampleRegionImpl(doc, relativePath, regionName) { | 
					
						
							|  |  |  |     const EXAMPLES_FOLDERS = collectExamples.exampleFolders; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Find the example in the folders
 | 
					
						
							|  |  |  |     var exampleFile; | 
					
						
							|  |  |  |     // Try an "annotated" version first
 | 
					
						
							|  |  |  |     EXAMPLES_FOLDERS.some(EXAMPLES_FOLDER => { return exampleFile = exampleMap[EXAMPLES_FOLDER][relativePath + '.annotated']; }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // If no annotated version is available then try the actual file
 | 
					
						
							|  |  |  |     if (!exampleFile) { | 
					
						
							|  |  |  |       EXAMPLES_FOLDERS.some(EXAMPLES_FOLDER => { return exampleFile = exampleMap[EXAMPLES_FOLDER][relativePath]; }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // If still no file then we error
 | 
					
						
							|  |  |  |     if (!exampleFile) { | 
					
						
							| 
									
										
										
										
											2017-09-19 10:15:39 +01:00
										 |  |  |       const gitIgnoreFile = collectExamples.isExampleIgnored(relativePath); | 
					
						
							| 
									
										
										
										
											2018-10-18 14:32:32 +03:00
										 |  |  |       if (gitIgnoreFile) { | 
					
						
							| 
									
										
										
										
											2017-09-19 10:15:39 +01:00
										 |  |  |         const message = createDocMessage('Ignored example file... relativePath: "' + relativePath + '"', doc) + '\n' + | 
					
						
							|  |  |  |         'This example file exists but has been ignored by a rule, in "' + gitIgnoreFile + '".'; | 
					
						
							|  |  |  |         throw new Error(message); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         const message = createDocMessage('Missing example file... relativePath: "' + relativePath + '".', doc) + '\n' + | 
					
						
							|  |  |  |             'Example files can be found in the following relative paths: ' + EXAMPLES_FOLDERS.map(function(folder) { return '"' + folder + '"'; }).join(', '); | 
					
						
							|  |  |  |         throw new Error(message); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-03-23 12:54:29 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var sourceCodeDoc = exampleFile.regions[regionName || '']; | 
					
						
							|  |  |  |     if (!sourceCodeDoc) { | 
					
						
							| 
									
										
										
										
											2017-07-06 12:17:57 +01:00
										 |  |  |       const message = createDocMessage('Missing example region... relativePath: "' + relativePath + '", region: "' + regionName + '".', doc) + '\n' + | 
					
						
							| 
									
										
										
										
											2017-09-19 10:15:39 +01:00
										 |  |  |                       'Regions available are: ' + Object.keys(exampleFile.regions).map(function(region) { return '"' + region + '"'; }).join(', '); | 
					
						
							| 
									
										
										
										
											2017-07-06 12:17:57 +01:00
										 |  |  |       throw new Error(message); | 
					
						
							| 
									
										
										
										
											2017-03-23 12:54:29 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return sourceCodeDoc.renderedContent; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; |