diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..ade14b9 --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +node_modules diff --git a/lib/npm-docs-view.coffee b/lib/npm-docs-view.coffee index a4eb1c5..f5713ea 100644 --- a/lib/npm-docs-view.coffee +++ b/lib/npm-docs-view.coffee @@ -1,4 +1,4 @@ -{ScrollView} = require 'atom' +{ScrollView} = require 'atom-space-pen-views' module.exports = class NpmDocsView extends ScrollView @@ -22,12 +22,13 @@ class NpmDocsView extends ScrollView path: @path handleEvents: -> - @subscribe this, 'core:move-up', => @scrollUp() - @subscribe this, 'core:move-down', => @scrollDown() + @on 'core:move-up', this, => @scrollUp() + @on 'core:move-down',this, => @scrollDown() # Tear down any state and detach destroy: -> - @unsubscribe() + @off('core:move-up',this) + @off('core:move-down',this) getTitle: -> "npm-docs: #{@path}" diff --git a/lib/npm-docs.coffee b/lib/npm-docs.coffee index 3802e5d..3e97532 100644 --- a/lib/npm-docs.coffee +++ b/lib/npm-docs.coffee @@ -8,39 +8,42 @@ module.exports = npmDocsView: null activate: (state) -> - atom.workspace.registerOpener (uriToOpen) -> + atom.workspace.addOpener (uriToOpen) -> {protocol, host} = url.parse(uriToOpen) return unless protocol is 'npm-docs:' new NpmDocsView(host) - atom.workspaceView.command "npm-docs:open", => - open("https://npmjs.org/package/#{@getSelection()}") + atom.commands.add 'atom-workspace', + "npm-docs:open": => + selection = @getSelection() + if(selection.trim() == '') then return + open("https://npmjs.org/package/#{selection}") - atom.workspaceView.command "npm-docs:homepage", => - @search (err, json, selection) -> - if (err) then throw err - open(json.homepage) + "npm-docs:homepage": => + @search (err, json, selection) -> + if (err) then throw err + open(json.homepage) - atom.workspaceView.command "npm-docs:readme", => - @search (err, json, selection) -> - if (err) then throw err - markdown = json.readme - if !markdown then return - roaster markdown, {}, (err, contents) -> + "npm-docs:readme": => + @search (err, json, selection) -> if (err) then throw err - uri = "npm-docs://#{selection}" - previousActivePane = atom.workspace.getActivePane() - atom.workspace.open(uri, split: 'right', searchAllPanes: true).done (npmDocsView) -> - npmDocsView.renderContents(contents) - previousActivePane.activate() + markdown = json.readme + if !markdown then return + roaster markdown, {}, (err, contents) -> + if (err) then throw err + uri = "npm-docs://#{selection}" + previousActivePane = atom.workspace.getActivePane() + atom.workspace.open(uri, split: 'right', searchAllPanes: true).done (npmDocsView) -> + npmDocsView.renderContents(contents) + previousActivePane.activate() getSelection: -> - editor = atom.workspace.getActiveEditor() - editor.getSelection().getText() || editor.getWordUnderCursor() + editor = atom.workspace.getActiveTextEditor() + editor.getSelectedText() || editor.getWordUnderCursor() search: (cb) -> selection = @getSelection() - + if(selection.trim() == '') then return request.get "https://registry.npmjs.org/#{selection}", (err, res) -> if (err) then throw err diff --git a/package.json b/package.json index 8c91f7b..f3955c6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "npm-docs", "main": "./lib/npm-docs", - "version": "0.2.0", + "version": "0.3.1", "private": true, "description": "Helpful information for node modules for the Atom text editor", "activationEvents": [ @@ -16,6 +16,7 @@ "atom": ">0.50.0" }, "dependencies": { + "atom-space-pen-views": "^2.2.0", "request": "~2.34.0", "roaster": "~1.0.1", "open": "0.0.4" diff --git a/spec/npm-docs-spec.coffee b/spec/npm-docs-spec.coffee index fd77e2d..5a719b7 100644 --- a/spec/npm-docs-spec.coffee +++ b/spec/npm-docs-spec.coffee @@ -1,4 +1,5 @@ NpmDocs = require '../lib/npm-docs' +{$} = require 'atom-space-pen-views' # Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs. # @@ -6,24 +7,26 @@ NpmDocs = require '../lib/npm-docs' # or `fdescribe`). Remove the `f` to unfocus the block. describe "NpmDocs", -> - activationPromise = null + loadpackage = null beforeEach -> - atom.workspaceView = new WorkspaceView - activationPromise = atom.packages.activatePackage('npmDocs') - + atom.workspaceView = atom.views.getView(atom.workspace) + loadpackage = atom.packages.enablePackage("npm-docs") + console.log loadpackage describe "when the npm-docs:search event is triggered", -> it "attaches and then detaches the view", -> - expect(atom.workspaceView.find('.npm-docs')).not.toExist() + expect($(atom.workspaceView).find('.npm-docs')).not.toExist() # This is an activation event, triggering it will cause the package to be # activated. - atom.workspaceView.trigger 'npm-docs:toggle' + atom.commands.dispatch atom.workspaceView, 'npm-docs:toggle' - waitsForPromise -> - activationPromise + #waitsForPromise -> + #loadpackage.activationPromise runs -> - expect(atom.workspaceView.find('.npm-docs')).toExist() - atom.workspaceView.trigger 'npm-docs:search' - expect(atom.workspaceView.find('.npm-docs')).not.toExist() + console.log loadpackage + #console.log $(atom.workspaceView).find('.npm-docs') + expect($(atom.workspaceView).find('.npm-docs')).toExist() + atom.commands.dispatch atom.workspaceView, 'npm-docs:search' + expect($(atom.workspaceView).find('.npm-docs')).not.toExist()