Modernize gists package with package.cson

This commit is contained in:
Kevin Sawicki
2013-02-07 19:32:37 -08:00
committed by Corey Johnson & Kevin Sawicki
parent df962afe0e
commit a70f5ea1f7
4 changed files with 12 additions and 19 deletions

View File

@@ -1,12 +0,0 @@
DeferredAtomPackage = require 'deferred-atom-package'
module.exports =
class GistsPackage extends DeferredAtomPackage
loadEvents:
'gist:create': '.editor'
instanceClass: 'gists/lib/gists'
onLoadEvent: (event, instance) ->
instance.createGist(event.currentTargetView())

View File

@@ -3,12 +3,15 @@ $ = require 'jquery'
module.exports =
class Gists
@activate: -> new Gists
@activate: (rootView) -> new Gists(rootView)
constructor: (@rootView) ->
constructor: ->
rootView.command 'gist:create', '.editor', => @createGist()
createGist: (editor) ->
editor = rootView.getActiveEditor()
return unless editor?
gist = { public: false, files: {} }
gist.files[editor.getBuffer().getBaseName()] =
content: editor.getSelectedText() or editor.getText()
@@ -27,5 +30,5 @@ class Gists
@div class: 'content', =>
@h3 "Gist #{response.id} created", class: 'title'
@p "The url is on your clipboard", class: 'message'
@rootView.append(notification.hide())
rootView.append(notification.hide())
notification.fadeIn().delay(2000).fadeOut(complete: -> $(this).remove())

View File

@@ -0,0 +1,3 @@
'main': 'lib/gists'
'activationEvents':
'gist:create': '.editor'

View File

@@ -2,12 +2,11 @@ RootView = require 'root-view'
$ = require 'jquery'
describe "Gists package", ->
[rootView, editor] = []
[editor] = []
beforeEach ->
rootView = new RootView(fixturesProject.resolve('sample.js'))
atom.loadPackage('gists').getInstance()
atom.loadPackage('gists')
editor = rootView.getActiveEditor()
spyOn($, 'ajax')