3
3
"
4
4
" Author: Arithran Thurairetnam
5
5
" Maintainer: https://github.com/arithran/vim-pizza
6
- " Version: 0.1 .0
6
+ " Version: 0.2 .0
7
7
" ============================================================================
8
8
if exists (" g:pizza#loaded" )
9
9
finish
10
10
endif
11
11
12
- let s: DEFAULT_PIZZA_URL = " https://www.pizzahut.com"
12
+ let s: DEFAULT_PIZZA_URL = " pizza hut"
13
+ let s: INVALID_PIZZERIA = " "
13
14
14
- if ! exists (' g:pizza#default_url ' )
15
- let g: pizza #defaul_url = s: DEFAULT_PIZZA_URL
15
+ if ! exists (' g:pizza#default_pizzeria ' )
16
+ let g: pizza #default_pizzeria = s: DEFAULT_PIZZA_URL
16
17
endif
17
18
18
19
if ! exists (' g:pizza#pizzerias' )
19
20
let g: pizza #pizzerias = { ' pizza hut' : ' https://www.pizzahut.com' ,
20
21
\ ' ph' : ' https://www.pizzahut.com' ,
21
22
\ ' papa johns' : ' https://www.papajohns.com' ,
22
23
\ ' pj' : ' https://www.papajohns.com' ,
24
+ \ ' papa johns pan cheese' : 'https: // www.papajohns.com /
25
+ \ order/builder/ productBuilderInfo?
26
+ \ productGroupId= pan- cheese&productSKU.sku
27
+ \ = 1 - 296 - 3 - 83 &quantity= 1 ',
28
+ \ ' dominos' : ' https://www.dominos.com' ,
23
29
\ }
24
30
endif
25
31
32
+ " Attempt to get a key's corresponding value in a dictionary. If the key does
33
+ " not exist in the dictionary, return the default value instead.
34
+ "
35
+ " @param[in] Dictionary dict to get value from
36
+ " @param[in] String key corresponding to the value to return
37
+ " @param[in] String default value to return if key does not exist in the
38
+ " specified map
39
+ function ! s: GetValueOrDefault (dict , key , default) abort
40
+ return has_key (a: dict , a: key ) ? a: dict [a: key ] : a: default
41
+ endfunction
26
42
27
- function ! OrderPizza () abort
43
+
44
+ " Order pizza from the specified pizzeria
45
+ "
46
+ " @param[in] List<String> a:000 pizzeria name, with each element as a word
47
+ function ! OrderPizza (... )
48
+ let s: pizzeria = s: GetValueOrDefault (g: pizza #pizzerias,
49
+ \ join (a: 000 , " " ),
50
+ \ g: pizza #pizzerias[g: pizza #default_pizzeria])
51
+ call s: OpenURL (s: pizzeria )
52
+ endfunction
53
+
54
+ " Open the specified URL in a browser window.
55
+ "
56
+ " @param[in] String url specified to open
57
+ function ! s: OpenURL (url) abort
28
58
let haskdeinit = system (" ps -e" ) = ~ ' kdeinit'
29
59
let hasdarwin = system (" uname -s" ) = ~ ' Darwin'
30
60
31
61
32
62
if has (" gui_running" )
33
- let args = shellescape (g: pizza # url,1 )." &"
63
+ let args = shellescape (a: url ,1 )." &"
34
64
else
35
- let args = shellescape (g: pizza # url,1 )." > /dev/null"
65
+ let args = shellescape (a: url ,1 )." > /dev/null"
36
66
end
37
67
38
68
if has (" unix" ) && executable (" gnome-open" ) && ! haskdeinit
@@ -44,12 +74,12 @@ function! OrderPizza() abort
44
74
elseif has (" unix" ) && executable (" xdg-open" )
45
75
exe " silent !xdg-open " .args
46
76
elseif has (" win32" ) || has (" win64" )
47
- exe " silent !start explorer " .shellescape (g: pizza # url,1 )
77
+ exe " silent !start explorer " .shellescape (a: url ,1 )
48
78
end
49
79
redraw !
50
80
endfunction
51
81
52
- command ! OrderPizza call OrderPizza ()
82
+ command ! - nargs = * OrderPizza call OrderPizza (<q-args> )
53
83
54
84
nnoremap <silent> <Plug> (pizza#order) :call OrderPizza()<Return>
55
85
0 commit comments