From 5191a7336a93dbbfe94eb60d77fe9d4f89fad5ed Mon Sep 17 00:00:00 2001 From: "Christopher H. Laco" Date: Wed, 2 Feb 2011 00:17:20 -0500 Subject: [PATCH] Moved functions to autoload Added functions/settings for template/snippets directory Now uses templates for new Spec/SpecHelper.js files --- README.textile | 5 ++++ autoload/jasmine.vim | 55 +++++++++++++++++++++++++++++++++++++++++ ftdetect/jasmine.vim | 3 +-- ftplugin/jasmine.vim | 20 ++------------- plugin/jasmine.vim | 6 +++-- templates/Spec.js | 10 ++++++++ templates/SpecHelper.js | 12 +++++++++ 7 files changed, 89 insertions(+), 22 deletions(-) create mode 100644 autoload/jasmine.vim create mode 100644 templates/Spec.js create mode 100644 templates/SpecHelper.js diff --git a/README.textile b/README.textile index 54e26af..a969e11 100644 --- a/README.textile +++ b/README.textile @@ -29,6 +29,11 @@ This plugin is pretty basic right now. It currently: ** matcher: matcher block for SpecHelper.js ** expect: expect..to line ** spy: spyOn method +* Uses templates for new Spec/SpecHelper buffers + +You can disable templating by setting g:jasmine_use_templates="" + +By default, the plugin assumes the templates are in bundle/jasmine/template and the snippets are in bundle/jasmine/snippets. You can override those by setting g:jasmine_snippets_directory and g:jasmine_templates_directory in your vimrc h2. TODO diff --git a/autoload/jasmine.vim b/autoload/jasmine.vim new file mode 100644 index 0000000..efffbf6 --- /dev/null +++ b/autoload/jasmine.vim @@ -0,0 +1,55 @@ +if exists("g:loaded_autoloadjasmine") || &cp + finish +endif + +let g:loaded_autoloadjasmine=1 + +if !exists("g:jasmine_use_templates") + let g:jasmine_use_templates = 1 +endif + +function jasmine#directory() + if !exists("g:jasmine_directory") + for directory in pathogen#split(&rtp) + if directory =~ "jasmine$" + let g:jasmine_directory = directory + endif + endfor + endif + + return g:jasmine_directory +endfunction + +function jasmine#snippets_directory() + if !exists("g:jasmine_snippets_directory") + let g:jasmine_snippets_directory = jasmine#directory() . "/snippets" + endif + + return g:jasmine_snippets_directory +endfunction + +function jasmine#templates_directory() + if !exists("g:jasmine_templates_directory") + let g:jasmine_templates_directory = jasmine#directory() . "/templates" + endif + + return g:jasmine_templates_directory +endfunction + +function jasmine#load_snippets() + if !exists("s:loaded_snippets") + if exists("*ExtractSnips") + call ExtractSnips(jasmine#snippets_directory(), "jasmine") + end + + let s:loaded_snippets = 1 + endif +endfunction + +function jasmine#configure_templates() + if g:jasmine_use_templates && !exists("g:configured_templates") + autocmd BufNewFile *Spec.js execute "0r".jasmine#templates_directory()."/Spec.js" + autocmd BufNewFile *SpecHelper.js execute "0r".jasmine#templates_directory()."/SpecHelper.js" + let g:configured_templates=1 + endif +endfunction diff --git a/ftdetect/jasmine.vim b/ftdetect/jasmine.vim index b146603..f201b60 100644 --- a/ftdetect/jasmine.vim +++ b/ftdetect/jasmine.vim @@ -1,2 +1 @@ -au BufNewFile,BufRead,BufWritePost *[Ss]pec.js set filetype=jasmine.javascript syntax=jasmine -au BufNewFile,BufRead,BufWritePost *[Ss]pec[Hh]elper.js set filetype=jasmine.javascript syntax=jasmine +autocmd BufNewFile,BufRead,BufWritePost *Spec.js,*SpecHelper.js set filetype=jasmine.javascript syntax=jasmine diff --git a/ftplugin/jasmine.vim b/ftplugin/jasmine.vim index 5f846d9..09fbbf9 100644 --- a/ftplugin/jasmine.vim +++ b/ftplugin/jasmine.vim @@ -1,23 +1,7 @@ -if exists("b:did_ftplugin") +if exists("b:did_ftplugin") || &cp finish endif -if !exists("g:loaded_jasmine_snippets") - if exists("g:loaded_pathogen") - - if !exists("g:jasmine_snippets_dir") - for dir in pathogen#split(&rtp) - if dir =~ "jasmine$" && isdirectory(dir."/snippets") - let g:jasmine_snippets_dir = dir."/snippets" - endif - endfor - endif - - call ExtractSnips(g:jasmine_snippets_dir, "jasmine") - end - - let g:loaded_jasmine_snippets = 1 -endif - let b:did_ftplugin = 1 +call jasmine#load_snippets() diff --git a/plugin/jasmine.vim b/plugin/jasmine.vim index 641fd69..f6c1bc2 100644 --- a/plugin/jasmine.vim +++ b/plugin/jasmine.vim @@ -1,6 +1,8 @@ -if exists("g:loaded_jasmine") +if exists("g:loaded_jasmine") || &cp finish -endif +end let g:loaded_jasmine=1 +call jasmine#configure_templates() + diff --git a/templates/Spec.js b/templates/Spec.js new file mode 100644 index 0000000..7f83379 --- /dev/null +++ b/templates/Spec.js @@ -0,0 +1,10 @@ +describe('', function () { + beforeEach(function () { + + }); + + it('should...', function () { + expect(condition).toEqual(); + }); +}); + diff --git a/templates/SpecHelper.js b/templates/SpecHelper.js new file mode 100644 index 0000000..f6c40f2 --- /dev/null +++ b/templates/SpecHelper.js @@ -0,0 +1,12 @@ +beforeEach(function() { + this.addMatchers({ + + toHaveSomething: function() { + var summary = this.actual; + this.actual = summary.clone().wrap('
').parent().html(); + + // Magical matcher work goes here. + + return false; + }, +});