"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/theme-converter.js" (8 Mar 2017, 2420 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var TextMateTheme, ThemeConverter, fs, path, request, url;
    3 
    4   path = require('path');
    5 
    6   url = require('url');
    7 
    8   fs = require('./fs');
    9 
   10   request = require('./request');
   11 
   12   TextMateTheme = require('./text-mate-theme');
   13 
   14   module.exports = ThemeConverter = (function() {
   15     function ThemeConverter(sourcePath1, destinationPath) {
   16       this.sourcePath = sourcePath1;
   17       this.destinationPath = path.resolve(destinationPath);
   18     }
   19 
   20     ThemeConverter.prototype.readTheme = function(callback) {
   21       var protocol, requestOptions, sourcePath;
   22       protocol = url.parse(this.sourcePath).protocol;
   23       if (protocol === 'http:' || protocol === 'https:') {
   24         requestOptions = {
   25           url: this.sourcePath
   26         };
   27         return request.get(requestOptions, (function(_this) {
   28           return function(error, response, body) {
   29             if (error != null) {
   30               if (error.code === 'ENOTFOUND') {
   31                 error = "Could not resolve URL: " + _this.sourcePath;
   32               }
   33               return callback(error);
   34             } else if (response.statusCode !== 200) {
   35               return callback("Request to " + _this.sourcePath + " failed (" + response.headers.status + ")");
   36             } else {
   37               return callback(null, body);
   38             }
   39           };
   40         })(this));
   41       } else {
   42         sourcePath = path.resolve(this.sourcePath);
   43         if (fs.isFileSync(sourcePath)) {
   44           return callback(null, fs.readFileSync(sourcePath, 'utf8'));
   45         } else {
   46           return callback("TextMate theme file not found: " + sourcePath);
   47         }
   48       }
   49     };
   50 
   51     ThemeConverter.prototype.convert = function(callback) {
   52       return this.readTheme((function(_this) {
   53         return function(error, themeContents) {
   54           var error1, theme;
   55           if (error != null) {
   56             return callback(error);
   57           }
   58           try {
   59             theme = new TextMateTheme(themeContents);
   60           } catch (error1) {
   61             error = error1;
   62             return callback(error);
   63           }
   64           fs.writeFileSync(path.join(_this.destinationPath, 'styles', 'base.less'), theme.getStylesheet());
   65           fs.writeFileSync(path.join(_this.destinationPath, 'styles', 'syntax-variables.less'), theme.getSyntaxVariables());
   66           return callback();
   67         };
   68       })(this));
   69     };
   70 
   71     return ThemeConverter;
   72 
   73   })();
   74 
   75 }).call(this);