Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Change some TODOs, default settings that can be overriden,

Removed TODOs that have been done
Add new TODOs
Setup some some sensible default settings
Allow default settings to be overriden in vimrc
Settings can be set with buffer specific values (b:vimxqmarklogic_XXXX)
Make sure buffer variables are setup so that let b:vimxq will tab
complete
  • Loading branch information...
commit 3d3e81af6b2ab7439197400ef5fe93342c3b4d8e 1 parent 6f932b6
Darren Cole authored

Showing 1 changed file with 98 additions and 30 deletions. Show diff stats Hide diff stats

  1. 128  plugin/vim-xqmarklogic.vim
128  plugin/vim-xqmarklogic.vim
... ...
@@ -1,4 +1,8 @@
1 1
 " vim-xqmarklogic.vim - man <Leader>B run against marklogic
  2
+" Maintainer:   Darren Cole <http://github.com/coledarr/vim-xqmarklogic>
  3
+" Version:      0.5.0
  4
+" TODO: GetLatestVimScripts: ### ### :AutoInstall: vim-xqmarklogic
  5
+" TODO: see *glvs-plugins*
2 6
 " 
3 7
 " Inspired partly by: http://superiorautomaticdictionary.com/vim-nirvana-interactive-xquery-with-marklogic
4 8
 " Assumes xq is setup
@@ -19,24 +23,16 @@
19 23
 " This script is will execute whatever it is sent with xdmp:eval, so it can do
20 24
 " pretty anything to the database
21 25
 "
22  
-" Assumes xml responses, for not tries to break up lines and re-indent (TODO better
  26
+" Assumes xml responses, for now tries to break up lines and re-indent (TODO better
23 27
 " would be to fix the xquery output) For large responses this can be slow
24 28
 "
25  
-" TODO The user and password are encoded in this file, and should be changed
26  
-" (prompt for password and cache for later calls) Or at least allow setting
27  
-" the values
  29
+" TODO Cleanup for release
  30
+" TODO Prompt for password if unset
28 31
 " TODO Consider a different script instead of xq.xqy.  Use XCC, RestFUL
29 32
 " interface (MarkLogic6 and later), or even just package up the xq.xqy
30  
-" TODO xq.xqy hardcodes database, but it would be better to be configurable
31  
-" (db http header can be set to override hardcoded default).  Best would be
32  
-" configured on a per buffer basis and maybe a default set in .vimrc
33 33
 " TODO add a real help doc
34 34
 " TODO only load for xquery files
35  
-" TODO more options and settings will be needed (botright vs belowright and
36  
-" such)
37  
-" 
38  
-" Maintainer:   Darren Cole <http://github.com/coledarr/vim-xqmarklogic>
39  
-" Version:      0.4.1
  35
+" TODO output something useful when curl returns an error
40 36
 
41 37
 if exists('g:loaded_vimxqmarklogic')
42 38
     finish
@@ -47,6 +43,46 @@ let g:loaded_vimxqmarklogic=1
47 43
 let s:showCurlCmd=0
48 44
 let s:showDuration=1
49 45
 
  46
+" Default Settings {{{
  47
+if !exists('g:vimxqmarklogic_defaultUser')
  48
+    let g:vimxqmarklogic_defaultUser='admin'
  49
+endif
  50
+let b:vimxqmarklogic_user=g:vimxqmarklogic_defaultUser
  51
+
  52
+" Should cause error when query is attempted
  53
+if !exists('g:vimxqmarklogic_defaultPassword')
  54
+    let g:vimxqmarklogic_defaultPassword=''
  55
+    let b:vimxqmarklogic_password=''
  56
+    unlet b:vimxqmarklogic_password
  57
+endif
  58
+let b:vimxqmarklogic_password=g:vimxqmarklogic_defaultPassword
  59
+
  60
+if !exists('g:vimxqmarklogic_defaultURI')
  61
+    let g:vimxqmarklogic_defaultURI='http://'
  62
+endif
  63
+let b:vimxqmarklogic_uri=g:vimxqmarklogic_defaultURI
  64
+
  65
+if !exists('g:vimxqmarklogic_defaultHost')
  66
+    let g:vimxqmarklogic_defaultHost='localhost'
  67
+endif
  68
+let b:vimxqmarklogic_host=g:vimxqmarklogic_defaultHost
  69
+
  70
+if !exists('g:vimxqmarklogic_defaultPort')
  71
+    let g:vimxqmarklogic_defaultPort='8002'
  72
+endif
  73
+let b:vimxqmarklogic_port=g:vimxqmarklogic_defaultPort
  74
+
  75
+if !exists('g:vimxqmarklogic_defaultXq')
  76
+    let g:vimxqmarklogic_defaultXq='/xq.xqy'
  77
+endif
  78
+let b:vimxqmarklogic_xq=g:vimxqmarklogic_defaultXq
  79
+
  80
+if !exists('g:vimxqmarklogic_defaultDb')
  81
+    let g:vimxqmarklogic_defaultDb="Documents"
  82
+endif
  83
+let b:vimxqmarklogic_db=g:vimxqmarklogic_defaultDb
  84
