mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Modernize gists package with package.cson
This commit is contained in:
committed by
Corey Johnson & Kevin Sawicki
parent
df962afe0e
commit
a70f5ea1f7
@@ -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())
|
||||
@@ -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())
|
||||
|
||||
3
src/packages/gists/package.cson
Normal file
3
src/packages/gists/package.cson
Normal file
@@ -0,0 +1,3 @@
|
||||
'main': 'lib/gists'
|
||||
'activationEvents':
|
||||
'gist:create': '.editor'
|
||||
@@ -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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user