Permalink
Browse files

v2.2.0 - External formatters and language mapping

  • Loading branch information...
1 parent e391321 commit 6e8ff615d91c97c1e973f5a0cb8fd2ed8bea510c @Hirse Hirse committed Jun 12, 2016
View
@@ -117,7 +117,7 @@
no-undef: 2 # disallow the use of undeclared variables unless mentioned in /*global */ comments
no-undef-init: 2 # disallow initializing variables to undefined
no-undefined: 1 # disallow the use of undefined as an identifier
- no-unused-vars: 1 # disallow unused variables
+ no-unused-vars: [2, {vars: all, args: none}] # disallow unused variables
no-use-before-define: 1 # disallow the use of variables before they are defined
# Stylistic Issues
array-bracket-spacing: 1 # enforce consistent spacing inside array brackets
View
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
This project tries to adhere to [Semantic Versioning](http://semver.org/).
+## 2.2.0 - 2016-06-12
+### Added
+- Configure any program to beautify a language
+
+### Removed
+- Explicit SASS settings as they can be handled by generic mechanism
+
+
## 2.1.0 - 2016-06-11
### Added
- Chinese (simplified) translation, thanks to [__@quarkchaos__](https://github.com/quarkchaos)
View
@@ -9,7 +9,7 @@ The last version on the Brackets Extension Registry is [1.2.0](https://github.co
## Installation
### Latest Release
To install the latest _release_ of this extension use the `Install from URL...` function of the Brackets [Extension Manager][Brackets Extension Manager].
-The link can be found on our [Release-page](https://github.com/brackets-beautify/brackets-beautify/releases/latest).
+The link can be found on our [Release-page][Beautify latest release].
### Latest Commit
To install the latest _commit_ of this extension use the built-in Brackets [Extension Manager][Brackets Extension Manager] which has a function to `Install from URL...` using this link:
@@ -19,14 +19,14 @@ https://github.com/brackets-beautify/brackets-beautify/archive/master.zip
## Usage
Brackets Beautify can be run manually on the whole file or on a selection.
-Use the menu entry `Edit > Beautify`, the context-menu entry `Beautify`, or one of the keyboard shortcuts `Ctrl-Alt-B` (Windows/Linux), `Ctrl-Shift-L` (Windows), `Cmd-Shift-L` (Mac), or [define your own][Beautify User Key Map].
+Use the Toolbar Button with the wand icon, the menu entry `Edit > Beautify`, the context-menu entry `Beautify`, or one of the keyboard shortcuts `Ctrl-Alt-B` (Windows/Linux), `Ctrl-Shift-L` (Windows), `Cmd-Shift-L` (Mac), or [define your own][Beautify User Key Map].
Alternatively it can be enabled to run automatically on save.
Use the menu entry `Edit > Beautify on Save` or the more [advanced settings][Beautify Beautify on Save] to activate.
-### Configuration
-#### Beautifier Options
+## Configuration
+### Beautifier Options
Brackets Beautify supports the same [options][js-beautify options] as [js-beautify][js-beautify] with the exception of indentation-based options (`indent_size`, `indent_char`, and `indent_with_tabs`) which are taken from the current settings in Brackets.
The options can be specified in a `.jsbeautifyrc` file on project level and will be merged with the default.
The default is defined in `default.jsbeautifyrc` and looks like this:
@@ -69,7 +69,7 @@ The default is defined in `default.jsbeautifyrc` and looks like this:
}
```
-#### File Options for Beautify on Save
+### File Options for Beautify on Save
Brackets Beautify leverages [Brackets preferences][Brackets preferences], which means that you can specify per project settings by defining a `.brackets.json` in the root directory of your project. With Brackets preferences you can even define per file settings, which is really handy when dealing with third party libraries or minified resources.
Brackets Beautify also support per language settings, which enables you to enable/disabled `Beautify on Save` for your documents using the Brackets language layer.
@@ -94,7 +94,7 @@ The sample `.brackets.json` below generally enables `Beautify on Save` and disab
}
```
-#### User Key Map for Beautify
+### User Key Map for Beautify
Open the `keymap.json` with the menu entry `Debug > Open User Key Map` and add an _overrides_ entry.
For example:
```js
@@ -106,18 +106,44 @@ For example:
}
```
-## External formatters
-### SASS
-You need to supply an absolute path to the `sass-convert` executable for SASS formatting to work.
+### Configure languages
+Brackets Beautify comes with beautifiers for JavaScript, HTML and CSS. You can add languages by adding their ids to the `bb.beautify.languages` setting:
+```json
+{
+ "bb.beautify.languages": {
+ "css": "css",
+ "ejs": "html",
+ "handlebars": "html",
+ "html": "html",
+ "javascript": "js",
+ "json": "js",
+ "less": "css",
+ "php": "html",
+ "scss": "css",
+ "svg": "html",
+ "vue": "html",
+ "xml": "html"
+ }
+}
+```
-- Install [SASS][SASS Install]
-- Get the absolute path to the executable
- Some example paths:
- - On MacOSX
- Using *rbenv*: `/Users/<USER>/.rbenv/shims/sass-convert`
- Using system Ruby (`sudo gem install sass`): `/usr/bin/sass-convert`
- - On Windows: `C:\\Ruby193\\bin\\sass-convert.bat`
-- Open the Brackets settings file and set the entry `bb.beautify.external.sass` to the path value.
+### External formatters
+Additionally, external formatters can be added to Brackets Beautify by modifying the `bb.beautify.beautifiers` setting.
+```json
+{
+ "bb.beautify.beautifiers": {
+ "formatterName": {
+ "command": "/path/to/file --with args"
+ }
+ },
+ "bb.beautify.languages": {
+
+ "languageId": "formatterName"
+ }
+}
+```
+The key is a name that can be use to configure the language where this formatter should be used.
+The `command` is executed on a shell and gets the filename as last command line argument.
## Issues
@@ -133,6 +159,7 @@ Brackets Beautify is licensed under the [MIT license][MIT]. [js-beautify][js-bea
[Brackets preferences]: https://github.com/adobe/brackets/wiki/How-to-Use-Brackets#preferences
[Beautify User Key Map]: https://github.com/brackets-beautify/brackets-beautify#user-key-map-for-beautify
[Beautify Beautify on Save]: https://github.com/brackets-beautify/brackets-beautify#file-options-for-beautify-on-save
+[Beautify latest release]: https://github.com/brackets-beautify/brackets-beautify/releases/latest
[js-beautify]: https://github.com/beautify-web/js-beautify
[js-beautify version]: https://github.com/beautify-web/js-beautify/blob/master/CHANGELOG.md#v163
[js-beautify issues]: https://github.com/beautify-web/js-beautify/issues
View
@@ -0,0 +1,24 @@
+define(function (require, exports, module) {
+ 'use strict';
+
+ /* beautify preserve:start *//* eslint-disable no-multi-spaces */
+ var DocumentManager = brackets.getModule('document/DocumentManager');
+ var ExtensionUtils = brackets.getModule('utils/ExtensionUtils');
+ var NodeDomain = brackets.getModule('utils/NodeDomain');
+ /* eslint-enable no-multi-spaces *//* beautify preserve:end */
+
+ var domain = new NodeDomain('externalBeautify', ExtensionUtils.getModulePath(module, 'domain'));
+
+ function beautify(options, unformattedText, callback) {
+ var fullPath = DocumentManager.getCurrentDocument().file.fullPath;
+ domain.exec('beautify', options, fullPath).done(function (formattedText) {
+ callback(null, formattedText);
+ }).fail(function (err) {
+ callback(err, unformattedText);
+ });
+ }
+
+ module.exports = {
+ beautify: beautify
+ };
+});
View
@@ -0,0 +1,34 @@
+/* eslint-env node */
+/* eslint-disable strict */
+
+(function () {
+ 'use strict';
+
+ var exec = require('child_process').exec;
+
+ function beautify(options, filePath, callback) {
+ exec(options.command + ' ' + filePath, function (error, stdout, stderr) {
+ return callback(error, stdout);
+ });
+ }
+
+ function init(DomainManager) {
+ if (!DomainManager.hasDomain('externalBeautify')) {
+ DomainManager.registerDomain('externalBeautify', {
+ major: 0,
+ minor: 1
+ });
+ }
+ DomainManager.registerCommand('externalBeautify', 'beautify', beautify, true, 'beautify externally', [{
+ name: 'options',
+ type: 'object',
+ description: 'Options object with path'
+ }, {
+ name: 'filePath',
+ type: 'string',
+ description: 'Path to file.'
+ }], []);
+ }
+
+ exports.init = init;
+}());
@@ -1,44 +0,0 @@
-define(function (require, exports, module) {
- 'use strict';
-
- var PREFIX = 'bb.beautify';
- var PATH_PREF = 'external.sass';
-
- /* beautify preserve:start *//* eslint-disable no-multi-spaces */
- var DocumentManager = brackets.getModule('document/DocumentManager');
- var PreferencesManager = brackets.getModule('preferences/PreferencesManager');
- var ExtensionUtils = brackets.getModule('utils/ExtensionUtils');
- var NodeDomain = brackets.getModule('utils/NodeDomain');
- /* eslint-enable no-multi-spaces *//* beautify preserve:end */
-
- var Strings = require('strings');
-
- var simpleDomain = new NodeDomain('sassformat', ExtensionUtils.getModulePath(module, 'domain'));
- var prefs = PreferencesManager.getExtensionPrefs(PREFIX);
- prefs.definePreference(PATH_PREF, 'string', '', {
- name: Strings.SASS_PREF_NAME,
- description: Strings.SASS_PREF_DESC
- });
-
- function beautify(unformattedText, options, callback) {
- var indentSize = options.indent_with_tabs ? 't' : options.indent_size;
-
- var path = prefs.get(PATH_PREF);
-
- if (!path) {
- console.error(Strings.SASS_ERROR);
- callback(Strings.SASS_ERROR, unformattedText);
- }
-
- var fullPath = DocumentManager.getCurrentDocument().file.fullPath;
- simpleDomain.exec('parse', path, fullPath, indentSize).done(function (formattedText) {
- callback(null, formattedText);
- }).fail(function (err) {
- callback(err, unformattedText);
- });
- }
-
- module.exports = {
- beautify: beautify
- };
-});
@@ -1,46 +0,0 @@
-/* eslint-env node */
-/* eslint-disable strict */
-
-(function () {
- 'use strict';
-
- // "beautify.sassConvertPath": "/Users/drewh/.rbenv/shims/sass-convert"
-
- var exec = require('child_process').exec;
-
- function cmdFormat(sassPath, filePath, indentSize, callback) {
- exec(sassPath + ' --indent ' + indentSize + ' -F scss -T scss ' + filePath, function (err, out, stderr) {
- return callback(err, out, stderr);
- });
- }
-
- function init(DomainManager) {
- if (!DomainManager.hasDomain('sassformat')) {
- DomainManager.registerDomain('sassformat', {
- major: 0,
- minor: 1
- });
- }
- DomainManager.registerCommand(
- 'sassformat',
- 'parse',
- cmdFormat,
- true,
- 'SASS format', [{
- name: 'sassPath',
- type: 'string',
- description: 'Path to sass-convert program'
- }, {
- name: 'filePath',
- type: 'string',
- description: 'Path to file.'
- }, {
- name: 'indentSize',
- type: 'string',
- description: 'Indention size or tab character'
- }], {}
- );
- }
-
- exports.init = init;
-}());
Oops, something went wrong.

0 comments on commit 6e8ff61

Please sign in to comment.