+" end of default Settings }}}
  85
+
50 86
 " Toggle Options
51 87
 command XQtoggleShowCurlCmd :execute s:toggleShowCurlCmd()
52 88
 function! s:toggleShowCurlCmd()
@@ -69,7 +105,7 @@ endfunction
69 105
 command -nargs=1 XQsetDatabase :execute s:setDatabase(<args>)
70 106
 
71 107
 function! s:setDatabase(db)
72  
-    let s:db = a:db
  108
+    let b:vimxqmarklogic_db = a:db
73 109
 endfunction
74 110
 
75 111
 " Running the Query
@@ -77,33 +113,63 @@ map <Leader>B :XQmlquery<cr>
77 113
 
78 114
 command XQmlquery :execute s:QueryMarkLogic(expand("%"))
79 115
 
80  
-let s:host = 'localhost'
81  
-let s:uri = 'http://'
82  
-let s:port = '8002'
83  
-let s:user = 'admin'
84  
-let s:password = 'password'
85  
-let s:xq = '/xq.xqy'
86  
-
87 116
 " Used for preview window
88  
-"let s:out = tempname()
89 117
 function! s:QueryMarkLogic(fname)
90  
-    let info = ''
91  
-    " Use preview window
  118
+    let info        = ''
  119
+
  120
+    " setup local settings
  121
+    " use b:___ if present, else the g:___ value {{{
  122
+    let l:user      = g:vimxqmarklogic_defaultUser
  123
+    "let l:password  = g:vimxqmarklogic_defaultPassword
  124
+    let l:uri       = g:vimxqmarklogic_defaultURI
  125
+    let l:host      = g:vimxqmarklogic_defaultHost
  126
+    let l:port      = g:vimxqmarklogic_defaultPort
  127
+    let l:xq        = g:vimxqmarklogic_defaultXq
  128
+    let l:db        = g:vimxqmarklogic_defaultDb
  129
+ 
  130
+    if exists('b:vimxqmarklogic_user')
  131
+        let l:user = b:vimxqmarklogic_user
  132
+    endif
  133
+
  134
+    if exists('b:vimxqmarklogic_password')
  135
+        let l:password = b:vimxqmarklogic_password
  136
+    endif
  137
+
  138
+    if exists('b:vimxqmarklogic_uri')
  139
+        let l:uri = b:vimxqmarklogic_uri
  140
+    endif
  141
+
  142
+    if exists('b:vimxqmarklogic_host')
  143
+        let l:host = b:vimxqmarklogic_host
  144
+    endif
  145
+
  146
+    if exists('b:vimxqmarklogic_port')
  147
+        let l:port = b:vimxqmarklogic_port
  148
+    endif
  149
+
  150
+    if exists('b:vimxqmarklogic_xq')
  151
+        let l:xq = b:vimxqmarklogic_xq
  152
+    endif
  153
+
  154
+    if exists('b:vimxqmarklogic_db')
  155
+        let l:db = b:vimxqmarklogic_db
  156
+    endif
  157
+    " end of local settings }}}
  158
+
  159
+    " Could use preview window
  160
+    "let s:out = tempname()
92 161
     "pedit s:out
93 162
     "wincmd P
94  
- 
  163
+    
95 164
     " Use a 'nofile' window
96 165
     "botright new
97 166
     belowright new
98 167
 
99  
-    if !exists('s:db')
100  
-        let s:db = 'Documents'
101  
-    endif
102  
-    let info .= ' db="' . s:db . '"'
  168
+    let info .= ' db="' . l:db . '"'
103 169
 
104 170
     setlocal buftype=nofile
105 171
     setlocal filetype=xml
106  
-    let curlCmd='curl --digest --user ' . s:user . ':' . s:password . ' -s -X PUT -d@"' . a:fname . '" ' . s:uri . s:host . ':' . s:port  . s:xq . '?db='.s:db
  172
+    let curlCmd='curl --digest --user ' . l:user . ':' . l:password . ' -s -X PUT -d@"' . a:fname . '" ' . l:uri . l:host . ':' . l:port  . l:xq . '?db='.l:db
107 173
 
108 174
     if (s:showCurlCmd)
109 175
         call append(0, '<!-- ' . curlCmd . '  -->')
@@ -111,7 +177,7 @@ function! s:QueryMarkLogic(fname)
111 177
 
112 178
     let start=reltime()
113 179
     execute 'r! ' . curlCmd
114  
-    "execute 'r! curl --digest --user ' . s:user . ':' . s:password . ' -s -X PUT -d@"' . a:fname . '" ' . s:uri . s:host . ':' . s:port  . s:xq
  180
+
115 181
     if (s:showDuration)
116 182
         let end=reltimestr(reltime(start))
117 183
         let info .= ' query_duration="' . end . '"'
@@ -122,3 +188,5 @@ function! s:QueryMarkLogic(fname)
122 188
     silent! :%s/></>
</g
123 189
     normal gg=G 
124 190
 endfunction
  191
+
  192
+" vim:foldmarker=marker foldlevel=5:

0 notes on commit 3d3e81a

Please sign in to comment.
Something went wrong with that request. Please try again.