├── .gitignore ├── plugin └── emberlayout.vim ├── LICENSE.txt ├── README.md ├── doc └── emberlayout.txt └── autoload └── emberlayout.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | .vimrc.local 3 | -------------------------------------------------------------------------------- /plugin/emberlayout.vim: -------------------------------------------------------------------------------- 1 | " Description: Emlayout command for opening Ember files in windows 2 | " Author: Devin Weaver 3 | " License: MIT 4 | 5 | if exists('g:loaded_emberlayout') 6 | finish 7 | endif 8 | let g:loaded_emberlayout = 1 9 | 10 | command! -nargs=? -complete=file Emlayout call emberlayout#open() 11 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Devin Weaver 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-emberlayout 2 | 3 | This plugin simply takes a base filename in an Ember.js project and will open 4 | a grid of windows for each related file. 5 | 6 | ![animated screen shot](https://sukima.github.io/vim-emberlayout/vim-emberlayout.gif) 7 | 8 | ## Commands, Mappings and Configuration 9 | 10 | Read the [help][txt-doc] to know more. 11 | 12 | ## Installation 13 | 14 | ### Using [Vundle][vundle]: 15 | 16 | Just add this line to your `~/.vimrc`: 17 | 18 | ```vim 19 | Plugin 'sukima/vim-emberlayout' 20 | ``` 21 | 22 | And run `:PluginInstall` inside Vim. 23 | 24 | ### Using [pathogen.vim][pathogen]: 25 | 26 | Copy and paste in your shell: 27 | 28 | ```bash 29 | cd ~/.vim/bundle 30 | git clone https://github.com/sukima/vim-emberlayout.git 31 | ``` 32 | 33 | ### Using [vpm][vpm]: 34 | 35 | Run this command in your shell: 36 | 37 | ```bash 38 | vpm insert sukima/vim-emberlayout 39 | ``` 40 | 41 | ### Using [Plug][plug]: 42 | 43 | Just add this line to your `~/.vimrc` inside plug call: 44 | 45 | ```vim 46 | Plug 'sukima/vim-emberlayout' 47 | ``` 48 | 49 | And run `:PlugInstall` inside Vim or `vim +PlugInstall +qa` from shell. 50 | 51 | ## License 52 | 53 | MIT 54 | 55 | [pathogen]: https://github.com/tpope/vim-pathogen 56 | [txt-doc]: https://raw.githubusercontent.com/sukima/vim-emberlayout/master/doc/emberlayout.txt 57 | [vpm]: https://github.com/KevinSjoberg/vpm 58 | [vundle]: https://github.com/gmarik/vundle 59 | [plug]: https://github.com/junegunn/vim-plug 60 | -------------------------------------------------------------------------------- /doc/emberlayout.txt: -------------------------------------------------------------------------------- 1 | *emberlayout.txt* Open Ember files in a grid 2 | 3 | CONTENTS 4 | 5 | 1. Intro ...................... |EmberLayoutIntro| 6 | 2. Command .................... |:Emlayout| 7 | 3. License .................... |EmberLayoutLicense| 8 | 4. Contributing ............... |EmberLayoutContributing| 9 | 10 | ============================================================================== 11 | 1. Intro *EmberLayoutIntro* 12 | 13 | This plugin simply takes a base filename in an Ember.js project and will open 14 | a grid of windows for each realated file. 15 | 16 | This curently assumes you want to use page-objects with your testing: 17 | 18 | http://ember-cli-page-object.js.org/ 19 | 20 | An example for a component called 'foo-bar' you would get a grid with the 21 | following files loaded: 22 | 23 | +---------+---------+ 24 | | | | 25 | | A | C | 26 | | | | 27 | +---------+---------+ 28 | | | | 29 | | B | D | 30 | | | | 31 | +---------+---------+ 32 | 33 | A: app/components/foo-bar.js 34 | B: app/templates/components/foo-bar.hbs 35 | C: tests/integration/components/foo-bar-test.js 36 | D: tests/pages/components/foo-bar.js 37 | 38 | This was designed to work with components (integration), controllers 39 | (acceptance), and any other type (unit). And hopefully will be able to glean 40 | the correct related files from any of the above types; meaning you can run the 41 | |:Emlayout| command for any of the above files and the same grid should be 42 | presented. 43 | 44 | ============================================================================== 45 | 2. :Emlayout *:Emlayout* 46 | 47 | Use the FILE to open realted files in a grid of windows. 48 | 49 | Usage: 50 | > 51 | :Emlayout [FILE] 52 | < 53 | Examples: 54 | > 55 | :Emlayout 56 | < 57 | Will use the current buffer as the base for related files. 58 | > 59 | :Emlayout app/components/foo-bar.js 60 | < 61 | Will use 'app/components/foo-bar.js' as the base for related files. 62 | 63 | ============================================================================== 64 | 3. License *EmberlayoutLicense* 65 | 66 | Released under the MIT License. 67 | 68 | ============================================================================== 69 | 4. Contributing *EmberLayoutContributing* 70 | 71 | Contributions are welcomed and appreciated. Just follow the normal Github 72 | procedure. Go to: 73 | 74 | https://github.com/sukima/vim-emberlayout.vim 75 | 76 | Fork the project. Work on what you think would make it better. Send a pull 77 | request. 78 | -------------------------------------------------------------------------------- /autoload/emberlayout.vim: -------------------------------------------------------------------------------- 1 | " Description: Functions for opening Ember files in windows 2 | " Author: Devin Weaver 3 | " License: MIT 4 | 5 | function! s:EmberLoadFiles(files) 6 | only 7 | exec 'edit ' . a:files.js 8 | vsplit 9 | exec 'edit ' . a:files.test 10 | wincmd h 11 | if get(a:files, 'template') != '0' 12 | split 13 | exec 'edit ' . a:files.template 14 | wincmd k 15 | endif 16 | if get(a:files, 'page') != '0' 17 | wincmd l 18 | split 19 | exec 'edit ' . a:files.page 20 | wincmd k 21 | wincmd h 22 | endif 23 | endfunction 24 | 25 | function! s:EmberCoffeeifyFilename(file) 26 | let coffeefile = fnamemodify(a:file, ':r') . '.coffee' 27 | if filereadable(coffeefile) 28 | return coffeefile 29 | else 30 | return a:file 31 | endif 32 | endfunction 33 | 34 | function! s:gsub(str,pat,rep) abort 35 | return substitute(a:str,'\v\C'.a:pat,a:rep,'g') 36 | endfunction 37 | 38 | function! s:winshell() abort 39 | return &shell =~? 'cmd' || exists('+shellslash') && !&shellslash 40 | endfunction 41 | 42 | function! s:shellslash(path) abort 43 | if s:winshell() 44 | return s:gsub(a:path,'\\','/') 45 | else 46 | return a:path 47 | endif 48 | endfunction 49 | 50 | function! s:EmberAutoDetectFiles(file) 51 | let normalizedFile = s:shellslash(a:file) 52 | let type = '' 53 | let relativePath = matchstr(normalizedFile, '\(addon\|app\|tests\)/.\+$') 54 | let prefixOffset = strridx(normalizedFile, relativePath) 55 | let prefix = strpart(normalizedFile, 0, prefixOffset) 56 | let parts = split(relativePath, '/') 57 | let base = remove(parts, 0) 58 | 59 | let filename = remove(parts, -1) 60 | let filename = fnamemodify(filename, ':t:r') 61 | 62 | let suffixOffset = strridx(filename, '-test') 63 | if suffixOffset != -1 64 | let filename = strpart(filename, 0, suffixOffset) 65 | endif 66 | 67 | if base == 'addon' || base == 'app' 68 | let appType = remove(parts, 0) 69 | if appType == 'templates' 70 | let appType = remove(parts, 0) 71 | if appType == 'components' 72 | let type = 'components' 73 | else 74 | let type = 'controllers' 75 | endif 76 | elseif appType == 'components' 77 | let type = 'components' 78 | else 79 | let type = appType 80 | endif 81 | elseif base == 'tests' 82 | let testType = remove(parts, 0) 83 | if testType == 'acceptance' 84 | let type = 'controllers' 85 | elseif testType == 'integration' || testType == 'pages' 86 | if parts[0] == 'components' 87 | call remove(parts, 0) 88 | let type = 'components' 89 | else 90 | let type = parts[0] 91 | endif 92 | else 93 | let type = parts[0] 94 | endif 95 | else 96 | echohl WarningMsg 97 | echo 'Unknown Ember entity' 98 | echohl None 99 | return 100 | endif 101 | 102 | call add(parts, filename) 103 | let fileData = {} 104 | 105 | if finddir('addon', prefix) == '' 106 | let typeDir = 'app' 107 | else 108 | let typeDir = 'addon' 109 | endif 110 | 111 | if type == 'components' 112 | let fileData.template = prefix . typeDir . '/templates/components/' . join(parts, '/') . '.hbs' 113 | let fileData.js = EmberCoffeeifyFilename(prefix . typeDir . '/components/' . join(parts, '/') . '.js') 114 | let fileData.test = EmberCoffeeifyFilename(prefix . 'tests/integration/components/' . join(parts, '/') . '-test.js') 115 | let fileData.page = EmberCoffeeifyFilename(prefix . 'tests/pages/components/' . join(parts, '/') . '.js') 116 | elseif type == 'controllers' 117 | let fileData.template = prefix . typeDir . '/templates/' . join(parts, '/') . '.hbs' 118 | let fileData.js = EmberCoffeeifyFilename(prefix . typeDir . '/controllers/' . join(parts, '/') . '.js') 119 | let fileData.test = EmberCoffeeifyFilename(prefix . 'tests/acceptance/' . join(parts, '/') . '-test.js') 120 | let fileData.page = EmberCoffeeifyFilename(prefix . 'tests/pages/' . join(parts, '/') . '.js') 121 | else 122 | let fileData.js = EmberCoffeeifyFilename(prefix . typeDir . '/' . join(parts, '/') . '.js') 123 | let fileData.test = EmberCoffeeifyFilename(prefix . 'tests/unit/' . join(parts, '/') . '-test.js') 124 | endif 125 | 126 | return fileData 127 | endfunction 128 | 129 | function! emberlayout#open(...) 130 | let file = a:0 >= 1 ? a:1 : bufname('%') 131 | let fileData = EmberAutoDetectFiles(file) 132 | call EmberLoadFiles(fileData) 133 | endfunction 134 | --------------------------------------------------------------------------------