Created
August 19, 2015 21:36
-
-
Save smt/0c1dc82a4dfa9736003b to your computer and use it in GitHub Desktop.
Dynamic filename-based names in JS snippets (using UltiSnips)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the basename (of the file in which the snippet is invoked) as a sensible | |
# default for module names. Supports JSX files as well. | |
global !p | |
def module_name(name=None): | |
name = name or 'ModuleName' | |
s1 = re.sub('\.js(x?)$', '', name) | |
return ''.join(x.title() for x in re.sub('([A-Z])', r'_\1', s1).split('_')) | |
endglobal | |
# Usage: | |
# In file myCleverApp.js, expands to `module.exports = MyCleverApp;` | |
snippet me "module.exports" b | |
module.exports = ${1:`!p snip.rv = module_name(snip.basename)`};$0 | |
endsnippet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment