Browse files

Moved functions to autoload

Added functions/settings for template/snippets directory
Now uses templates for new Spec/SpecHelper.js files
  • Loading branch information...
1 parent 481e7f4 commit 5191a7336a93dbbfe94eb60d77fe9d4f89fad5ed @claco claco committed Feb 2, 2011
Showing with 89 additions and 22 deletions.
  1. +5 −0 README.textile
  2. +55 −0 autoload/jasmine.vim
  3. +1 −2 ftdetect/jasmine.vim
  4. +2 −18 ftplugin/jasmine.vim
  5. +4 −2 plugin/jasmine.vim
  6. +10 −0 templates/Spec.js
  7. +12 −0 templates/SpecHelper.js
View
5 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
View
55 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
View
3 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
View
20 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()
View
6 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()
+
View
10 templates/Spec.js
@@ -0,0 +1,10 @@
+describe('', function () {
+ beforeEach(function () {
+
+ });
+
+ it('should...', function () {
+ expect(condition).toEqual();
+ });
+});
+
View
12 templates/SpecHelper.js
@@ -0,0 +1,12 @@
+beforeEach(function() {
+ this.addMatchers({
+
+ toHaveSomething: function() {
+ var summary = this.actual;
+ this.actual = summary.clone().wrap('<div>').parent().html();
+
+ // Magical matcher work goes here.
+
+ return false;
+ },
+});

0 comments on commit 5191a73

Please sign in to comment.