mirror of
				https://github.com/JuanCanham/HackMyResume.git
				synced 2025-11-04 06:47:27 +00:00 
			
		
		
		
	Add baseline support for multifile themes. #rough
This commit is contained in:
		@@ -12,7 +12,7 @@ Abstract theme representation.
 | 
			
		||||
    , PATH = require('path')
 | 
			
		||||
    , EXTEND = require('../utils/extend')
 | 
			
		||||
    , moment = require('moment')
 | 
			
		||||
    , recursiveReadSync = require('recursive-readdir-sync');
 | 
			
		||||
    , RECURSIVE_READ_DIR = require('recursive-readdir-sync');
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
  The Theme class is a representation of a FluentCV theme asset.
 | 
			
		||||
@@ -40,47 +40,77 @@ Abstract theme representation.
 | 
			
		||||
    var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
 | 
			
		||||
    EXTEND( true, this, themeInfo );
 | 
			
		||||
 | 
			
		||||
    var formatsHash = { };
 | 
			
		||||
 | 
			
		||||
    // Iterate over all files in the theme folder, producing an array, fmts,
 | 
			
		||||
    // containing info for each file.
 | 
			
		||||
    var tplFolder = PATH.join( themeFolder, 'src' );
 | 
			
		||||
    var fmts = recursiveReadSync( tplFolder ).map( function( file ) {
 | 
			
		||||
      var absPath = PATH.join( tplFolder, file );
 | 
			
		||||
      var pathInfo = PATH.parse(absPath);
 | 
			
		||||
      var temp = [ pathInfo.name, {
 | 
			
		||||
        title: friendlyName(pathInfo.name),
 | 
			
		||||
        pre: pathInfo.name,
 | 
			
		||||
        ext: pathInfo.ext.slice(1),
 | 
			
		||||
        path: absPath,
 | 
			
		||||
        data: FS.readFileSync( absPath, 'utf8' ),
 | 
			
		||||
        css: null
 | 
			
		||||
      }];
 | 
			
		||||
      return temp;
 | 
			
		||||
    });
 | 
			
		||||
    var fmts = RECURSIVE_READ_DIR( tplFolder ).map(
 | 
			
		||||
      function( absPath ) {
 | 
			
		||||
 | 
			
		||||
        var pathInfo = PATH.parse(absPath);
 | 
			
		||||
 | 
			
		||||
        // If this file lives in a specific format folder within the theme,
 | 
			
		||||
        // such as "/latex" or "/html", then that format is the output format
 | 
			
		||||
        // for all files within the folder.
 | 
			
		||||
        var outFmt = '';
 | 
			
		||||
        var portion = pathInfo.dir.replace(tplFolder,'');
 | 
			
		||||
        if( portion && portion.trim() ) {
 | 
			
		||||
          var reg = /^(?:\/|\\)(html|latex|doc|pdf)(?:\/|\\)?/ig;
 | 
			
		||||
          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;
 | 
			
		||||
      }
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // Add freebie formats every theme gets
 | 
			
		||||
    fmts.push( [ 'json', { title: 'json', pre: 'json', ext: 'json', path: null, data: null } ] );
 | 
			
		||||
    fmts.push( [ 'yml', { title: 'yaml', pre: 'yml', ext: 'yml', 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 };
 | 
			
		||||
 | 
			
		||||
    // Now, get all the CSS files...
 | 
			
		||||
    this.cssFiles = fmts.filter(function( fmt ){ return fmt[1].ext === 'css'; });
 | 
			
		||||
    this.cssFiles = fmts.filter(function( fmt ){ return fmt.ext === 'css'; });
 | 
			
		||||
 | 
			
		||||
    // ...and assemble information on them
 | 
			
		||||
    this.cssFiles.forEach(function( cssf ) {
 | 
			
		||||
      // For each CSS file, get its corresponding HTML file
 | 
			
		||||
      var idx = _.findIndex(fmts, function( fmt ) {
 | 
			
		||||
        return fmt[1].pre === cssf[1].pre && fmt[1].ext === 'html'
 | 
			
		||||
        return fmt.pre === cssf.pre && fmt.ext === 'html'
 | 
			
		||||
      });
 | 
			
		||||
      fmts[ idx ][1].css = cssf[1].data;
 | 
			
		||||
      fmts[ idx ][1].cssPath = cssf[1].path;
 | 
			
		||||
      fmts[ idx ].css = cssf.data;
 | 
			
		||||
      fmts[ idx ].cssPath = cssf.path;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // Remove CSS files from the formats array
 | 
			
		||||
    fmts = fmts.filter( function( fmt) {
 | 
			
		||||
      return fmt[1].ext !== 'css';
 | 
			
		||||
      return fmt.ext !== 'css';
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // Create a hash out of the formats for this theme
 | 
			
		||||
    this.formats = _.object( fmts );
 | 
			
		||||
    this.formats = formatsHash;
 | 
			
		||||
 | 
			
		||||
    // Set the official theme name
 | 
			
		||||
    this.name = PATH.parse( themeFolder ).name;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user