diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ade14b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +node_modules diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..bd01255 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2014 Shinji Tanaka + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2f937ed --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# dash-on-cursor package + +Search the word on the cursor with Dash diff --git a/keymaps/dash-on-cursor.cson b/keymaps/dash-on-cursor.cson new file mode 100644 index 0000000..a721e08 --- /dev/null +++ b/keymaps/dash-on-cursor.cson @@ -0,0 +1,2 @@ +'.editor': + 'cmd-ctrl-d': 'dash-on-cursor:open' diff --git a/lib/dash-on-cursor.coffee b/lib/dash-on-cursor.coffee new file mode 100644 index 0000000..0bf0dcb --- /dev/null +++ b/lib/dash-on-cursor.coffee @@ -0,0 +1,40 @@ +shell = require 'shell' + +grammar2docsets = + C: "c,glib,gl2,gl3,gl4,manpages" + "C++": "cpp,net,boost,qt,cvcpp,cocos2dx,c,manpages" + CoffeeScript: "coffee" + CSS: "css,bootstrap,foundation,less,cordova,phonegap" + "Github Markdown": "markdown" + Go: "go" + HTML: "html,svg,css,bootstrap,foundation,javascript,jquery,jqueryui,jquerym,angularjs,backbone,marionette,meteor,moo,prototype,ember,lodash,underscore,sencha,extjs,knockout,zepto,cordova,phonegap,yui" + Java: "java,javafx,grails,groovy,playjava,spring,cvj,processing" + JavaScript: "javascript,backbone,angularjs,nodejs" + LESS: "less" + "Objective-C": "cpp,iphoneos,macosx,appledoc,cocos2dx,cocos2d,cocos3d,kobold2d,sparrow,c,manpages" + "Objective-C++": "cpp,iphoneos,macosx,appledoc,cocos2dx,cocos2d,cocos3d,kobold2d,sparrow,c,manpages" + Perl: "perl,manpages" + PHP: "php,wordpress,drupal,zend,laravel,yii,joomla,ee,codeigniter,cakephp,symfony,typo3,twig,smarty,html,mysql,sqlite,mongodb,psql,redis" + Python: "python3,django,twisted,sphinx,flask,cvp" + Ruby: "ruby,rubygems,rails" + SASS: "sass,compass,bourbon,neat,css" + Scala: "scala,akka,playscala" + YAML: "chef,ansible" + +module.exports = + activate: (state) -> + atom.workspaceView.command "dash-on-cursor:open", => @open() + + open: -> + editor = atom.workspace.getActiveEditor() + return unless editor? + + token = editor.tokenForBufferPosition(editor.getCursorBufferPosition()) + return unless token?.value + + grammar = editor.getGrammar() + docsets = grammar2docsets[grammar.name] if grammar + if docsets + shell.openExternal("dash-plugin://keys=#{docsets}&query=#{token.value}") + else + shell.openExternal("dash://#{token.value}") diff --git a/package.json b/package.json new file mode 100644 index 0000000..d5a8839 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "dash-on-cursor", + "main": "./lib/dash-on-cursor", + "version": "0.0.1", + "private": true, + "description": "Search the word on the cursor with Dash", + "activationEvents": ["dash-on-cursor:open"], + "repository": "https://github.com/stanaka/dash-on-cursor", + "license": "MIT", + "engines": { + "atom": ">0.50.0" + }, + "dependencies": { + } +} diff --git a/spec/dash-on-cursor-spec.coffee b/spec/dash-on-cursor-spec.coffee new file mode 100644 index 0000000..c6bef64 --- /dev/null +++ b/spec/dash-on-cursor-spec.coffee @@ -0,0 +1,30 @@ +{WorkspaceView} = require 'atom' +shell = require 'shell' + +describe "dash-on-cursor package", -> + activationPromise = null + + beforeEach -> + atom.packages.activatePackage('language-coffee-script') + + atom.workspaceView = new WorkspaceView + atom.workspace = atom.workspaceView.model + + activationPromise = atom.packages.activatePackage('dash-on-cursor') + + describe "when the dash:open event is triggered", -> + it "opens dash for searching text on the cursor", -> + atom.workspaceView.openSync('sample.coffee') + editorView = atom.workspaceView.getActiveView() + {editor} = editorView + editor.setText("return\n") + + spyOn(shell, 'openExternal') + editorView.trigger('dash-on-cursor:open') + expect(shell.openExternal).not.toHaveBeenCalled() + + editor.setCursorBufferPosition([0,5]) + editorView.trigger('dash-on-cursor:open') + + expect(shell.openExternal).toHaveBeenCalled() + expect(shell.openExternal.argsForCall[0][0]).toBe 'dash://return'