From ec2a0c7a9b95cb15a29b4ce6b7a4cab2f500ec23 Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Mon, 17 Aug 2015 15:23:19 -0700 Subject: [PATCH 1/6] Update python to use closest previous angular component --- UltiSnips/javascript/angular_js.snippets | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/UltiSnips/javascript/angular_js.snippets b/UltiSnips/javascript/angular_js.snippets index d6ce32e..03e50f4 100644 --- a/UltiSnips/javascript/angular_js.snippets +++ b/UltiSnips/javascript/angular_js.snippets @@ -8,10 +8,9 @@ component_re = re.compile('\.(?:controller|directive|service|factory|provider)\( DEFAULT_NAME = 'appName' DEFAULT_TYPE_NAME = 'type' DEFAULT_COMPONENT_NAME = 'componentName' -CHECK_LINES=20 def bufText(): - return '\n'.join(vim.current.window.buffer[:CHECK_LINES]) + return '\n'.join(vim.current.window.buffer[:vim.current.window.cursor[0]+1]) def get_ng_component_of(snip): text = bufText() @@ -25,7 +24,7 @@ def get_ng_type(snip, **kwargs): text = kwargs.get('text', bufText()) res = type_re.findall(text) if len(res) > 0: - snip.rv += res[0] + snip.rv += res[len(res)-1] else: snip.rv += DEFAULT_TYPE_NAME @@ -33,7 +32,7 @@ def get_ng_component(snip, **kwargs): text = kwargs.get('text', bufText()) res = component_re.findall(text) if len(res) > 0: - snip.rv += res[0] + snip.rv += res[len(res)-1] else: snip.rv += DEFAULT_COMPONENT_NAME @@ -41,7 +40,7 @@ def get_ng_module(snip, **kwargs): text = kwargs.get('text', bufText()) res = mod_re.findall(text) if len(res) > 0: - snip.rv += res[0] + snip.rv += res[len(res)-1] else: snip.rv += DEFAULT_NAME endglobal From df20ba509484d69ca9266ccf931b09bdbcef072c Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Thu, 20 Aug 2015 16:27:51 -0700 Subject: [PATCH 2/6] Update inline docs --- UltiSnips/javascript/angular_js.snippets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UltiSnips/javascript/angular_js.snippets b/UltiSnips/javascript/angular_js.snippets index 03e50f4..8cee284 100644 --- a/UltiSnips/javascript/angular_js.snippets +++ b/UltiSnips/javascript/angular_js.snippets @@ -240,7 +240,7 @@ snippet /s "NGDoc service" !b */ endsnippet -snippet /c "NGDoc service" !b +snippet /c "NGDoc controller" !b /** * @ngdoc controller * @name ${1:`!p get_ng_module(snip)`}.controller:${2:`!p get_ng_component(snip)`} From 44f1c307fb1701695afb8e62b0f904e4a8a0ad5b Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Wed, 2 Sep 2015 15:19:50 -0700 Subject: [PATCH 3/6] Add more testing snippets and a $q snippet --- UltiSnips/javascript/angular_js.snippets | 76 +++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/UltiSnips/javascript/angular_js.snippets b/UltiSnips/javascript/angular_js.snippets index 8cee284..40ffa56 100644 --- a/UltiSnips/javascript/angular_js.snippets +++ b/UltiSnips/javascript/angular_js.snippets @@ -1,6 +1,7 @@ global !p import uuid import re +import textwrap mod_re = re.compile('angular.module\(["\']*(.*?)["\'\),]') type_re = re.compile('\.(controller|directive|service|factory|provider|value)\(') @@ -43,6 +44,37 @@ def get_ng_module(snip, **kwargs): snip.rv += res[len(res)-1] else: snip.rv += DEFAULT_NAME + +def injector_phrase(v): + return '%s = $injector.get(\'%s\')' % (v, v) + +def trim_list(p): + while p[-1] in (',', ';'): p = p[:-1] + return '\n'.join(v for v in p.split('\n') + if len(v.strip()) > 0 + and v.strip() not in (',', ';') + and v[:2] != '//') + + +def set_injectors(var_list, pre=''): + var_list = trim_list(var_list) + if len(var_list) == 0: return '' + + phrase = textwrap.dedent( + ''' + beforeEach(inject(function($injector) { + %s + })); + ''') + + injectors = '\n\t'.join(injector_phrase(v) for v in var_list.split(', ')) + + phrase = phrase % (injectors,) + + if len(pre) > 0: + return ('\n' + pre).join(phrase.split('\n')) + + return phrase endglobal snippet ngc "Define a new Angular Controller. You can change the controller name and parameters." @@ -276,7 +308,7 @@ snippet /d "NGDoc directive" !b */ endsnippet -snippet */ex "Example comment" +snippet */ex "Example comment" * @example * * @@ -284,4 +316,46 @@ snippet */ex "Example comment" * endsnippet +snippet r$q "return $q(function ..." !b +return \$q(function(resolve, reject) { + ${1://asynchronously resolve()} +});$0 +endsnippet + +# TESTING snippets + +snippet inj "angular inject() function" !b +inject(function(${1:thingsToInject}) { + ${0://Do something with $1} +}); +endsnippet + +snippet $ig "$injector.get" !b +${1:something} = \$injector.get('${2:$1}'); +endsnippet + +snippet mod "" !b +beforeEach(module(function(${1:\$provide}) { + ${0:\$provide.service('TestThing', function(/*injected*/) { + this.foo = 'bar'; + \});} +})); +endsnippet + +snippet injg "Set a local variable via injection" !b +var ${1:injectable}; inject(function(_$1_) { $1 = _$1_; }); +endsnippet + +snippet test "karma angular test scaffold" !b +describe('${1:something to be tested}', function() { + //Setup + beforeEach(module('${2:someModule}')); + + var ${3://Injectables}`!p snip += set_injectors(t[3], '\t')` + + //Tests + $0 +}); +endsnippet + # vim:ft=snippets: From 50460475d34080ab8bf4f667186d4529160bf0b3 Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Tue, 8 Sep 2015 19:06:05 -0700 Subject: [PATCH 4/6] Update python function for smart test injection --- UltiSnips/javascript/angular_js.snippets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UltiSnips/javascript/angular_js.snippets b/UltiSnips/javascript/angular_js.snippets index 40ffa56..dd2f5ba 100644 --- a/UltiSnips/javascript/angular_js.snippets +++ b/UltiSnips/javascript/angular_js.snippets @@ -63,7 +63,7 @@ def set_injectors(var_list, pre=''): phrase = textwrap.dedent( ''' beforeEach(inject(function($injector) { - %s + %s })); ''') From 861515b1f4ba75b3f255a5b15bddd7eccd209d54 Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Thu, 10 Sep 2015 11:25:37 -0700 Subject: [PATCH 5/6] Add override for angular module name, documentation --- 2 | 358 +++++++++++++++++++++++ UltiSnips/javascript/angular_js.snippets | 51 ++-- readme.md | 10 + 3 files changed, 393 insertions(+), 26 deletions(-) create mode 100644 2 diff --git a/2 b/2 new file mode 100644 index 0000000..4f9f6e1 --- /dev/null +++ b/2 @@ -0,0 +1,358 @@ +global !p +import uuid +import re +import textwrap + +mod_re = re.compile('angular.module\(["\']*(.*?)["\'\),]') +type_re = re.compile('\.(controller|directive|service|factory|provider|value)\(') +component_re = re.compile('\.(?:controller|directive|service|factory|provider)\(["\'](.*?)["\']') +DEFAULT_NAME = 'appName' +DEFAULT_TYPE_NAME = 'type' +DEFAULT_COMPONENT_NAME = 'componentName' + +def bufText(): + return '\n'.join(vim.current.window.buffer[:vim.current.window.cursor[0]+1]) + +def get_ng_component_of(snip): + text = bufText() + get_ng_module(snip, text=text) + snip.rv += '.' + get_ng_type(snip, text=text) + snip.rv += ':' + get_ng_component(snip, text=text) + +def get_ng_type(text=bufText()): + res = type_re.findall(text) + if len(res) > 0: + snip.rv += res[len(res)-1] + else: + snip.rv += DEFAULT_TYPE_NAME + +def get_ng_component(text=bufText()): + res = component_re.findall(text) + if len(res) > 0: + snip.rv += res[len(res)-1] + else: + snip.rv += DEFAULT_COMPONENT_NAME + +def get_ng_module(text=bufText()): + res = mod_re.findall(text) + if len(res) > 0: + snip.rv += res[len(res)-1] + else: + snip.rv += DEFAULT_NAME + +def injector_phrase(v): + return '%s = $injector.get(\'%s\')' % (v, v) + +def trim_list(p): + while p[-1] in (',', ';'): p = p[:-1] + return '\n'.join(v for v in p.split('\n') + if len(v.strip()) > 0 + and v.strip() not in (',', ';') + and v[:2] != '//') + + +def set_injectors(var_list, pre=''): + var_list = trim_list(var_list) + if len(var_list) == 0: return '' + + phrase = textwrap.dedent( + ''' + beforeEach(inject(function($injector) { + %s + })); + ''') + + injectors = '\n\t'.join(injector_phrase(v) for v in var_list.split(', ')) + + phrase = phrase % (injectors,) + + if len(pre) > 0: + return ('\n' + pre).join(phrase.split('\n')) + + return phrase +endglobal + +snippet ngc "Define a new Angular Controller. You can change the controller name and parameters." +var ${1:controllerName} = function(${2:\$scope}, ${3:injectables}) { + $0 +}; +endsnippet + +snippet ngfor "angular.foreach loop" +angular.forEach(${1:iterateOver}, function(value, key) { + $0 +}); +endsnippet + + +snippet ngm "A new angular module without a config function." +angular.module('${1:moduleName}', [${2:moduleDependencies}]); +$0 +endsnippet + + +snippet ngma "A new angular module without a config function and a variable assignment." +var ${1:moduleName} = angular.module('$1$', [${2:moduleDeps}]); +$0 +endsnippet + + +snippet ngmc "A new angular module with a config function" +var ${1:moduleName} = angular.module('$1', [${2:moduleDeps}], function(${3:configDeps}) { + $0 +}); +endsnippet + + +snippet ngmfa "A factory in a module" +factory('${1:factoryName}', function(${2:dependencies}) { + $0 +}); +endsnippet + + +snippet ngms "Define an Angular Module Service to be attached to a previously defined module. You can change the service name and service injectables." +service('${1:serviceName}', function(${2:injectables}) { + $0 +}); +endsnippet + + +snippet ngmfi "Define an Angular Module Filter to be attached to a previously defined module. You can change the filter name." +filter('${1:filterName}', function(${2:injectables}) { + return function(input, ${3:args}) { + $0 + }; +}) +endsnippet + + + +# Route Based Snippets +snippet ngrw "Defines a when condition of an AngularJS route." +$routeProvider.when('${1:url}', { + templateUrl: '${2:templateUrl}', + controller: '${3:controller}' +}); +$0 +endsnippet + + + +snippet ngrwr "Defines a when condition of an AngularJS route with the resolve block." +$routeProvider.when('${1:url}', { + templateUrl: '${2:templateUrl}', + controller: '${3:controller}', + resolve: { + $4 + } +}); +$0 +endsnippet + + +snippet ngro "Defines an otherwise condition of an AngularJS route." +$routeProvider.otherwise({ + redirectTo: '${1:url}' +}); +$0 +endsnippet + + +# Scope Related Snippets +snippet $f "Define a new $scope'd function (usually inside an AngularJS Controller). You can change the function name and arguments." +$scope.${1:functionName} = function(${2:args}) { + $0 +}; +endsnippet + + +snippet $v "Defines a new $scope'd variable inside an AngularJS controller." +$scope.${1:variable} = ${2:value}; +$0 +endsnippet + + +snippet $va "Defines a new $scope'd variable inside an AngularJS controller and assigns a value from a constructor arguments." +$scope.${1:variable} = ${2:variable}; +$0 +endsnippet + + +snippet $w "Define a $watch for an expression. You can change the expression to be watched." +$scope.$watch('${1:watchExpr}',function(newValue, oldValue) { + $0 +}); +endsnippet + + +snippet $on "Define a $on for a $broadcast/$emit on the $scope inside an Angular Controller. You can change the event name to listen on." +$scope.$on('${1:eventName}', function(event, ${2:args}) { + $0 +}); +endsnippet + + +snippet $b "Define a $broadcast for a $scope inside an Angular Controller / Angular Controller Function. You can change the event name and optional event arguments." +$scope.$broadcast('${1:eventName}', ${2:eventArgs}); +$0 +endsnippet + + +snippet $e "Define an $emit for a $scope inside an Angular Controller / Angular Controller Function. You can change the event name and optional event arguments." +$scope.$emit('${1:eventName}', ${2:eventArgs}); +$0 +endsnippet + + +# Directive related snippets +snippet ngdcf "A compile function" +function compile(tElement, tAttrs, transclude) { + return function (scope, element, attrs) { + $0 + } +} +endsnippet + + +snippet ngdlf "A linking function in a directive." +function (scope, element, attrs${1:ctrl}) { + $0 +} +endsnippet + + +snippet ngdc "A directive with a compile function" +directive('${1:directiveName}', function factory(${2:injectables}) { + var directiveDefinitionObject = { + ${3:directiveAttrs}, + compile: function compile(tElement, tAttrs, transclude) { + return function (scope, element, attrs) { + $0 + } + } + }; + return directiveDefinitionObject; +}); +endsnippet + + +snippet ngdl "A directive with a linking function only." +.directive('${1:directiveName}', function(${2:directiveDeps}) { + return function(scope, element, attrs${3:ctrl}) { + $0 + } +}); +endsnippet + +snippet hget "$http.get" !b +$http.get('${1:/uri}'${3:, ${2:query}}) + .success(function(${4:collection}) { + ${5:$scope.$4 = $4;} + }) + .error(function(err) { + ${6:console.log(err);} + }) +endsnippet + +snippet $iget "Injector Get" !b +${1:variable} = $injector.get('${2:$1}'); +endsnippet + +snippet /s "NGDoc service" !b +/** + * @ngdoc service + * @name ${1:`!p get_ng_module(snip)`}.service:${2:`!p get_ng_component(snip)`} + * @description \`$2\` is a service ${0:to do $2} + */ +endsnippet + +snippet /c "NGDoc controller" !b +/** + * @ngdoc controller + * @name ${1:`!p get_ng_module(snip)`}.controller:${2:`!p get_ng_component(snip)`} + * @description \`$2\` is a controller ${0:to do $2} + */ +endsnippet + +snippet /m "NGDoc Method" !b +/** + * @ngdoc + * @methodOf ${1:`!p get_ng_component_of(snip)`} + * @name $1#${2:name} + * @description ${0:\`$2\` is a method to} + */ +endsnippet + +snippet /p "NGDoc Property" !b +/** + * @ngdoc + * @propertyOf ${1:`!p get_ng_component_of(snip)`} + * @name $1#${2:name} + * @description ${0:\`$2\` is a property for} + */ +endsnippet + +snippet /d "NGDoc directive" !b +/** + * @ngdoc directive + * @name ${1:`!p get_ng_module(snip)`.directive:`!p get_ng_component(snip)`} + * @param {${2: Type}} ${3: name} ${4: description} + * @description ${0:Description} + * @restrict ECA + */ +endsnippet + +snippet */ex "Example comment" +* @example +* +* +* +* +endsnippet + +snippet r$q "return $q(function ..." !b +return \$q(function(resolve, reject) { + ${1://asynchronously resolve()} +});$0 +endsnippet + +# TESTING snippets + +snippet inj "angular inject() function" !b +inject(function(${1:thingsToInject}) { + ${0://Do something with $1} +}); +endsnippet + +snippet $ig "$injector.get" !b +${1:something} = \$injector.get('${2:$1}'); +endsnippet + +snippet mod "" !b +beforeEach(module(function(${1:\$provide}) { + ${0:\$provide.service('TestThing', function(/*injected*/) { + this.foo = 'bar'; + \});} +})); +endsnippet + +snippet injg "Set a local variable via injection" !b +var ${1:injectable}; inject(function(_$1_) { $1 = _$1_; }); +endsnippet + +snippet test "karma angular test scaffold" !b +describe('${1:something to be tested}', function() { + //Setup + beforeEach(module('${2:someModule}')); + + var ${3://Injectables}`!p snip += set_injectors(t[3], '\t')` + + //Tests + $0 +}); +endsnippet + +# vim:ft=snippets: diff --git a/UltiSnips/javascript/angular_js.snippets b/UltiSnips/javascript/angular_js.snippets index dd2f5ba..f194924 100644 --- a/UltiSnips/javascript/angular_js.snippets +++ b/UltiSnips/javascript/angular_js.snippets @@ -13,37 +13,36 @@ DEFAULT_COMPONENT_NAME = 'componentName' def bufText(): return '\n'.join(vim.current.window.buffer[:vim.current.window.cursor[0]+1]) -def get_ng_component_of(snip): +def get_ng_component_of(): text = bufText() - get_ng_module(snip, text=text) - snip.rv += '.' - get_ng_type(snip, text=text) - snip.rv += ':' - get_ng_component(snip, text=text) - -def get_ng_type(snip, **kwargs): - text = kwargs.get('text', bufText()) + return "%s.%s:%s" % (get_ng_module(text), + get_ng_type(text), + get_ng_component(text)) + +def get_ng_type(text=bufText()): res = type_re.findall(text) if len(res) > 0: - snip.rv += res[len(res)-1] + return res[len(res)-1] else: - snip.rv += DEFAULT_TYPE_NAME + return DEFAULT_TYPE_NAME -def get_ng_component(snip, **kwargs): - text = kwargs.get('text', bufText()) +def get_ng_component(text=bufText()): res = component_re.findall(text) if len(res) > 0: - snip.rv += res[len(res)-1] + return res[len(res)-1] else: - snip.rv += DEFAULT_COMPONENT_NAME + return DEFAULT_COMPONENT_NAME + +def get_ng_module(text=bufText()): + explicit_name = vim.vars.get('ngdoc_module_name', None) + if explicit_name: + return explicit_name.decode('utf-8') -def get_ng_module(snip, **kwargs): - text = kwargs.get('text', bufText()) res = mod_re.findall(text) if len(res) > 0: - snip.rv += res[len(res)-1] + return res[len(res)-1] else: - snip.rv += DEFAULT_NAME + return DEFAULT_NAME def injector_phrase(v): return '%s = $injector.get(\'%s\')' % (v, v) @@ -52,7 +51,7 @@ def trim_list(p): while p[-1] in (',', ';'): p = p[:-1] return '\n'.join(v for v in p.split('\n') if len(v.strip()) > 0 - and v.strip() not in (',', ';') + and v.strip() not in (',', ';') and v[:2] != '//') @@ -67,7 +66,7 @@ def set_injectors(var_list, pre=''): })); ''') - injectors = '\n\t'.join(injector_phrase(v) for v in var_list.split(', ')) + injectors = ';\n\t'.join(injector_phrase(v) for v in var_list.split(', ')) phrase = phrase % (injectors,) @@ -267,7 +266,7 @@ endsnippet snippet /s "NGDoc service" !b /** * @ngdoc service - * @name ${1:`!p get_ng_module(snip)`}.service:${2:`!p get_ng_component(snip)`} + * @name ${1:`!p snip.rv += get_ng_module()`}.service:${2:`!p snip.rv += get_ng_component()`} * @description \`$2\` is a service ${0:to do $2} */ endsnippet @@ -275,7 +274,7 @@ endsnippet snippet /c "NGDoc controller" !b /** * @ngdoc controller - * @name ${1:`!p get_ng_module(snip)`}.controller:${2:`!p get_ng_component(snip)`} + * @name ${1:`!p snip.rv += get_ng_module()`}.controller:${2:`!p snip.rv += get_ng_component()`} * @description \`$2\` is a controller ${0:to do $2} */ endsnippet @@ -283,7 +282,7 @@ endsnippet snippet /m "NGDoc Method" !b /** * @ngdoc - * @methodOf ${1:`!p get_ng_component_of(snip)`} + * @methodOf ${1:`!p snip.rv += get_ng_component_of()`} * @name $1#${2:name} * @description ${0:\`$2\` is a method to} */ @@ -292,7 +291,7 @@ endsnippet snippet /p "NGDoc Property" !b /** * @ngdoc - * @propertyOf ${1:`!p get_ng_component_of(snip)`} + * @propertyOf ${1:`!p snip.rv += get_ng_component_of()`} * @name $1#${2:name} * @description ${0:\`$2\` is a property for} */ @@ -301,7 +300,7 @@ endsnippet snippet /d "NGDoc directive" !b /** * @ngdoc directive - * @name ${1:`!p get_ng_module(snip)`.directive:`!p get_ng_component(snip)`} + * @name ${1:`!p snip.rv += get_ng_module()`.directive:`!p snip.rv += get_ng_component()`} * @param {${2: Type}} ${3: name} ${4: description} * @description ${0:Description} * @restrict ECA diff --git a/readme.md b/readme.md index 59264e9..3cca576 100644 --- a/readme.md +++ b/readme.md @@ -14,6 +14,16 @@ This repository contains snippets files for [AngularJS](http://angularjs.org/) i - `git submodule add git@github.com:matthewsimo/angular-vim-snippets.git /path/you/want/it/` - add `./UltiSnip` to your list of `g:UltiSnipsSnippetDirectories` and you should be set +#### UltiSnip options + +For ngdoc snippets in ultisnips, the module name can be overwritten in case +you're using a variable or js expression for your module name. Add this to your +modeline or set as needed. +```vim +let g:angular_module_name='FooBar' "Replace with your module name, of course. +``` + + ### Snipmate - `git submodule add git@github.com:matthewsimo/angular-vim-snippets.git /path/you/want/it/` From b1ad6bb5172066f0cbebcd39a12470bd0a0299db Mon Sep 17 00:00:00 2001 From: Andrew Stuart Date: Thu, 10 Sep 2015 16:18:52 -0700 Subject: [PATCH 6/6] Remove "2" file created by accident --- 2 | 358 -------------------------------------------------------------- 1 file changed, 358 deletions(-) delete mode 100644 2 diff --git a/2 b/2 deleted file mode 100644 index 4f9f6e1..0000000 --- a/2 +++ /dev/null @@ -1,358 +0,0 @@ -global !p -import uuid -import re -import textwrap - -mod_re = re.compile('angular.module\(["\']*(.*?)["\'\),]') -type_re = re.compile('\.(controller|directive|service|factory|provider|value)\(') -component_re = re.compile('\.(?:controller|directive|service|factory|provider)\(["\'](.*?)["\']') -DEFAULT_NAME = 'appName' -DEFAULT_TYPE_NAME = 'type' -DEFAULT_COMPONENT_NAME = 'componentName' - -def bufText(): - return '\n'.join(vim.current.window.buffer[:vim.current.window.cursor[0]+1]) - -def get_ng_component_of(snip): - text = bufText() - get_ng_module(snip, text=text) - snip.rv += '.' - get_ng_type(snip, text=text) - snip.rv += ':' - get_ng_component(snip, text=text) - -def get_ng_type(text=bufText()): - res = type_re.findall(text) - if len(res) > 0: - snip.rv += res[len(res)-1] - else: - snip.rv += DEFAULT_TYPE_NAME - -def get_ng_component(text=bufText()): - res = component_re.findall(text) - if len(res) > 0: - snip.rv += res[len(res)-1] - else: - snip.rv += DEFAULT_COMPONENT_NAME - -def get_ng_module(text=bufText()): - res = mod_re.findall(text) - if len(res) > 0: - snip.rv += res[len(res)-1] - else: - snip.rv += DEFAULT_NAME - -def injector_phrase(v): - return '%s = $injector.get(\'%s\')' % (v, v) - -def trim_list(p): - while p[-1] in (',', ';'): p = p[:-1] - return '\n'.join(v for v in p.split('\n') - if len(v.strip()) > 0 - and v.strip() not in (',', ';') - and v[:2] != '//') - - -def set_injectors(var_list, pre=''): - var_list = trim_list(var_list) - if len(var_list) == 0: return '' - - phrase = textwrap.dedent( - ''' - beforeEach(inject(function($injector) { - %s - })); - ''') - - injectors = '\n\t'.join(injector_phrase(v) for v in var_list.split(', ')) - - phrase = phrase % (injectors,) - - if len(pre) > 0: - return ('\n' + pre).join(phrase.split('\n')) - - return phrase -endglobal - -snippet ngc "Define a new Angular Controller. You can change the controller name and parameters." -var ${1:controllerName} = function(${2:\$scope}, ${3:injectables}) { - $0 -}; -endsnippet - -snippet ngfor "angular.foreach loop" -angular.forEach(${1:iterateOver}, function(value, key) { - $0 -}); -endsnippet - - -snippet ngm "A new angular module without a config function." -angular.module('${1:moduleName}', [${2:moduleDependencies}]); -$0 -endsnippet - - -snippet ngma "A new angular module without a config function and a variable assignment." -var ${1:moduleName} = angular.module('$1$', [${2:moduleDeps}]); -$0 -endsnippet - - -snippet ngmc "A new angular module with a config function" -var ${1:moduleName} = angular.module('$1', [${2:moduleDeps}], function(${3:configDeps}) { - $0 -}); -endsnippet - - -snippet ngmfa "A factory in a module" -factory('${1:factoryName}', function(${2:dependencies}) { - $0 -}); -endsnippet - - -snippet ngms "Define an Angular Module Service to be attached to a previously defined module. You can change the service name and service injectables." -service('${1:serviceName}', function(${2:injectables}) { - $0 -}); -endsnippet - - -snippet ngmfi "Define an Angular Module Filter to be attached to a previously defined module. You can change the filter name." -filter('${1:filterName}', function(${2:injectables}) { - return function(input, ${3:args}) { - $0 - }; -}) -endsnippet - - - -# Route Based Snippets -snippet ngrw "Defines a when condition of an AngularJS route." -$routeProvider.when('${1:url}', { - templateUrl: '${2:templateUrl}', - controller: '${3:controller}' -}); -$0 -endsnippet - - - -snippet ngrwr "Defines a when condition of an AngularJS route with the resolve block." -$routeProvider.when('${1:url}', { - templateUrl: '${2:templateUrl}', - controller: '${3:controller}', - resolve: { - $4 - } -}); -$0 -endsnippet - - -snippet ngro "Defines an otherwise condition of an AngularJS route." -$routeProvider.otherwise({ - redirectTo: '${1:url}' -}); -$0 -endsnippet - - -# Scope Related Snippets -snippet $f "Define a new $scope'd function (usually inside an AngularJS Controller). You can change the function name and arguments." -$scope.${1:functionName} = function(${2:args}) { - $0 -}; -endsnippet - - -snippet $v "Defines a new $scope'd variable inside an AngularJS controller." -$scope.${1:variable} = ${2:value}; -$0 -endsnippet - - -snippet $va "Defines a new $scope'd variable inside an AngularJS controller and assigns a value from a constructor arguments." -$scope.${1:variable} = ${2:variable}; -$0 -endsnippet - - -snippet $w "Define a $watch for an expression. You can change the expression to be watched." -$scope.$watch('${1:watchExpr}',function(newValue, oldValue) { - $0 -}); -endsnippet - - -snippet $on "Define a $on for a $broadcast/$emit on the $scope inside an Angular Controller. You can change the event name to listen on." -$scope.$on('${1:eventName}', function(event, ${2:args}) { - $0 -}); -endsnippet - - -snippet $b "Define a $broadcast for a $scope inside an Angular Controller / Angular Controller Function. You can change the event name and optional event arguments." -$scope.$broadcast('${1:eventName}', ${2:eventArgs}); -$0 -endsnippet - - -snippet $e "Define an $emit for a $scope inside an Angular Controller / Angular Controller Function. You can change the event name and optional event arguments." -$scope.$emit('${1:eventName}', ${2:eventArgs}); -$0 -endsnippet - - -# Directive related snippets -snippet ngdcf "A compile function" -function compile(tElement, tAttrs, transclude) { - return function (scope, element, attrs) { - $0 - } -} -endsnippet - - -snippet ngdlf "A linking function in a directive." -function (scope, element, attrs${1:ctrl}) { - $0 -} -endsnippet - - -snippet ngdc "A directive with a compile function" -directive('${1:directiveName}', function factory(${2:injectables}) { - var directiveDefinitionObject = { - ${3:directiveAttrs}, - compile: function compile(tElement, tAttrs, transclude) { - return function (scope, element, attrs) { - $0 - } - } - }; - return directiveDefinitionObject; -}); -endsnippet - - -snippet ngdl "A directive with a linking function only." -.directive('${1:directiveName}', function(${2:directiveDeps}) { - return function(scope, element, attrs${3:ctrl}) { - $0 - } -}); -endsnippet - -snippet hget "$http.get" !b -$http.get('${1:/uri}'${3:, ${2:query}}) - .success(function(${4:collection}) { - ${5:$scope.$4 = $4;} - }) - .error(function(err) { - ${6:console.log(err);} - }) -endsnippet - -snippet $iget "Injector Get" !b -${1:variable} = $injector.get('${2:$1}'); -endsnippet - -snippet /s "NGDoc service" !b -/** - * @ngdoc service - * @name ${1:`!p get_ng_module(snip)`}.service:${2:`!p get_ng_component(snip)`} - * @description \`$2\` is a service ${0:to do $2} - */ -endsnippet - -snippet /c "NGDoc controller" !b -/** - * @ngdoc controller - * @name ${1:`!p get_ng_module(snip)`}.controller:${2:`!p get_ng_component(snip)`} - * @description \`$2\` is a controller ${0:to do $2} - */ -endsnippet - -snippet /m "NGDoc Method" !b -/** - * @ngdoc - * @methodOf ${1:`!p get_ng_component_of(snip)`} - * @name $1#${2:name} - * @description ${0:\`$2\` is a method to} - */ -endsnippet - -snippet /p "NGDoc Property" !b -/** - * @ngdoc - * @propertyOf ${1:`!p get_ng_component_of(snip)`} - * @name $1#${2:name} - * @description ${0:\`$2\` is a property for} - */ -endsnippet - -snippet /d "NGDoc directive" !b -/** - * @ngdoc directive - * @name ${1:`!p get_ng_module(snip)`.directive:`!p get_ng_component(snip)`} - * @param {${2: Type}} ${3: name} ${4: description} - * @description ${0:Description} - * @restrict ECA - */ -endsnippet - -snippet */ex "Example comment" -* @example -* -* -* -* -endsnippet - -snippet r$q "return $q(function ..." !b -return \$q(function(resolve, reject) { - ${1://asynchronously resolve()} -});$0 -endsnippet - -# TESTING snippets - -snippet inj "angular inject() function" !b -inject(function(${1:thingsToInject}) { - ${0://Do something with $1} -}); -endsnippet - -snippet $ig "$injector.get" !b -${1:something} = \$injector.get('${2:$1}'); -endsnippet - -snippet mod "" !b -beforeEach(module(function(${1:\$provide}) { - ${0:\$provide.service('TestThing', function(/*injected*/) { - this.foo = 'bar'; - \});} -})); -endsnippet - -snippet injg "Set a local variable via injection" !b -var ${1:injectable}; inject(function(_$1_) { $1 = _$1_; }); -endsnippet - -snippet test "karma angular test scaffold" !b -describe('${1:something to be tested}', function() { - //Setup - beforeEach(module('${2:someModule}')); - - var ${3://Injectables}`!p snip += set_injectors(t[3], '\t')` - - //Tests - $0 -}); -endsnippet - -# vim:ft=snippets: