define([\r
"jquery",\r
"base64",\r
- "plugins/github/ui",\r
+ "plugins/github/github_api",\r
"plugins/github/loginbox",\r
"plugins/github/modalbox",\r
-], function($, Base64, UI, LoginBox, ModalBox) {\r
- // Load GitHub UI\r
- var upstream = $("body").attr("data-github-upstream");\r
- var basesha1 = $("body").attr("data-github-base-sha1");\r
- if(upstream && basesha1) {\r
- console.info("Github plugin: init GitHub module (upstream: "+ upstream +", base: " + basesha1 + ")");\r
-\r
- $("nav.main ul").append(\r
- $("<li/>").attr("id", "nitdoc-github-li")\r
- );\r
- $("#nitdoc-github-li")\r
- .loginbox()\r
- .bind( "loginbox_logoff", function() {\r
- UI.disactivate();\r
+ "plugins/github/commentbox",\r
+ "Markdown.Converter",\r
+], function($, Base64, GithubAPI, LoginBox, ModalBox, CommentBox) {\r
+ var GithubUser = function(login, password, repo, branch) {\r
+ this.login = login;\r
+ this.password = password;\r
+ this.repo = repo;\r
+ this.auth = "Basic " + Base64.encode(login + ':' + password);\r
+ this.branch = branch;\r
+ }\r
+\r
+ var GithubUI = {\r
+ init: function(upstream, basesha1) {\r
+ console.info("Github plugin: init GitHub module (upstream: "+ upstream +", base: " + basesha1 + ")");\r
+ this.origin = this._parseUpstream(upstream);\r
+ // Add github menu\r
+ $("nav.main ul").append(\r
+ $("<li/>")\r
+ .attr("id", "nitdoc-github-li")\r
+ .loginbox()\r
+ .loginbox("displayLogin")\r
+ .bind("loginbox_logoff", function() {\r
+ GithubUI.disactivate();\r
+ })\r
+ .bind("loginbox_login", function(event, infos) {\r
+ GithubUI._tryLoginFromCredentials(infos);\r
+ })\r
+ );\r
+ // check local session\r
+ this._tryLoginFromLocalSession();\r
+ },\r
+\r
+ activate: function(user, origin) {\r
+ this.openedComments = 0;\r
+ this._saveSession(user);\r
+ $("#nitdoc-github-li").loginbox("displayLogout", origin, user);\r
+ this._attachCommentBoxes();\r
+ this._reloadComments();\r
+\r
+ // Prevent page unload if there is comments in editing mode\r
+ $(window).on('beforeunload', function() {\r
+ if(GithubUI.openedComments > 0){\r
+ return "There is uncommited modified comments. Are you sure you want to leave this page?";\r
+ }\r
+ });\r
+ },\r
+\r
+ disactivate: function() {\r
+ if(this.openedComments > 0){\r
+ if(!confirm('There is uncommited modified comments. Are you sure you want to leave this page?')) {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ localStorage.clear();\r
$("#nitdoc-github-li").loginbox("toggle");\r
- })\r
- .bind( "loginbox_login", function(event, infos) {\r
+ $("#nitdoc-github-li").loginbox("displayLogin");\r
+ $(window).unbind('beforeunload');\r
+ //window.location.reload();\r
+ },\r
+\r
+ /* login */\r
+\r
+ _checkLoginInfos: function(infos) {\r
if(!infos.login || !infos.password || !infos.repo || !infos.branch) {\r
- ModalBox.open("Sign in error", "Please enter your GitHub username, password, repository and branch.", true);\r
+ ModalBox.open(\r
+ "Sign in error",\r
+ "Please enter your GitHub username, password, repository and branch.",\r
+ true\r
+ );\r
+ return false;\r
} else {\r
- var user = UI.tryLogin(infos.login, infos.password, infos.repo, infos.branch);\r
- if(user == "error:login") {\r
- ModalBox.open("Sign in error", "The username, password, repo or branch you entered is incorrect.", true);\r
- } else if(user == "error:sha") {\r
- ModalBox.open("Base commit not found", "The provided GitHub repository must contains the base commit '" + UI.origin.sha + "'", true);\r
- } else if(user == "error:profile") {\r
- ModalBox.open("Incomplete GitHub profile", "Please set your public name and email in your <a href='https://github.com/settings/profile'>GitHub profile</a>.<br/><br/>Your public profile informations are used to sign-off your commits.", true);\r
+ return true;\r
+ }\r
+ },\r
+\r
+ _tryLoginFromCredentials: function(infos) {\r
+ if(this._checkLoginInfos(infos)) {\r
+ var isok = this._tryLogin(infos.login, infos.password, infos.repo, infos.branch);\r
+ if(isok === true) {\r
+ this.activate(this.user, this.origin);\r
} else {\r
- UI.activate(user);\r
- $("#nitdoc-github-li").loginbox("displayLogout", UI.origin, UI.user);\r
+ if(isok == "error:login") {\r
+ ModalBox.open(\r
+ "Sign in error",\r
+ "The username, password, repo or branch you entered is incorrect.",\r
+ true\r
+ );\r
+ } else if(isok == "error:sha") {\r
+ ModalBox.open(\r
+ "Base commit not found",\r
+ "The provided Github repository must contain the base commit '" + UI.origin.sha + "'",\r
+ true\r
+ );\r
+ } else if(isok == "error:profile") {\r
+ ModalBox.open(\r
+ "Incomplete Github profile",\r
+ "Please set your public name and email in your " +\r
+ "<a href='https://github.com/settings/profile'>GitHub profile</a>." +\r
+ "<br/><br/>Your public profile informations are used to sign-off your commits.",\r
+ true\r
+ );\r
+ }\r
}\r
}\r
- });\r
+ },\r
\r
- // parse origin\r
- var parts = upstream.split(":");\r
- UI.origin = {\r
- user: parts[0],\r
- repo: parts[1],\r
- branch: parts[2],\r
- sha: basesha1\r
- };\r
+ _tryLoginFromLocalSession: function() {\r
+ if(localStorage.user) {\r
+ var session = JSON.parse(localStorage.user);\r
+ var isok = this._tryLogin(\r
+ session.login,\r
+ Base64.decode(session.password),\r
+ session.repo,\r
+ session.branch\r
+ );\r
+ if(isok === true) {\r
+ this.activate(this.user, this.origin);\r
+ } else {\r
+ console.debug("Github plugin: Session found but authentification failed");\r
+ localStorage.clear();\r
+ }\r
+ } else {\r
+ console.debug("Github plugin: No session found");\r
+ }\r
+ },\r
\r
- // check local session\r
- if(localStorage.user) {\r
+ _tryLogin: function(login, password, repo, branch) {\r
+ var tmpUser = new GithubUser(login, password, repo, branch);\r
+ if(!GithubAPI.login(tmpUser)) {\r
+ return "error:login";\r
+ }\r
+ if(!tmpUser.infos.name || !tmpUser.infos.email) {\r
+ return "error:profile";\r
+ }\r
+ var commit = GithubAPI.getCommit(tmpUser, this.origin.sha);\r
+ if(!commit || !commit.sha) {\r
+ return "error:sha";\r
+ }\r
+ this.user = tmpUser;\r
+ return true;\r
+ },\r
\r
- var session = JSON.parse(localStorage.user);\r
- UI.user = UI.tryLogin(session.login, Base64.decode(session.password), session.repo, session.branch);\r
- if(!UI.user.login) {\r
- console.debug("Github plugin: Session found but authentification failed");\r
- localStorage.clear();\r
+ _saveSession: function(user) {\r
+ localStorage.user = JSON.stringify({\r
+ login: user.login,\r
+ password: Base64.encode(user.password),\r
+ repo: user.repo,\r
+ branch: user.branch,\r
+ });\r
+ // check local storage synchro with branch\r
+ if(localStorage.base != this.origin.sha) {\r
+ console.log("Base changed: cleaned cache");\r
+ localStorage.requests = "[]";\r
+ localStorage.base = this.origin.sha;\r
}\r
+ },\r
+\r
+ /* html decoration */\r
\r
- // activate ui\r
- if(UI.user && UI.user.login) {\r
- $("#nitdoc-github-li").loginbox("displayLogout", UI.origin, UI.user);\r
- UI.activate(UI.user);\r
+ // Attach edit button on each comment\r
+ _attachCommentBoxes: function() {\r
+ $("textarea.baseComment").each(function() {\r
+ $(this).commentbox();\r
+\r
+ var isNew = false;\r
+ if(!$(this).val()) {\r
+ isNew = true;\r
+ $(this).nextAll(".info:first").find(".noComment").hide()\r
+ $(this).nextAll(".info:first").before(\r
+ $("<div/>")\r
+ .hide()\r
+ .addClass("comment")\r
+ .append(\r
+ $("<div/>").addClass("nitdoc")\r
+ )\r
+ )\r
+ }\r
+\r
+ $(this).nextAll(".info:first").prepend(\r
+ $("<a/>")\r
+ .addClass("nitdoc-github-editComment")\r
+ .css("cursor", "pointer")\r
+ .text((isNew ? "add" : "edit") + " comment")\r
+ .click($.proxy(GithubUI._openCommentBox, GithubUI, null, $(this)))\r
+ .after(" for ")\r
+ )\r
+\r
+ $(this).bind("commentbox_commit", function(event, data) {\r
+ GithubUI._saveChanges(data);\r
+ $(this).commentbox("close");\r
+ GithubUI._reloadComments();\r
+ })\r
+ .bind("commentbox_preview", function(event, data) {\r
+ var converter = new Markdown.Converter()\r
+ var html = converter.makeHtml(data.value);\r
+ ModalBox.open("Preview", html, false);\r
+ })\r
+ .bind("commentbox_open", function(event, data) {\r
+ GithubUI.openedComments++;\r
+ $(this).nextAll(".comment").hide();\r
+ })\r
+ .bind("commentbox_close", function(event, data) {\r
+ GithubUI.openedComments--;\r
+ $(this).nextAll(".comment").show();\r
+ });\r
+ });\r
+ },\r
+\r
+ // reload comments from saved pull request\r
+ _reloadComments: function() {\r
+ if(!localStorage.requests){ return; }\r
+ $("p.pullRequest").remove();\r
+ var converter = new Markdown.Converter();\r
+ var requests = JSON.parse(localStorage.requests);\r
+ // Look for modified comments in page\r
+ for(i in requests) {\r
+ if(!requests[i]) { continue; }\r
+ var request = requests[i];\r
+ $("textarea[data-comment-location=\"" + request.location + "\"]").each(function () {\r
+ if(request.isClosed) {\r
+ var oldComment = Base64.decode(request.oldComment);\r
+ var htmlComment = converter.makeHtml(oldComment);\r
+ $(this).val(oldComment);\r
+ if(!$(this).val()) {\r
+ $(this).nextAll("div.comment:first").hide();\r
+ } else {\r
+ $(this).nextAll("div.comment:first").show();\r
+ }\r
+ $(this).nextAll("div.comment").find("div.nitdoc").empty().html(htmlComment);\r
+ $(this).nextAll("p.info").find("a.nitdoc-github-editComment").show();\r
+ } else {\r
+ var newComment = Base64.decode(request.comment);\r
+ var htmlComment = converter.makeHtml(newComment);\r
+ $(this).val(newComment);\r
+ if(!$(this).val()) {\r
+ $(this).nextAll("div.comment:first").hide();\r
+ } else {\r
+ $(this).nextAll("div.comment:first").show();\r
+ }\r
+ $(this).nextAll("div.comment").find("div.nitdoc").empty().html(htmlComment);\r
+ GithubUI._addPullRequestLink($(this), request);\r
+ $(this).nextAll("p.info").find("a.nitdoc-github-editComment").hide();\r
+ }\r
+ });\r
}\r
- } else {\r
- console.debug("Github plugin: No session found");\r
- $("#nitdoc-github-li").loginbox("displayLogin");\r
+ },\r
+\r
+ _addPullRequestLink: function(baseArea, request) {\r
+ baseArea.nextAll("p.info").before(\r
+ $("<p/>")\r
+ .addClass("pullRequest inheritance")\r
+ .text("comment modified in ")\r
+ .append(\r
+ $("<a/>")\r
+ .attr({\r
+ href: request.request.html_url,\r
+ title: "Review on GitHub"\r
+ })\r
+ .text("pull request #" + request.request.number)\r
+ )\r
+ .append(" ")\r
+ .append(\r
+ $("<a/>")\r
+ .data("pullrequest-number", request.request.number)\r
+ .addClass("nitdoc-github-update")\r
+ .text("update")\r
+ .click($.proxy(GithubUI._doUpdateRequest, GithubUI, null, baseArea, request))\r
+ )\r
+ .append(" ")\r
+ .append(\r
+ $("<a/>")\r
+ .data("pullrequest-number", request.request.number)\r
+ .addClass("nitdoc-github-cancel")\r
+ .text("cancel")\r
+ .click($.proxy(GithubUI._doCancelRequest, GithubUI, null, baseArea, request))\r
+ )\r
+ );\r
+ },\r
+\r
+ /* github calls */\r
+\r
+ _saveChanges: function(edit) {\r
+ // if pull request update close existing pull request for the comment\r
+ if(edit.requestID) {\r
+ this._closePullRequest(edit.requestID);\r
+ }\r
+ edit.oldContent = this._getFileContent(edit.location.path);\r
+ edit.newContent = this._mergeComment(edit.oldContent, edit.newComment, edit.location);\r
+ edit.request = this._pushChanges(edit)\r
+ if(!edit.request) {\r
+ ModalBox.open("Unable to commit changes!", response, true);\r
+ return;\r
+ }\r
+ this._saveRequest(edit);\r
+ },\r
+\r
+ // save pull request in local storage\r
+ _saveRequest: function(edit) {\r
+ var requests = {};\r
+ if(localStorage.requests) {requests = JSON.parse(localStorage.requests)}\r
+ requests[edit.request.number] = {\r
+ request: edit.request,\r
+ location: edit.location.origin,\r
+ comment: Base64.encode(edit.newComment),\r
+ oldComment: Base64.encode(edit.oldComment)\r
+ };\r
+ localStorage.requests = JSON.stringify(requests);\r
+ },\r
+\r
+ /*\r
+ Creating a new pull request with the new comment take 5 steps:\r
+ 1. get the base tree from latest commit\r
+\r
+ 2. create a new blob with updated file content\r
+ 3. post a new tree from base tree and blob\r
+ 4. post the new commit with new tree\r
+ 5. create the pull request\r
+ */\r
+ _pushChanges: function(edit) {\r
+ var baseTree = GithubAPI.getTree(this.user, this.origin.sha);\r
+ if(!baseTree.sha) {\r
+ ModalBox.open("Unable to locate base tree!", baseTree.status + ": " + baseTree.statusText, true);\r
+ return false;\r
+ }\r
+ console.log("Base tree: " + baseTree.url);\r
+ var newBlob = GithubAPI.createBlob(this.user, edit.newContent);\r
+ if(!newBlob.sha) {\r
+ ModalBox.open("Unable to create new blob!", newBlob.status + ": " + newBlob.statusText, true);\r
+ return false;\r
+ }\r
+ console.log("New blob: " + newBlob.url);\r
+ var newTree = GithubAPI.createTree(this.user, baseTree, edit.location.path, newBlob);\r
+ if(!newTree.sha) {\r
+ ModalBox.open("Unable to create new tree!", newTree.status + ": " + newTree.statusText, true);\r
+ return false;\r
+ }\r
+ console.log("New tree: " + newTree.url);\r
+ var newCommit = GithubAPI.createCommit(this.user, edit.message, baseTree.sha, newTree);\r
+ if(!newCommit.sha) {\r
+ ModalBox.open("Unable to create new commit!", newCommit.status + ": " + newCommit.statusText, true);\r
+ return false;\r
+ }\r
+ console.log("New commit: " + newCommit.url);\r
+ var pullRequest = GithubAPI.createPullRequest(this.user, edit.title, "Pull request from Nitdoc", this.origin, newCommit.sha);\r
+ if(!pullRequest.number) {\r
+ ModalBox.open("Unable to create pull request!", pullRequest.status + ": " + pullRequest.statusText, true);\r
+ return false;\r
+ }\r
+ console.log("New pull request: " + pullRequest.url);\r
+ return pullRequest;\r
+ },\r
+\r
+ // close previously opened pull request\r
+ _closePullRequest: function(number) {\r
+ var requests = JSON.parse(localStorage.requests);\r
+ if(!requests[number]) {\r
+ ModalBox.open("Unable to close pull request!", "Pull request " + number + "not found", true);\r
+ return false;\r
+ }\r
+ // close pull request\r
+ var res = GithubAPI.updatePullRequest(this.user, "Closed from Nitdoc", "", "closed", requests[number].request);\r
+ if(!res.id) {\r
+ ModalBox.open("Unable to close pull request!", res.status + ": " + res.statusText, true);\r
+ return false;\r
+ }\r
+ // update in localstorage\r
+ requests[number].isClosed = true;\r
+ localStorage.requests = JSON.stringify(requests);\r
+ },\r
+\r
+ /* internals */\r
+\r
+ _parseUpstream: function(upstream) {\r
+ var parts = upstream.split(":");\r
+ return {\r
+ user: parts[0],\r
+ repo: parts[1],\r
+ branch: parts[2],\r
+ sha: basesha1\r
+ };\r
+ },\r
+\r
+ _getFileContent: function(githubUrl) {\r
+ var origFile = GithubAPI.getFile(this.user, githubUrl);\r
+ if(!origFile.content) {\r
+ ModalBox.open("Unable to locate source file!", origFile.status + ": " + origFile.statusText, true);\r
+ return;\r
+ }\r
+ var base64Content = origFile.content.substring(0, origFile.content.length - 1)\r
+ return Base64.decode(base64Content);\r
+ },\r
+\r
+ _mergeComment: function(fileContent, comment, location) {\r
+ // replace comment in file content\r
+ var res = new String();\r
+ var lines = fileContent.split("\n");\r
+ // copy lines fron 0 to lstart\r
+ for(var i = 0; i < location.lstart - 1; i++) {\r
+ res += lines[i] + "\n";\r
+ }\r
+ // set comment\r
+ if(comment && comment != "") {\r
+ var commentLines = comment.split("\n");\r
+ for(var i = 0; i < commentLines.length; i++) {\r
+ var line = commentLines[i];\r
+ var tab = location.tabpos > 1 ? "\t" : "";\r
+ res += tab + (line.length > 0 ? "# " : "#") + line + "\n";\r
+ }\r
+ }\r
+ // copy lines fron lend to end\r
+ for(var i = location.lend - 1; i < lines.length; i++) {\r
+ res += lines[i];\r
+ if(i < lines.length - 1) { res += "\n"; }\r
+ }\r
+ return res;\r
+ },\r
+\r
+ /* events */\r
+\r
+ _openCommentBox: function(event, baseArea) {\r
+ baseArea.commentbox("open", this.user);\r
+ },\r
+\r
+ _doCancelRequest: function(event, baseArea, request) {\r
+ this._closePullRequest(request.request.number);\r
+ this._reloadComments();\r
+ },\r
+\r
+ _doUpdateRequest: function(event, baseArea, request) {\r
+ baseArea.commentbox("open", this.user, request.request.number);\r
}\r
}\r
+\r
+ // Get github plugin data\r
+ var upstream = $("body").attr("data-github-upstream");\r
+ var basesha1 = $("body").attr("data-github-base-sha1");\r
+ if(upstream && basesha1) {\r
+ GithubUI.init(upstream, basesha1);\r
+ }\r
});\r
"jquery",\r
"jQueryUI"\r
], function($) {\r
+ var Location = function(location) {\r
+ var parts = location.split(":");\r
+ this.origin = location;\r
+ this.path = parts[0];\r
+ this.lstart = parseInt(parts[1].split("--")[0].split(",")[0]);\r
+ this.tabpos = parseInt(parts[1].split("--")[0].split(",")[1]);\r
+ this.lend = parseInt(parts[1].split("--")[1].split(",")[0]);\r
+ this.toString = function() {\r
+ return this.path + ":" + this.lstart + "," + this.tabpos + "--" + this.lend + ",0";\r
+ }\r
+ }\r
+\r
$.widget("nitdoc.commentbox", {\r
\r
options: {\r
previewTxt: "preview",\r
- commitTxt: "Commit...",\r
- cancelTxt: "Cancel"\r
+ commitTxt: "Commit",\r
+ cancelTxt: "Cancel",\r
+ commentboxTitle: "Edit comment",\r
+ messageTxt: "Commit message"\r
},\r
\r
_create: function() {\r
+ this._id = $(".nitdoc-github-commentbox").length\r
+ this._oldComment = this.element.val();\r
+ this._namespace = this.element.data("comment-namespace");\r
+ this._location = new Location(this.element.data("comment-location"));\r
this.commentBox = $("<div/>")\r
+ .hide()\r
.addClass("nitdoc-github-commentbox")\r
.append(\r
- $("<textarea/>")\r
- .addClass("nitdoc-github-commentarea")\r
- .keyup($.proxy(this._doKeyUp, this))\r
- .keydown($.proxy(this._doKeyDown, this))\r
- )\r
- .append(\r
- $("<a/>")\r
- .addClass("nitdoc-github-preview")\r
- .html(this.options.previewTxt)\r
- .click($.proxy(this._doPreviewClick, this))\r
+ $("<h3/>")\r
+ .text(this.options.commentboxTitle)\r
)\r
.append(\r
- $("<button/>")\r
- .addClass("nitdoc-github-button")\r
- .addClass("nitdoc-github-commit")\r
- .html(this.options.commitTxt)\r
- .click($.proxy(this._doCommitClick, this))\r
+ $("<dl/>")\r
+ .addClass("nitdoc-github-commentbox-fields")\r
+ .append(\r
+ $("<dd/>")\r
+ .append(\r
+ $("<textarea/>")\r
+ .attr("id", "nitdoc-github-commentbox-comment" + this._id)\r
+ .addClass("nitdoc-github-commentarea")\r
+ .keyup($.proxy(this._doKeyUp, this))\r
+ .keydown($.proxy(this._doKeyDown, this))\r
+ )\r
+ )\r
+ .append(\r
+ $("<dt/>")\r
+ .append(\r
+ $("<label/>")\r
+ .attr("for", "nitdoc-github-commentbox-message" + this._id)\r
+ .text(this.options.messageTxt + ":")\r
+ )\r
+ )\r
+ .append(\r
+ $("<dd/>")\r
+ .append(\r
+ $("<textarea/>")\r
+ .attr("id", "nitdoc-github-commentbox-message" + this._id)\r
+ .keyup($.proxy(this._doKeyUp, this))\r
+ .keydown($.proxy(this._doKeyDown, this))\r
+ )\r
+ )\r
+ .append(\r
+ $("<dt/>")\r
+ .append(\r
+ $("<input/>")\r
+ .attr({\r
+ id: "nitdoc-github-commentbox-signedoff" + this._id,\r
+ type: "checkbox"\r
+ })\r
+ .change($.proxy(this._doSignedChange, this))\r
+ )\r
+ .append(\r
+ $("<label/>")\r
+ .attr({\r
+ "id": "nitdoc-github-commentbox-signedoff-label" + this._id,\r
+ "for": "nitdoc-github-commentbox-signedoff" + this._id\r
+ })\r
+ )\r
+ )\r
)\r
- .append(\r
- $("<button/>")\r
- .addClass("nitdoc-github-button")\r
- .addClass("nitdoc-github-cancel")\r
- .html(this.options.cancelTxt)\r
- .click($.proxy(this._doCancelClick, this))\r
- );\r
-\r
+ this._buildButtonBar();\r
this.element.after(this.commentBox);\r
},\r
\r
+ _buildButtonBar: function() {\r
+ this.commentBox.append(\r
+ $("<div/>")\r
+ .addClass("nitdoc-github-commentbox-buttons")\r
+ .append(\r
+ $("<a/>")\r
+ .addClass("nitdoc-github-preview")\r
+ .html(this.options.previewTxt)\r
+ .click($.proxy(this._doPreviewClick, this))\r
+ )\r
+ .append(\r
+ $("<button/>")\r
+ .addClass("nitdoc-github-button")\r
+ .addClass("nitdoc-github-commit")\r
+ .attr("disabled", "disabled")\r
+ .html(this.options.commitTxt)\r
+ .click($.proxy(this._doCommitClick, this))\r
+ )\r
+ .append(\r
+ $("<button/>")\r
+ .addClass("nitdoc-github-button")\r
+ .addClass("nitdoc-github-cancel")\r
+ .html(this.options.cancelTxt)\r
+ .click($.proxy(this._doCancelClick, this))\r
+ )\r
+ );\r
+ },\r
+\r
/* public actions */\r
\r
- open: function(value) {\r
- this._originalValue = value;\r
- this._setValue(value);\r
- this._autosize();\r
+ open: function(user, requestID) {\r
+ this._requestID = requestID;\r
+ var value = this.element.val();\r
+ var isNew = !value;\r
+ var message = "doc: " + (isNew ? "added" : "modified") + " comment for " + this._namespace;\r
+ this._setMessage(message);\r
+ this._setSignedOff("Signed-off-by: " + user.signedOff);\r
+ this._setComment(value);\r
this.commentBox.show();\r
- var cbw = this.commentBox.innerWidth();\r
- var taw = this._getArea().outerWidth();\r
- this._getArea().width(cbw - (taw - cbw));\r
- this.commentBox.find("textarea").trigger("keyup");\r
- this.commentBox.find("textarea").focus();\r
+ this.commentBox.find("textarea").width(this.commentBox.innerWidth() - 45)\r
+ $("#nitdoc-github-commentbox-comment" + this._id).focus();\r
+ $("#nitdoc-github-commentbox-comment" + this._id).trigger("keyup");\r
+ $("#nitdoc-github-commentbox-message" + this._id).trigger("keyup");\r
this._trigger("_open", null, {commentBox: this});\r
},\r
\r
\r
/* internals */\r
\r
- _autosize: function() {\r
- this._getArea().height(this._getArea().val().split(/\r|\n/).length * 16);\r
+ _setComment: function(value) {\r
+ $("#nitdoc-github-commentbox-comment" + this._id).val(value);\r
+ },\r
+\r
+ _getComment: function() {\r
+ return $("#nitdoc-github-commentbox-comment" + this._id).val();\r
},\r
\r
- _getArea: function() {\r
- return this.commentBox.find("textarea.nitdoc-github-commentarea");\r
+ _getMessage: function() {\r
+ return $("#nitdoc-github-commentbox-message" + this._id).val();\r
},\r
\r
- _setValue: function(value) {\r
- this._getArea().val(value);\r
+ _setMessage: function(message) {\r
+ $("#nitdoc-github-commentbox-message" + this._id).val(message);\r
},\r
\r
- _getValue: function() {\r
- return this._getArea().val();\r
+ _getSignedOff: function() {\r
+ return $("#nitdoc-github-commentbox-signedoff" + this._id).val();\r
+ },\r
+\r
+ _setSignedOff: function(signedoff) {\r
+ $("#nitdoc-github-commentbox-signedoff" + this._id).val(signedoff);\r
+ $("#nitdoc-github-commentbox-signedoff-label" + this._id).text(signedoff);\r
},\r
\r
/* events */\r
\r
- _doKeyUp: function() {\r
- if(this._getValue() == this._originalValue) {\r
- this.commentBox.find("button.nitdoc-github-commit").attr("disabled", "disabled");\r
- } else {\r
- this.commentBox.find("button.nitdoc-github-commit").removeAttr("disabled");\r
- }\r
- this._autosize();\r
+ _doKeyUp: function(event) {\r
+ $(event.target).height($(event.target).val().split(/\r|\n/).length * 16);\r
},\r
\r
_doKeyDown: function(event) {\r
if(event.keyCode == 13){\r
- this._getArea().css("height", (this._getArea().outerHeight() + 6) + "px");\r
+ $(event.target).css("height", ($(event.target).outerHeight() + 6) + "px");\r
+ }\r
+ },\r
+\r
+ _doSignedChange: function(event) {\r
+ if ($(event.currentTarget).is(':checked')) {\r
+ this.commentBox.find("button.nitdoc-github-commit").removeAttr("disabled");\r
+ } else {\r
+ this.commentBox.find("button.nitdoc-github-commit").attr("disabled", "disabled");\r
}\r
},\r
\r
_doPreviewClick: function(event) {\r
- this._trigger("_preview", event, {value: this._getValue()});\r
+ this._trigger("_preview", event, {value: this._getComment()});\r
},\r
\r
_doCommitClick: function() {\r
- this._trigger("_commit", {value: this._getValue()});\r
+ this._trigger("_commit", event, {\r
+ requestID: this._requestID,\r
+ location: this._location,\r
+ namespace: this._namespace,\r
+ oldComment: this._oldComment,\r
+ newComment: this._getComment(),\r
+ title: this._getMessage(),\r
+ message: this._getMessage() + "\n\n" + this._getSignedOff()\r
+ });\r
},\r
\r
_doCancelClick: function() {\r
+++ /dev/null
-/* This file is part of NIT ( http://www.nitlanguage.org ).\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-*/\r
-\r
-/*\r
- * CommitBox allows user to add a message and sign its commit\r
- */\r
-define([\r
- "jquery",\r
- "jQueryUI"\r
-], function($) {\r
- $.widget("nitdoc.commitbox", {\r
-\r
- options: {\r
- title: "Commit changes"\r
- },\r
-\r
- _create: function() {\r
- this._fade = this._buildFade();\r
- $("body").append(this._fade);\r
- this._commitBox = $("<div/>")\r
- .hide()\r
- .attr("id", "nitdoc-github-commitBox")\r
- .addClass("nitdoc-github-modal")\r
- .append(\r
- $("<a/>")\r
- .addClass("nitdoc-github-close")\r
- .attr("title", "Close")\r
- .append("x")\r
- .click($.proxy(this.close, this))\r
- )\r
- .append("<h3>" + this.options.title + "</h3>")\r
- .append(\r
- $("<div/>")\r
- .append(\r
- $("<label/>")\r
- .attr("for", "nitdoc-github-commit-message")\r
- )\r
- .append($("<br/>"))\r
- .append(\r
- $("<textarea/>")\r
- .attr("id", "nitdoc-github-commit-message")\r
- )\r
- .append($("<br/>"))\r
- .append(\r
- $("<input/>")\r
- .attr({\r
- id: "nitdoc-github-commit-signedoff",\r
- type: "checkbox"\r
- })\r
- .change($.proxy(this._doSignedChange, this))\r
- )\r
- .append(\r
- $("<label/>")\r
- .attr({\r
- "id": "nitdoc-github-commit-signedoff-label",\r
- "for": "nitdoc-github-commit-signedoff"\r
- })\r
- )\r
- ).append(\r
- $("<div/>")\r
- .addClass("nitdoc-github-buttons")\r
- .append(\r
- $("<button/>")\r
- .attr({\r
- id: "nitdoc-github-commit-button",\r
- disabled: "disabled"\r
- })\r
- .addClass("nitdoc-github-button")\r
- .append(\r
- $(document.createElement("img"))\r
- .attr("src", "resources/icons/github-icon.png")\r
- )\r
- .append("Commit")\r
- .click($.proxy(this._doCommitClick, this))\r
- )\r
- );\r
- $("body").append(this._commitBox);\r
- },\r
-\r
- open: function(namespace, user, isNew) {\r
- var message = "doc: " + (isNew ? "added" : "modified") + " comment for " + namespace;\r
- this._setMessage(message);\r
- this._setSignedOff(user.signedOff);\r
- this._fade.show();\r
- this._commitBox.show();\r
- this._commitBox.css({\r
- top: "50%",\r
- marginTop: -(this._commitBox.outerHeight() / 2) + "px",\r
- left: "50%",\r
- marginLeft: -(this._commitBox.outerWidth() / 2) + "px"\r
- })\r
- .find("#nitdoc-github-commit-message").focus();\r
- },\r
-\r
- close: function() {\r
- this._commitBox.hide();\r
- this._fade.hide();\r
- },\r
-\r
- /* internals */\r
-\r
- _buildFade: function() {\r
- return $("<div/>")\r
- .hide()\r
- .attr("id", "nitdoc-github-commitBox-fade")\r
- .addClass("nitdoc-github-fade")\r
- },\r
-\r
- _getMessage: function() {\r
- return $("#nitdoc-github-commit-message").val();\r
- },\r
-\r
- _setMessage: function(message) {\r
- $("#nitdoc-github-commit-message").val(message);\r
- },\r
-\r
- _getSignedOff: function() {\r
- return $("#nitdoc-github-commit-message").val();\r
- },\r
-\r
- _setSignedOff: function(signedoff) {\r
- $("#nitdoc-github-commit-signedoff").val(signedoff);\r
- $("#nitdoc-github-commit-signedoff-label").text(signedoff);\r
- },\r
-\r
- /* events */\r
-\r
- _doSignedChange: function(event) {\r
- if ($(event.currentTarget).is(':checked')) {\r
- $("#nitdoc-github-commit-button").removeAttr("disabled");\r
- } else {\r
- $("#nitdoc-github-commit-button").attr("disabled", "disabled");\r
- }\r
- },\r
-\r
- _doCommitClick: function(event) {\r
- $(event.target).text("Commiting...");\r
- $(event.target).attr("disabled", "disabled");\r
- this._trigger("_commit", event, {\r
- message: this._getMessage(),\r
- signedoff: this._getSignedOff()\r
- });\r
- },\r
-\r
- _doCancelClick: function(event) {\r
- this._trigger("_cancel", event);\r
- }\r
- });\r
-});\r
+++ /dev/null
-/* This file is part of NIT ( http://www.nitlanguage.org ).\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
- Documentation generator for the nit language.\r
- Generate API documentation in HTML format from nit source code.\r
-*/\r
-\r
-/*\r
- * Nitdoc.Github.UI for comment edition module\r
- */\r
-define([\r
- "jquery",\r
- "jQueryUI",\r
- "plugins/github/user",\r
- "plugins/github/github_api",\r
- "plugins/github/utils",\r
- "plugins/github/commentbox",\r
- "plugins/github/modalbox",\r
- "plugins/github/commitbox",\r
- "base64"\r
-], function($, UI, User, GithubAPI, Utils, CommentBox, ModalBox, CommitBox, Base64) {\r
- var UI = {\r
- openedComments: 0, // currently edited comments count\r
- user: false, // logged user\r
-\r
- // Activate comment UI for a logged user\r
- activate: function(loggedUser) {\r
- // Save session\r
- this.user = loggedUser;\r
- this.saveSession(this.user);\r
- \r
- // check local storage synchro with branch\r
- if(localStorage.base != this.origin.sha) {\r
- console.log("Base changed: cleaned cache");\r
- localStorage.requests = "[]";\r
- localStorage.base = this.origin.sha;\r
- }\r
-\r
- // Prevent page unload if there is comments in editing mode\r
- $(window).on('beforeunload', function() {\r
- if(UI.getOpenedComments() > 0){\r
- return "There is uncommited modified comments. Are you sure you want to leave this page?";\r
- }\r
- });\r
-\r
- this.attachCommentEvents();\r
- this.reloadComments();\r
- },\r
-\r
- // clear storage\r
- disactivate: function() {\r
- if(this.openedComments > 0){\r
- if(!confirm('There is uncommited modified comments. Are you sure you want to leave this page?')) {\r
- return false;\r
- }\r
- }\r
- // close session and purge cookie\r
- localStorage.clear();\r
- $(window).unbind('beforeunload');\r
- window.location.reload();\r
- },\r
-\r
- // Attempt login through GitHub API\r
- tryLogin: function(login, password, repo, branch) {\r
- var user = new User(login, password, repo, branch);\r
- if(!GithubAPI.login(user)) {\r
- return "error:login";\r
- }\r
- // check github profile fields\r
- if(!user.infos.name || !user.infos.email) {\r
- return "error:profile";\r
- }\r
- // check correct base commit\r
- var commit = GithubAPI.getCommit(user, this.origin.sha);\r
- if(!commit || !commit.sha) {\r
- return "error:sha";\r
- }\r
- return user;\r
- },\r
-\r
- // Attach edit button on each comment\r
- attachCommentEvents: function() {\r
- $("body").commitbox();\r
- // Blocks without comment\r
- $("span.noComment").each(function() {\r
- //FIXME this should be done by nitdoc\r
- var baseComment = $(this).parent().prev();\r
- var location = Utils.parseLocation(baseComment.attr("data-comment-location"));\r
- var locString = location.path + ":" + location.lstart + "," + location.tabpos + "--" + location.lstart + ",0";\r
- baseComment.attr("data-comment-location", locString);\r
- $(this).html("<a class='nitdoc-github-editComment noComment'>add comment</a> for ");\r
- $(this).addClass("nitdoc-github-editComment");\r
- });\r
- // Blocks with comment\r
- $('.description div.comment').each(function() {\r
- var p = $(this).next();\r
- p.prepend("<span class='nitdoc-github-editComment'><a class='nitdoc-github-editComment'>edit comment</a> for </span>")\r
- });\r
-\r
- // Attach links events\r
- $('a.nitdoc-github-editComment').each(function() {\r
- $(this).css("cursor", "pointer")\r
- $(this).click(function() {\r
- // hide link\r
- $(this).parent().hide();\r
- // add infos\r
- var infos = {};\r
- var baseTextarea;\r
- if(!$(this).hasClass("noComment")) {\r
- $(this).parent().parent().prev().hide();\r
- baseTextarea = $(this).parent().parent().prev().prev();\r
- } else {\r
- baseTextarea = $(this).parent().parent().prev();\r
- infos.isNew = true;\r
- }\r
- infos.user = UI.user;\r
- infos.location = Utils.parseLocation(baseTextarea.attr("data-comment-location"));\r
- infos.namespace = baseTextarea.attr("data-comment-namespace");\r
- infos.oldComment = baseTextarea.val();\r
-\r
- if(infos.requestID) {\r
- // get comment from last pull request\r
- var requests = JSON.parse(localStorage.requests);\r
- infos.newComment = Base64.decode(requests[infos.requestID].comment);\r
- } else {\r
- infos.newComment = false;\r
- }\r
-\r
- baseTextarea.commentbox();\r
- baseTextarea.bind("commentbox_commit", function(event, data) {\r
- $("body").commitbox("open", infos.namespace, infos.user, infos.isNew ? true : false)\r
- //infos.message = $("#nitdoc-github-commit-message").val() + "\n\n" + infos.user.signedOff;\r
- //UI.saveChanges(infos);\r
- });\r
- baseTextarea.bind("commentbox_preview", function(event, data) {\r
- var converter = new Markdown.Converter()\r
- var html = converter.makeHtml(data.value);\r
- ModalBox.open("Preview", html, false);\r
- });\r
- baseTextarea.bind("commentbox_open", function() {\r
- UI.openedComments++;\r
- });\r
- baseTextarea.bind("commentbox_close", function(event, data) {\r
- UI.openedComments--;\r
- if(infos.isNew) {\r
- data.commentBox.commentBox.next().find("span.nitdoc-github-editComment").show();\r
- } else if(infos.requestID) {\r
- data.commentBox.commentBox.next().show();\r
- data.commentBox.commentBox.next().next().show();\r
- } else {\r
- data.commentBox.commentBox.next().show();\r
- data.commentBox.commentBox.next().next().find("span.nitdoc-github-editComment").show();\r
- }\r
- });\r
- baseTextarea.commentbox("open", baseTextarea.val());\r
- });\r
- });\r
- },\r
-\r
- // reload comments from saved pull request\r
- reloadComments: function() {\r
- if(!localStorage.requests){ return; }\r
- var requests = JSON.parse(localStorage.requests);\r
- var converter = new Markdown.Converter();\r
- // Look for modified comments in page\r
- for(i in requests) {\r
- if(!requests[i]) { continue; }\r
- var request = requests[i];\r
- $("textarea[data-comment-location=\"" + request.location + "\"]").each(function () {\r
- var div = $(this).next();\r
- if(request.isClosed) {\r
- if(div.is("div.comment.newComment")) {\r
- // hide empty comment\r
- div.next().remove();\r
- div.next().find("span.noComment").show();\r
- div.remove();\r
- } else if(div.is("div.comment.locked")) {\r
- // unlock comment\r
- div.empty();\r
- div.append(converter.makeHtml($(this).text()));\r
- div.removeClass("locked");\r
- div.css("cursor", "pointer")\r
- div.next().remove();\r
- div.next().find("span.nitdoc-github-editComment").show();\r
- }\r
- } else {\r
- // create div for the new coment\r
- if(!div.is("div.comment")) {\r
- $(this).after("<div class='comment newComment'></div>");\r
- div = $(this).next();\r
- }\r
- // lock modified comment\r
- if(!div.hasClass("locked")) {\r
- // convert modified comment to markdown\r
- div.empty()\r
- div.append(converter.makeHtml(Base64.decode(request.comment)));\r
- // lock click\r
- div.css("cursor", "auto");\r
- div.addClass("locked");\r
- div.next().find("span.nitdoc-github-editComment").hide();\r
- div.after(\r
- $("<p class='locked inheritance'>")\r
- .text("comment modified in ")\r
- .append("<a href='"+ request.request.html_url +"' target='_blank' title='Review on GitHub'>pull request #"+ request.request.number +"</a>")\r
- .append(" ")\r
- .append(\r
- $("<a data-pullrequest-number='"+ request.request.number +"' class='nitdoc-github-update'>update</a>")\r
- .click(function (){\r
- $(this).parent().hide();\r
- div.hide();\r
- var baseTextarea = div.prev();\r
- // add infos\r
- var infos = {};\r
- infos.user = UI.getUser();\r
- infos.location = Utils.parseLocation(baseTextarea.attr("data-comment-location"));\r
- infos.namespace = baseTextarea.attr("data-comment-namespace");\r
- infos.oldComment = baseTextarea.val();\r
- infos.requestID = $(this).attr("data-pullrequest-number");\r
- var box = new CommentBox(infos);\r
- box.open(baseTextarea); \r
- })\r
- )\r
- .append(" ")\r
- .append(\r
- $("<a data-pullrequest-number='"+ request.request.number +"' class='nitdoc-github-cancel'>cancel</a>")\r
- .click(function (){\r
- ui.closePullRequest($(this).attr("data-pullrequest-number"));\r
- ui.reloadComments();\r
- })\r
- )\r
- );\r
- }\r
- // hide "add comment" link\r
- if(div.hasClass("newComment")) {\r
- div.next().next().find("span.noComment").hide();\r
- }\r
- }\r
-\r
- });\r
- }\r
- },\r
-\r
- // Commit changes and send pull request\r
- saveChanges: function(infos) {\r
- // if pull request update close existing pull request for the comment\r
- if(infos.requestID) {\r
- closePullRequest(infos.requestID);\r
- }\r
-\r
- // forge commit\r
- var fileContent = getFileContent(infos.location.path);\r
- infos.newContent = Utils.mergeComment(fileContent, infos.newComment, infos.location);\r
-\r
- // commit\r
- infos.request = pushChanges(infos)\r
- if(!infos.request) {\r
- ModalBox.open("Unable to commit changes!", response, true);\r
- return;\r
- }\r
- saveRequest(infos);\r
-\r
- // close boxes and reload comments \r
- CommitBox.close();\r
- infos.commentBox.close();\r
- reloadComments();\r
- },\r
-\r
- /*\r
- Creating a new pull request with the new comment take 5 steps:\r
- 1. get the base tree from latest commit\r
-\r
- 2. create a new blob with updated file content\r
- 3. post a new tree from base tree and blob\r
- 4. post the new commit with new tree\r
- 5. create the pull request\r
- */\r
- pushChanges: function(infos) {\r
- var baseTree = GithubAPI.getTree(user, origin.sha);\r
- if(!baseTree.sha) {\r
- ModalBox.open("Unable to locate base tree!", baseTree.status + ": " + baseTree.statusText, true);\r
- return false;\r
- }\r
- console.log("Base tree: " + baseTree.url);\r
- var newBlob = GithubAPI.createBlob(user, infos.newContent);\r
- if(!newBlob.sha) {\r
- ModalBox.open("Unable to create new blob!", newBlob.status + ": " + newBlob.statusText, true);\r
- return false;\r
- }\r
- console.log("New blob: " + newBlob.url);\r
- var newTree = GithubAPI.createTree(user, baseTree, infos.location.path, newBlob);\r
- if(!newTree.sha) {\r
- ModalBox.open("Unable to create new tree!", newTree.status + ": " + newTree.statusText, true);\r
- return false;\r
- }\r
- console.log("New tree: " + newTree.url);\r
- var newCommit = GithubAPI.createCommit(user, infos.message, baseTree.sha, newTree);\r
- if(!newCommit.sha) {\r
- ModalBox.open("Unable to create new commit!", newCommit.status + ": " + newCommit.statusText, true);\r
- return false;\r
- }\r
- console.log("New commit: " + newCommit.url);\r
- var pullRequest = GithubAPI.createPullRequest(user, infos.message.split("\n\n")[0], "Pull request from Nitdoc", origin, newCommit.sha);\r
- if(!pullRequest.number) {\r
- ModalBox.open("Unable to create pull request!", pullRequest.status + ": " + pullRequest.statusText, true);\r
- return false;\r
- }\r
- console.log("New pull request: " + pullRequest.url);\r
- return pullRequest;\r
- },\r
-\r
- // close previously opened pull request\r
- closePullRequest: function(number) {\r
- var requests = JSON.parse(localStorage.requests);\r
- if(!requests[number]) {\r
- ModalBox.open("Unable to close pull request!", "Pull request " + number + "not found", true);\r
- return false;\r
- }\r
- // close pull request\r
- var res = GithubAPI.updatePullRequest(user, "Canceled from Nitdoc", "", "closed", requests[number].request);\r
- if(!res.id) {\r
- ModalBox.open("Unable to close pull request!", res.status + ": " + res.statusText, true);\r
- return false;\r
- }\r
- // update in localstorage\r
- requests[number].isClosed = true;\r
- localStorage.requests = JSON.stringify(requests);\r
- },\r
-\r
- // Get file content from github\r
- getFileContent: function(githubUrl) {\r
- var origFile = GithubAPI.getFile(user, githubUrl);\r
- if(!origFile.content) {\r
- ModalBox.open("Unable to locate source file!", origFile.status + ": " + origFile.statusText, true);\r
- return;\r
- }\r
- var base64Content = origFile.content.substring(0, origFile.content.length - 1)\r
- return Base64.decode(base64Content);\r
- },\r
-\r
- // save pull request in local storage\r
- saveRequest: function(infos) {\r
- var requests = [];\r
- if(localStorage.requests) {requests = JSON.parse(localStorage.requests)}\r
- requests[infos.request.number] = {\r
- request: infos.request,\r
- location: infos.location.origin,\r
- comment: Base64.encode(infos.newComment)\r
- };\r
- localStorage.requests = JSON.stringify(requests);\r
- },\r
-\r
- // save user in local storage\r
- saveSession: function(user) {\r
- var session = {\r
- login: user.login,\r
- password: Base64.encode(user.password),\r
- repo: user.repo,\r
- branch: user.branch,\r
- };\r
- localStorage.user = JSON.stringify(session);\r
- }\r
- }\r
- return UI;\r
-});\r
+++ /dev/null
-/* This file is part of NIT ( http://www.nitlanguage.org ).\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
- Documentation generator for the nit language.\r
- Generate API documentation in HTML format from nit source code.\r
-*/\r
-\r
-/*\r
- * GitHub API user object\r
- */\r
-define([\r
- "base64",\r
-], function(Base64) {\r
- return function(login, password, repo, branch) {\r
- this.login = login;\r
- this.password = password;\r
- this.repo = repo;\r
- this.auth = "Basic " + Base64.encode(login + ':' + password);\r
- this.branch = branch;\r
- }\r
-});\r
-\r
+++ /dev/null
-/* This file is part of NIT ( http://www.nitlanguage.org ).\r
-\r
- Licensed under the Apache License, Version 2.0 (the "License");\r
- you may not use this file except in compliance with the License.\r
- You may obtain a copy of the License at\r
-\r
- http://www.apache.org/licenses/LICENSE-2.0\r
-\r
- Unless required by applicable law or agreed to in writing, software\r
- distributed under the License is distributed on an "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- See the License for the specific language governing permissions and\r
- limitations under the License.\r
-\r
- Documentation generator for the nit language.\r
- Generate API documentation in HTML format from nit source code.\r
-*/\r
-\r
-/*\r
- * Nitdoc.Github comment edition module\r
- *\r
- * Allows user to modify source code comments directly from the Nitdoc\r
- */\r
-define([\r
- "jquery",\r
- "base64",\r
- "Markdown.Converter",\r
- "plugins/utils",\r
- "plugins/github/ui",\r
-], function($, Base64, mkdown, utils) {\r
-\r
-/*\r
- * Nitdoc.GitHub.Utils module\r
- */\r
-\r
- return {\r
- // Extract infos from string location "lib/standard/collection/array.nit:457,1--458,0"\r
- parseLocation: function(location) {\r
- var parts = location.split(":");\r
- var loc = new Object();\r
- loc.origin = location;\r
- loc.path = parts[0];\r
- loc.lstart = parseInt(parts[1].split("--")[0].split(",")[0]);\r
- loc.tabpos = parseInt(parts[1].split("--")[0].split(",")[1]);\r
- loc.lend = parseInt(parts[1].split("--")[1].split(",")[0]);\r
- return loc;\r
- },\r
-\r
- // Meld modified comment into file conten\r
- mergeComment: function(fileContent, comment, location) {\r
- // replace comment in file content\r
- var res = new String();\r
- var lines = fileContent.split("\n");\r
- // copy lines fron 0 to lstart\r
- for(var i = 0; i < location.lstart - 1; i++) {\r
- res += lines[i] + "\n";\r
- }\r
- // set comment\r
- if(comment && comment != "") {\r
- var commentLines = comment.split("\n");\r
- for(var i = 0; i < commentLines.length; i++) {\r
- var line = commentLines[i];\r
- var tab = location.tabpos > 1 ? "\t" : "";\r
- res += tab + (line.length > 0 ? "# " : "#") + line + "\n";\r
- }\r
- }\r
- // copy lines fron lend to end\r
- for(var i = location.lend - 1; i < lines.length; i++) {\r
- res += lines[i];\r
- if(i < lines.length - 1) { res += "\n"; }\r
- }\r
- return res;\r
- }\r
- }\r
-});\r
/* Comment editing */\r
\r
.nitdoc-github-commentbox {\r
+ margin: 1em 5px;\r
+ border: 1px solid #eee;\r
+ padding: 1em;\r
+ background: #fff;\r
+ -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);\r
+ -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);\r
+ box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);\r
+}\r
+\r
+.nitdoc-github-commentbox h3 {\r
+ margin: 0;\r
+}\r
+\r
+.nitdoc-github-commentbox-buttons {\r
text-align: right;\r
}\r
\r
+.nitdoc-github-commentbox dl {\r
+ margin-bottom: 0;\r
+}\r
+\r
+.nitdoc-github-commentbox dt {\r
+ margin-bottom: 0.5em;\r
+}\r
+\r
+.nitdoc-github-commentbox dd {\r
+ margin: 0 0 1em 0;\r
+}\r
+\r
.nitdoc-github-commentbox textarea {\r
+ display: block;\r
font-family: monospace;\r
font-size: 1em;\r
width: 100%;\r
- margin-top: 1em;\r
padding: 4px;\r
padding-left: 11px;\r
overflow-y: hidden;\r