mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Pull out gists package into a separate repo
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
'body':
|
||||
'alt-meta-g': 'gist:create'
|
||||
@@ -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())
|
||||
@@ -1,4 +0,0 @@
|
||||
'main': './lib/gists'
|
||||
'description': 'Create a Gist from the selected text or current editor contents.'
|
||||
'activationEvents':
|
||||
'gist:create': '.editor'
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user