diff --git a/README.md b/README.md index 2f80183..e7bf79b 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ > [Beautify](https://github.com/einars/js-beautify) HTML (including [Handlebars](http://handlebarsjs.com/)), -CSS (including [Sass](http://sass-lang.com/) and [LESS](http://lesscss.org/)) -and JavaScript in Atom. +CSS (including [Sass](http://sass-lang.com/) and [LESS](http://lesscss.org/)), +JavaScript, and much more in Atom. Atom Package: https://atom.io/packages/atom-beautify @@ -40,10 +40,29 @@ It will only beautify selected text, if a selection is found - if not, the whole You can also type `ctrl-alt-b` as a shortcut or click `Packages > Beautify` in the menu. +#### Custom Keyboard Shortcuts + +See [Keymaps In-Depth](https://atom.io/docs/latest/advanced/keymaps) for more details. + +For example: + +```coffeescript +'.editor': # Available from Editor only + 'ctrl-alt-b': 'beautify' +``` + ### Package Options +- `beautifyOnSave` You can also choose to beautify on every file save. +- `googleAnalytics` +There is Google Analytics to track what languages +are being used the most and other stats. +Everything is anonymized and no personal information, +such as source code, is sent to Google. +See https://github.com/Glavin001/atom-beautify/issues/47 +for more details. ## Configuration diff --git a/lib/atom-beautify.js b/lib/atom-beautify.js index 96b513e..59fadab 100644 --- a/lib/atom-beautify.js +++ b/lib/atom-beautify.js @@ -297,6 +297,7 @@ function handleSaveEvent() { } plugin.configDefaults = _.merge({ + googleAnalytics: true, beautifyOnSave: false }, defaultLanguageOptions); diff --git a/lib/language-options.js b/lib/language-options.js index 7532622..377ad7b 100644 --- a/lib/language-options.js +++ b/lib/language-options.js @@ -14,6 +14,8 @@ var beautifySQL = require('./langs/sql-beautify'); var beautifyPHP = require('./langs/php-beautify'); var beautifyPython = require('./langs/python-beautify'); var beautifyRuby = require('./langs/ruby-beautify'); +var NA = require('nodealytics'); +var pkg = require('../package.json'); module.exports = { @@ -68,6 +70,8 @@ module.exports = { // Process each language beautify: function (text, grammar, allOptions, beautifyCompleted) { var self = this; + // Beautify! + var unsupportedGrammar = false; switch (grammar) { case 'JSON': // Treat JSON as JavaScript, because it will support comments. @@ -104,14 +108,41 @@ module.exports = { beautifyPHP(text, self.getOptions('php', allOptions), beautifyCompleted); break; case 'Python': - beautifyPython(text, self.getOptions('python', allOptions), beautifyCompleted); + beautifyPython(text, self.getOptions('python', allOptions), + beautifyCompleted); break; case 'Ruby': beautifyRuby(text, self.getOptions('ruby', allOptions), beautifyCompleted); break; default: - return; + unsupportedGrammar = true; } + + // Google Analytics + if (atom.config.get('atom-beautify.googleAnalytics')) { + NA.initialize('UA-52729731-2', 'https://atom.io/packages/atom-beautify', + function () { + // category, action, label, value + NA.trackEvent('grammar', grammar, function (err, resp) { + // console.log(err, resp); + // if (!err && resp.statusCode === 200) { + // console.log('Event has been tracked with Google Analytics'); + // } + }); + NA.trackEvent('version', pkg.version, function (err, resp) { + // console.log(err, resp); + // if (!err && resp.statusCode === 200) { + // console.log('Event has been tracked with Google Analytics'); + // } + }); + if (unsupportedGrammar) { + NA.trackEvent('unsupportedGrammar', grammar, function (err, resp) { + // + }); + } + }); + } + }, getOptions: function (selection, allOptions) { diff --git a/package.json b/package.json index 762e941..01e0d4e 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,8 @@ "lodash": "2.4.1", "strip-json-comments": "^0.1.3", "js-yaml": "^3.0.2", - "temp": "^0.8.0" + "temp": "^0.8.0", + "nodealytics": "0.0.6" }, "activationEvents": [ "beautify"