diff --git a/src/packages/gists/index.coffee b/src/packages/gists/index.coffee deleted file mode 100644 index 6205cb366..000000000 --- a/src/packages/gists/index.coffee +++ /dev/null @@ -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()) diff --git a/src/packages/gists/lib/gists.coffee b/src/packages/gists/lib/gists.coffee index b46e5beab..4cc241fcd 100644 --- a/src/packages/gists/lib/gists.coffee +++ b/src/packages/gists/lib/gists.coffee @@ -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()) diff --git a/src/packages/gists/package.cson b/src/packages/gists/package.cson new file mode 100644 index 000000000..45603d61f --- /dev/null +++ b/src/packages/gists/package.cson @@ -0,0 +1,3 @@ +'main': 'lib/gists' +'activationEvents': + 'gist:create': '.editor' diff --git a/src/packages/gists/spec/gists-spec.coffee b/src/packages/gists/spec/gists-spec.coffee index 056d6e412..5382fb33f 100644 --- a/src/packages/gists/spec/gists-spec.coffee +++ b/src/packages/gists/spec/gists-spec.coffee @@ -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')