Skip to content

Instantly share code, notes, and snippets.

@pielgrzym
Created July 19, 2012 15:23
Show Gist options
  • Save pielgrzym/3144644 to your computer and use it in GitHub Desktop.
Save pielgrzym/3144644 to your computer and use it in GitHub Desktop.
global !p
def fb(string, c=0):
'''Count brackets'''
left_bracket = string.find("(")
if left_bracket > -1:
string = string[left_bracket + 1:]
right_bracket = string.find(")")
if right_bracket > -1:
if string[:right_bracket].find("(") == -1:
c += 1
string = string[right_bracket + 1:]
return fb(string, c)
else:
return c
def check_regexp_for_params(snip, t):
if len(t[1]):
arg_count = fb(t[1])
if arg_count:
args = ", ".join( ["arg%d" % (x+1) for x in range(arg_count)] )
snip.rv = ', ' + args
endglobal
snippet st "Lettuce step decorated function" b
@step(r"${1}")
def ${2:step_name}(step${3:`!p check_regexp_for_params(snip, t)`}):
${4:pass}
endsnippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment