lib/handlers/bin.js
function(bin) {
    var binSettings = {};

    // self defence against muppertary
    if (typeof bin.settings === 'string') {
      try {
        binSettings = JSON.parse(bin.settings);
      } catch (e) {}
    } else {
      binSettings = bin.settings;
    }

    if (
      binSettings &&
      binSettings.processors &&
      Object.keys(binSettings.processors).length
    ) {
      return Promise.all(
        Object.keys(binSettings.processors).map(function(panel) {
          var processorName = binSettings.processors[panel],
            code = bin[panel];
          if (processors.support(processorName)) {
            bin['original_' + panel] = code;
            return processors
              .run(processorName, {
                source: code,
                url: bin.url,
                revision: bin.revision,
              })
              .then(function(output) {
                var result = '';
                if (output.result) {
                  result = output.result;
                } else {
                  result = output.errors
                    .map(function(error) {
                      return (
                        'Line: ' +
                        error.line +
                        '\nCharacter: ' +
                        error.ch +
                        '\nMessage: ' +
                        error.msg
                      );
                    })
                    .join('\n\n');
                }
                bin[panel] = result;
                return bin;
              })
              .catch(function() {
                return bin;
              });
          } else {
            return Promise.resolve(bin);
          }
        })
      );
    }

    // otherwise default to being resolved
    return Promise.resolve([bin]);
  }
function(bin) {
    var binSettings = {};

    // self defence against muppertary
    if (typeof bin.settings === 'string') {
      try {
        binSettings = JSON.parse(bin.settings);
      } catch (e) {}
    } else {
      binSettings = bin.settings;
    }

    if (
      binSettings &&
      binSettings.processors &&
      Object.keys(binSettings.processors).length
    ) {
      return Promise.all(
        Object.keys(binSettings.processors).map(function(panel) {
          var processorName = binSettings.processors[panel],
            code = bin[panel];
          if (processors.support(processorName)) {
            bin['original_' + panel] = code;
            return processors
              .run(processorName, {
                source: code,
                url: bin.url,
                revision: bin.revision,
              })
              .then(function(output) {
                var result = '';
                if (output.result) {
                  result = output.result;
                } else {
                  result = output.errors
                    .map(function(error) {
                      return (
                        'Line: ' +
                        error.line +
                        '\nCharacter: ' +
                        error.ch +
                        '\nMessage: ' +
                        error.msg
                      );
                    })
                    .join('\n\n');
                }
                bin[panel] = result;
                return bin;
              })
              .catch(function() {
                return bin;
              });
          } else {
            return Promise.resolve(bin);
          }
        })
      );
    }

    // otherwise default to being resolved
    return Promise.resolve([bin]);
  }
function ( bin ) { var binSettings = { } ; // self defence against muppertary if ( typeof bin . settings === 'string' ) { try { binSettings = JSON . parse ( bin . settings ) ; } catch ( e ) { } } else { binSettings = bin . settings ; } if ( binSettings && binSettings . processors && Object . keys ( binSettings . processors ) . length ) { return Promise . all ( Object . keys ( binSettings . processors ) . map ( function ( panel ) { var processorName = binSettings . processors [ panel ] , code = bin [ panel ] ; if ( processors . support ( processorName ) ) { bin [ 'original_' + panel ] = code ; return processors . run ( processorName , { source : code , url : bin . url , revision : bin . revision , } ) . then ( function ( output ) { var result = '' ; if ( output . result ) { result = output . result ; } else { result = output . errors . map ( function ( error ) { return ( 'Line: ' + error . line + '\nCharacter: ' + error . ch + '\nMessage: ' + error . msg ) ; } ) . join ( '\n\n' ) ; } bin [ panel ] = result ; return bin ; } ) . catch ( function ( ) { return bin ; } ) ; } else { return Promise . resolve ( bin ) ; } } ) ) ; } // otherwise default to being resolved return Promise . resolve ( [ bin ] ) ; }
applies the processors to the bin and generates the html, js, etc based on the appropriate processor. Used in the previews and the API requests.
applies the processors to the bin and generates the html js etc based on the appropriate processor . Used in the previews and the API requests .