mirror of
				https://github.com/JuanCanham/HackMyResume.git
				synced 2025-10-31 05:07:26 +00:00 
			
		
		
		
	Scrub theme.js.
This commit is contained in:
		| @@ -33,72 +33,74 @@ Abstract theme representation. | |||||||
|       return friendly[val] || val; |       return friendly[val] || val; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Open the theme.json file; should have the same name as folder |     // Open the [theme-name].json file; should have the same name as folder | ||||||
|     this.folder = themeFolder; |     this.folder = themeFolder; | ||||||
|     var pathInfo = PATH.parse( themeFolder ); |     var pathInfo = PATH.parse( themeFolder ); | ||||||
|     var themeFile = PATH.join( themeFolder, pathInfo.base + '.json' ); |     var themeFile = PATH.join( themeFolder, pathInfo.base + '.json' ); | ||||||
|     var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) ); |     var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) ); | ||||||
|  |  | ||||||
|  |     // Move properties from the theme JSON file to the theme object | ||||||
|     EXTEND( true, this, themeInfo ); |     EXTEND( true, this, themeInfo ); | ||||||
|  |  | ||||||
|  |     // Set up a hash of formats supported by this theme. | ||||||
|     var formatsHash = { }; |     var formatsHash = { }; | ||||||
|  |  | ||||||
|     // Iterate over all files in the theme folder, producing an array, fmts, |     // Establish the base theme folder | ||||||
|     // containing info for each file. |  | ||||||
|     var tplFolder = PATH.join( themeFolder, 'src' ); |     var tplFolder = PATH.join( themeFolder, 'src' ); | ||||||
|     var fmts = RECURSIVE_READ_DIR( tplFolder ).map( |  | ||||||
|       function( absPath ) { |  | ||||||
|  |  | ||||||
|         var pathInfo = PATH.parse(absPath); |     // Iterate over all files in the theme folder, producing an array, fmts, | ||||||
|  |     // containing info for each file. While we're doing that, also build up | ||||||
|  |     // the formatsHash object. | ||||||
|  |     var fmts = RECURSIVE_READ_DIR( tplFolder ).map( function( absPath ) { | ||||||
|  |  | ||||||
|         // If this file lives in a specific format folder within the theme, |       // If this file lives in a specific format folder within the theme, | ||||||
|         // such as "/latex" or "/html", then that format is the output format |       // such as "/latex" or "/html", then that format is the output format | ||||||
|         // for all files within the folder. |       // for all files within the folder. | ||||||
|         var outFmt = ''; |       var pathInfo = PATH.parse(absPath); | ||||||
|         var portion = pathInfo.dir.replace(tplFolder,''); |       var outFmt = ''; | ||||||
|         if( portion && portion.trim() ) { |       var portion = pathInfo.dir.replace(tplFolder,''); | ||||||
|           var reg = /^(?:\/|\\)(html|latex|doc|pdf)(?:\/|\\)?/ig; |       if( portion && portion.trim() ) { | ||||||
|           var res = reg.exec( portion ); |         var reg = /^(?:\/|\\)(html|latex|doc|pdf)(?:\/|\\)?/ig; | ||||||
|           res && (outFmt = res[1]); |         var res = reg.exec( portion ); | ||||||
|         } |         res && (outFmt = res[1]); | ||||||
|  |  | ||||||
|         // Otherwise, the output format is inferred from the filename, as in |  | ||||||
|         // compact-[outputformat].[extension], for ex, compact-pdf.html. |  | ||||||
|         if( !outFmt ) { |  | ||||||
|           var idx = pathInfo.name.lastIndexOf('-'); |  | ||||||
|           outFmt = ( idx === -1 ) ? pathInfo.name : pathInfo.name.substr( idx + 1 ) |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // We should have a valid output format now |  | ||||||
|         formatsHash[ outFmt ] = formatsHash[outFmt] || { outFormat: outFmt, files: [] }; |  | ||||||
|  |  | ||||||
|         var obj = { |  | ||||||
|           path: absPath, |  | ||||||
|           ext: pathInfo.ext.slice(1), |  | ||||||
|           title: friendlyName( outFmt ), |  | ||||||
|           pre: outFmt, |  | ||||||
|           // outFormat: outFmt || pathInfo.name, |  | ||||||
|           data: FS.readFileSync( absPath, 'utf8' ), |  | ||||||
|           css: null |  | ||||||
|         }; |  | ||||||
|  |  | ||||||
|         // Add this file to the list of files for this format type. |  | ||||||
|         formatsHash[ outFmt ].files.push( obj ); |  | ||||||
|         return obj; |  | ||||||
|       } |       } | ||||||
|     ); |  | ||||||
|  |       // Otherwise, the output format is inferred from the filename, as in | ||||||
|  |       // compact-[outputformat].[extension], for ex, compact-pdf.html. | ||||||
|  |       if( !outFmt ) { | ||||||
|  |         var idx = pathInfo.name.lastIndexOf('-'); | ||||||
|  |         outFmt = ( idx === -1 ) ? pathInfo.name : pathInfo.name.substr( idx + 1 ) | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       // We should have a valid output format now. | ||||||
|  |       formatsHash[ outFmt ] = formatsHash[outFmt] || { outFormat: outFmt, files: [] }; | ||||||
|  |  | ||||||
|  |       // Create the file representation object. | ||||||
|  |       var obj = { | ||||||
|  |         path: absPath, | ||||||
|  |         ext: pathInfo.ext.slice(1), | ||||||
|  |         title: friendlyName( outFmt ), | ||||||
|  |         pre: outFmt, | ||||||
|  |         // outFormat: outFmt || pathInfo.name, | ||||||
|  |         data: FS.readFileSync( absPath, 'utf8' ), | ||||||
|  |         css: null | ||||||
|  |       }; | ||||||
|  |  | ||||||
|  |       // Add this file to the list of files for this format type. | ||||||
|  |       formatsHash[ outFmt ].files.push( obj ); | ||||||
|  |       return obj; | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     // Add freebie formats every theme gets |     // Add freebie formats every theme gets | ||||||
|     formatsHash[ 'json' ] = { title: 'json', outFormat: 'json', pre: 'json', ext: 'json', path: null, data: null }; |     formatsHash[ 'json' ] = { title: 'json', outFormat: 'json', pre: 'json', ext: 'json', path: null, data: null }; | ||||||
|     formatsHash[ 'yml' ] = { title: 'yaml', outFormat: 'yml', pre: 'yml', ext: 'yml', path: null, data: null }; |     formatsHash[ 'yml' ] = { title: 'yaml', outFormat: 'yml', pre: 'yml', ext: 'yml', path: null, data: null }; | ||||||
|  |  | ||||||
|     // Now, get all the CSS files... |     // Now, get all the CSS files... | ||||||
|     this.cssFiles = fmts.filter(function( fmt ){ return fmt.ext === 'css'; }); |     (this.cssFiles = fmts.filter(function( fmt ){ return fmt.ext === 'css'; })) | ||||||
|  |     .forEach(function( cssf ) { | ||||||
|     // ...and assemble information on them |         // For each CSS file, get its corresponding HTML file | ||||||
|     this.cssFiles.forEach(function( cssf ) { |         var idx = _.findIndex(fmts, function( fmt ) { | ||||||
|       // For each CSS file, get its corresponding HTML file |           return fmt.pre === cssf.pre && fmt.ext === 'html' | ||||||
|       var idx = _.findIndex(fmts, function( fmt ) { |  | ||||||
|         return fmt.pre === cssf.pre && fmt.ext === 'html' |  | ||||||
|       }); |       }); | ||||||
|       fmts[ idx ].css = cssf.data; |       fmts[ idx ].css = cssf.data; | ||||||
|       fmts[ idx ].cssPath = cssf.path; |       fmts[ idx ].cssPath = cssf.path; | ||||||
| @@ -109,7 +111,7 @@ Abstract theme representation. | |||||||
|       return fmt.ext !== 'css'; |       return fmt.ext !== 'css'; | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     // Create a hash out of the formats for this theme |     // Cache the formats hash | ||||||
|     this.formats = formatsHash; |     this.formats = formatsHash; | ||||||
|  |  | ||||||
|     // Set the official theme name |     // Set the official theme name | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user