Skip to content

Instantly share code, notes, and snippets.

@danielfoxp2
Created January 29, 2018 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielfoxp2/d39efa83dbbfe88425c5c6be6b349a1f to your computer and use it in GitHub Desktop.
Save danielfoxp2/d39efa83dbbfe88425c5c6be6b349a1f to your computer and use it in GitHub Desktop.
A especialized piece to alternate spec and production js code inside a phoenix 1.2 project
" It has to be put inside the https://github.com/danielfoxp2/vim-openalternatefile-phx1.2
" in order to work. It is not placed in the plugin because it is very opinionated about where
" the js files will be. So while I can decide if it is good or not to put it in there, I will
" keep it here.
" This let is_javascript_specs = match(current_file, '\.js$') != -1 and
" this
" elseif is_javascript_specs
" let new_file = BuildJavascriptUnitPath()
" is needed in the function AlternateForCurrentFile() then this will do the magic:
function! BuildJavascriptUnitPath()
let current_file = expand("%")
let in_spec = match(current_file, '_spec.js') != -1
let going_to_spec = !in_spec
if going_to_spec
let new_file = substitute(current_file, 'web/static/assets/js/', 'spec/js/', '')
let new_file = substitute(new_file, '\.js$', '_spec.js', '')
else
let new_file = substitute(current_file, 'spec/js/', 'web/static/assets/js/', '')
let new_file = substitute(new_file, '_spec\.js$', '.js', '')
endif
return new_file
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment