diff --git a/package.json b/package.json index 377ceccf2..9490623dc 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "autoflow": "0.1.0", "command-logger": "0.1.0", "gfm": "0.1.0", + "gists": "0.1.0", "image-view": "0.1.0", "spell-check": "0.1.0", "terminal": "0.3.0", diff --git a/src/packages/gists/keymaps/gists.cson b/src/packages/gists/keymaps/gists.cson deleted file mode 100644 index fa7699100..000000000 --- a/src/packages/gists/keymaps/gists.cson +++ /dev/null @@ -1,2 +0,0 @@ -'body': - 'alt-meta-g': 'gist:create' diff --git a/src/packages/gists/lib/gists.coffee b/src/packages/gists/lib/gists.coffee deleted file mode 100644 index ca181da69..000000000 --- a/src/packages/gists/lib/gists.coffee +++ /dev/null @@ -1,36 +0,0 @@ -$ = require 'jquery' -{$$} = require 'space-pen' -module.exports = -class Gists - @activate: -> new Gists - - constructor: -> - rootView.command 'gist:create', '.editor', => @createGist() - - createGist: -> - editor = rootView.getActiveView() - return unless editor? - - gist = { public: false, files: {} } - gist.files[editor.getBuffer().getBaseName()] = - content: editor.getSelectedText() or editor.getText() - - $.ajax - url: 'https://api.github.com/gists' - type: 'POST' - dataType: 'json' - contentType: 'application/json; charset=UTF-8' - data: JSON.stringify(gist) - beforeSend: (xhr) -> - if token = require('keytar').getPassword('GitHub.com', 'github') - xhr.setRequestHeader('Authorization', "bearer #{token}") - success: (response) => - pasteboard.write(response.html_url) - notification = $$ -> - @div class: 'notification', => - @span class: 'icon icon-gist mega-octicon' - @div class: 'content', => - @h3 "Gist #{response.id} created", class: 'title' - @p "The url is on your clipboard", class: 'message' - rootView.append(notification.hide()) - notification.fadeIn().delay(2000).fadeOut(complete: -> $(this).remove()) diff --git a/src/packages/gists/package.cson b/src/packages/gists/package.cson deleted file mode 100644 index 74aff3d23..000000000 --- a/src/packages/gists/package.cson +++ /dev/null @@ -1,4 +0,0 @@ -'main': './lib/gists' -'description': 'Create a Gist from the selected text or current editor contents.' -'activationEvents': - 'gist:create': '.editor' diff --git a/src/packages/gists/spec/gists-spec.coffee b/src/packages/gists/spec/gists-spec.coffee deleted file mode 100644 index 58866b892..000000000 --- a/src/packages/gists/spec/gists-spec.coffee +++ /dev/null @@ -1,53 +0,0 @@ -RootView = require 'root-view' -$ = require 'jquery' - -describe "Gists package", -> - [editor] = [] - - beforeEach -> - window.rootView = new RootView - rootView.open('sample.js') - atom.activatePackage('gists') - editor = rootView.getActiveView() - spyOn($, 'ajax') - - describe "when gist:create is triggered on an editor", -> - - describe "when the editor has no selection", -> - [request, originalFxOffValue] = [] - - beforeEach -> - editor.trigger 'gist:create' - expect($.ajax).toHaveBeenCalled() - request = $.ajax.argsForCall[0][0] - - it "creates an Ajax request to api.github.com with the entire buffer contents as the Gist's content", -> - expect(request.url).toBe 'https://api.github.com/gists' - expect(request.type).toBe 'POST' - requestData = JSON.parse(request.data) - expect(requestData.public).toBeFalsy() - expect(requestData.files).toEqual 'sample.js': content: editor.getText() - - describe "when the server responds successfully", -> - beforeEach -> - request.success(html_url: 'https://gist.github.com/1', id: '1') - - it "places the created Gist's URL on the clipboard", -> - expect(pasteboard.read()[0]).toBe 'https://gist.github.com/1' - - it "flashes that the Gist was created", -> - expect(rootView.find('.notification')).toExist() - expect(rootView.find('.notification .title').text()).toBe 'Gist 1 created' - advanceClock(2000) - expect(rootView.find('.notification')).not.toExist() - - describe "when the editor has a selection", -> - beforeEach -> - editor.setSelectedBufferRange [[4, 0], [8, 0]] - - it "creates an Ajax with the selected text as the Gist's content", -> - editor.trigger 'gist:create' - expect($.ajax).toHaveBeenCalled() - request = $.ajax.argsForCall[0][0] - requestData = JSON.parse(request.data) - expect(requestData.files).toEqual 'sample.js': content: editor.getSelectedText()