Skip to content

Commit d8d17cd

Browse files
committed
0.2.0
:OrderPizza optionally selects from an option of pizzerias
1 parent d1cc3bb commit d8d17cd

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

doc/pizza.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,17 @@ the following to your |vimrc| to bind a key like |F5|: >
6868
------------------------------------------------------------------------------
6969
2.3 Variables *pizza-variables*
7070

71-
DEFAULT URL *g:pizza#default_url*
71+
DEFAULT PIZZERIA *g:pizza#default_pizzeria*
7272

7373
Type: |String|
74-
Default: `'https://www.pizzahut.com'`
74+
Default: `'pizza hut'`
7575

76-
This specifies which URL the |:OrderPizza| command should visit by default if
76+
This specifies which pizzeria the |:OrderPizza| command should visit by default if
7777
no parameters are specified. For example, if you always order Papa John's Pan
7878
Cheese, add the following to your |vimrc|: >
7979
8080
81-
let g:vim_pizza_url ='https://www.papajohns.com/order/builder/
82-
\ productBuilderInfo?productGroupId=pan-
83-
\ cheese&productSKU.sku=1-296-3-83&quantity=1'
81+
let g:pizza#default_pizzeria = 'papa johns pan cheese'
8482
<
8583

8684
PIZZERIAS *g:pizza#urpizzerias*

plugin/pizza.vim

+39-9
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,66 @@
33
"
44
" Author: Arithran Thurairetnam
55
" Maintainer: https://github.com/arithran/vim-pizza
6-
" Version: 0.1.0
6+
" Version: 0.2.0
77
" ============================================================================
88
if exists("g:pizza#loaded")
99
finish
1010
endif
1111

12-
let s:DEFAULT_PIZZA_URL = "https://www.pizzahut.com"
12+
let s:DEFAULT_PIZZA_URL = "pizza hut"
13+
let s:INVALID_PIZZERIA = ""
1314

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
1617
endif
1718

1819
if !exists('g:pizza#pizzerias')
1920
let g:pizza#pizzerias = { 'pizza hut' : 'https://www.pizzahut.com',
2021
\ 'ph' : 'https://www.pizzahut.com',
2122
\ 'papa johns' : 'https://www.papajohns.com',
2223
\ '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',
2329
\ }
2430
endif
2531

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
2642

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
2858
let haskdeinit = system("ps -e") =~ 'kdeinit'
2959
let hasdarwin = system("uname -s") =~ 'Darwin'
3060

3161

3262
if has("gui_running")
33-
let args = shellescape(g:pizza#url,1)." &"
63+
let args = shellescape(a:url,1)." &"
3464
else
35-
let args = shellescape(g:pizza#url,1)." > /dev/null"
65+
let args = shellescape(a:url,1)." > /dev/null"
3666
end
3767

3868
if has("unix") && executable("gnome-open") && !haskdeinit
@@ -44,12 +74,12 @@ function! OrderPizza() abort
4474
elseif has("unix") && executable("xdg-open")
4575
exe "silent !xdg-open ".args
4676
elseif has("win32") || has("win64")
47-
exe "silent !start explorer ".shellescape(g:pizza#url,1)
77+
exe "silent !start explorer ".shellescape(a:url,1)
4878
end
4979
redraw!
5080
endfunction
5181

52-
command! OrderPizza call OrderPizza()
82+
command! -nargs=* OrderPizza call OrderPizza(<q-args>)
5383

5484
nnoremap <silent> <Plug>(pizza#order) :call OrderPizza()<Return>
5585

0 commit comments

Comments
 (0)