Improvements to the puppet snippets by Nikola Petrov.
This commit is contained in:
parent
064dfac638
commit
b272949b51
@ -1,7 +1,46 @@
|
||||
# Snippets for Puppet
|
||||
|
||||
snippet /^class/ "Class declaration" r
|
||||
class ${1:name} {
|
||||
global !p
|
||||
import vim
|
||||
import os.path
|
||||
def get_module_namespace_and_basename():
|
||||
"""This function will try to guess the current class or define name you are
|
||||
trying to create. Note that for this to work you should be using the module
|
||||
structure as per the style guide. Examples inputs and it's output
|
||||
* /home/nikolavp/puppet/modules/collectd/manifests/init.pp -> collectd
|
||||
* /home/nikolavp/puppet/modules/collectd/manfistes/mysql.pp -> collectd::mysql
|
||||
"""
|
||||
current_file_path_without_ext = vim.eval('expand("%:p:r")') or ""
|
||||
if not current_file_path_without_ext:
|
||||
return "name"
|
||||
parts = os.path.split(current_file_path_without_ext)
|
||||
namespace = ''
|
||||
while parts[0] and parts[0] != '/':
|
||||
# Skip the init.pp files because they don't create a deeper namespace
|
||||
# and are special. Note this might break things like
|
||||
# modules/collectd/init/test.pp. But I am not even sure if puppet will
|
||||
# work for those.
|
||||
if parts[1] == 'init':
|
||||
parts = os.path.split(parts[0])
|
||||
continue
|
||||
if parts[1] == 'manifests':
|
||||
return os.path.split(parts[0])[1] + '::' + namespace.rstrip(':')
|
||||
else:
|
||||
namespace = parts[1] + '::' + namespace
|
||||
parts = os.path.split(parts[0])
|
||||
# couldn't guess the namespace. The user is editing a raw file in no module like the site.pp file
|
||||
return "name"
|
||||
endglobal
|
||||
|
||||
snippet define "Definition" b
|
||||
define ${1:`!p snip.rv = get_module_namespace_and_basename()`} {
|
||||
${0:# body}
|
||||
}
|
||||
|
||||
endsnippet
|
||||
|
||||
snippet class "Class declaration" b
|
||||
class ${1:`!p snip.rv = get_module_namespace_and_basename()`} {
|
||||
${0:# body}
|
||||
}
|
||||
endsnippet
|
||||
|
@ -1369,6 +1369,7 @@ Contributors listed in chronological order:
|
||||
Danilo Bargen (dbrgn)
|
||||
Bernhard Vallant (lazerscience)
|
||||
Von Welch (von)
|
||||
Nikola Petrov (nikolavp)
|
||||
|
||||
Thank you for your support.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user