Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Adds php beautifing
Browse files Browse the repository at this point in the history
  • Loading branch information
Andr3as committed Jul 10, 2014
1 parent a7bb4d2 commit a57708d
Show file tree
Hide file tree
Showing 7 changed files with 360 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,6 +1,6 @@
#Beautify

Beautify js, json, html or css files.
Beautify js, json, html, css of php files.

##Installation

Expand Down
2 changes: 1 addition & 1 deletion controller.php
Expand Up @@ -5,7 +5,7 @@
* See http://opensource.org/licenses/MIT for more information.
* This information must remain intact.
*/
//error_reporting(0);
error_reporting(0);

require_once('../../common.php');
checkSession();
Expand Down
3 changes: 2 additions & 1 deletion default.settings.json
Expand Up @@ -3,7 +3,8 @@
"js": false,
"json": false,
"html": false,
"css": false
"css": false,
"php": false
},
"beautify": {
"indent_size": 1,
Expand Down
1 change: 1 addition & 0 deletions dialog.php
Expand Up @@ -11,6 +11,7 @@
<input type="checkbox" id="beautify_json">Beautify JSON <br>
<input type="checkbox" id="beautify_html">Beautify HTML <br>
<input type="checkbox" id="beautify_css">Beautify CSS <br>
<input type="checkbox" id="beautify_php">Beautify PHP <br>
<button onclick="codiad.Beautify.save(); return false;">Close</button>
<script>
codiad.Beautify.get();
Expand Down
19 changes: 15 additions & 4 deletions init.js
Expand Up @@ -19,17 +19,21 @@
codiad.Beautify = {

path: curpath,
beautifyPhp: null,
settings: {
js: false, json: false, html: false, css: false, auto: false
},
files: ["html", "htm", "js", "json", "css"],
files: ["html", "htm", "js", "json", "css", "php"],

init: function() {
var _this = this;
//Load libs
$.getScript(this.path+"libs/beautify-css.js");
$.getScript(this.path+"libs/beautify-html.js");
$.getScript(this.path+"libs/beautify.js");
$.getScript(this.path+"libs/ext-beautify.js", function() {
_this.beautifyPhp = ace.require("ace/ext/beautify");
});
//Load settings
this.load();
//Set subscriptions
Expand All @@ -56,7 +60,7 @@
});
amplify.subscribe('context-menu.onShow', function(obj){
var ext = _this.getExtension(obj.path);
if (_this.files.indexOf(ext) != -1) {
if (_this.files.indexOf(ext) != -1 && ext !== "php") {
$('#context-menu').append('<hr class="file-only beautify">');
$('#context-menu').append('<a class="file-only beautify" onclick="codiad.Beautify.contextMenu($(\'#context-menu\').attr(\'data-path\'));"><span class="icon-brush"></span>Beautify</a>');
}
Expand Down Expand Up @@ -86,6 +90,7 @@
this.checkSettings("json");
this.checkSettings("html");
this.checkSettings("css");
this.checkSettings("php");
$.post(this.path+"controller.php?action=save", {settings: JSON.stringify(this.settings)}, function(data){
var json = JSON.parse(data);
if (json.status == "error") {
Expand Down Expand Up @@ -120,6 +125,7 @@
this.setSettings("json");
this.setSettings("html");
this.setSettings("css");
this.setSettings("php");
},

//////////////////////////////////////////////////////////
Expand Down Expand Up @@ -201,8 +207,11 @@
return css_beautify(content, settings);
} else if (ext == "js" || ext == "json") {
return js_beautify(content, settings);
} else if (ext == "php") {
this.beautifyPhp.beautify(codiad.editor.getActive().getSession());
return false;
} else {
return content;
return false;
}
},

Expand All @@ -226,7 +235,9 @@
text = session.getTextRange(range);
}
text = _this.beautifyContent(path, text, settings);
session.replace(range, text);
if (text !== false) {
session.replace(range, text);
}
};
if (selText !== "") {
if (editor.selection.inMultiSelectMode) {
Expand Down

0 comments on commit a57708d

Please sign in to comment.