Skip to content

Instantly share code, notes, and snippets.

@rawaludin
Last active September 23, 2017 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rawaludin/cb9f1b251fce3a8075d0eefc67bd2c10 to your computer and use it in GitHub Desktop.
Save rawaludin/cb9f1b251fce3a8075d0eefc67bd2c10 to your computer and use it in GitHub Desktop.
function! ApiaryToPhp()
set ignorecase
set textwidth=80
" turn to $table->tipe..('field');(tipe..)...
execute "normal! dt`r'f`r'"
execute "normal! ldt(lyi("
execute "normal! 0i$table->\<ESC>pa(\<ESC>f';a);\<ESC>"
" save description as comment if type is lookup
" for easier setup relationship manually
let notLookup = ["string", "boolean", "number"]
execute "normal! 0f;f)yb"
let type = @"
" " delete rest of text
execute "normal! 0f;ld$"
if index(notLookup, type) == -1
" paste text, and reformat to 80 char limit
execute "normal! O// \<ESC>pv`[`]gqj"
endif
" add nullable if not required
execute "normal! 0f>lye"
let type = @"
if type == "required"
" delete required text
execute "normal! 0f>ldf\<space>\<ESC>"
else
" add ->nullable()
execute "normal! $i->nullable()\<ESC>"
endif
" change
" number => integer
" string => no change
" boolean => no change
" other string, and put comment
execute "normal! 0f>lye"
let type = @"
if type == "number"
execute "normal! 0f>lceinteger\<ESC>"
elseif type == "string"
execute "normal! 0"
elseif type == "boolean"
execute "normal! 0"
else
execute "normal! 0f>lcestring\<ESC>"
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment