From 79294109ac5a48f2d7ae275b6d7bd9b7f7054b2b Mon Sep 17 00:00:00 2001 From: Markus Emrich Date: Sat, 16 Feb 2013 00:39:15 +0100 Subject: [PATCH] added rename snippets skript --- .pre-commit.hook | 8 +- .renameSnippets.py | 59 ++++++++++++++ README.md | 80 +++++++++---------- ...et => createAReusableTablecell.codesnippet | 0 ...desnippet => createAnImageview.codesnippet | 0 ...t => createAndShowAUialertview.codesnippet | 0 ...codesnippet => formattedString.codesnippet | 0 ...snippet => incrementingForLoop.codesnippet | 0 ...desnippet => initalizeAnObject.codesnippet | 0 ...=> keyValuePairForLocalization.codesnippet | 0 ...codesnippet => localizeAString.codesnippet | 0 ...mark.codesnippet => pragmaMark.codesnippet | 0 ...snippet => pushAViewcontroller.codesnippet | 0 ...et => setupAutoresizingOfAView.codesnippet | 0 14 files changed, 106 insertions(+), 41 deletions(-) create mode 100644 .renameSnippets.py rename dequeueTableCell.codesnippet => createAReusableTablecell.codesnippet (100%) rename imageView.codesnippet => createAnImageview.codesnippet (100%) rename presentAlertView.codesnippet => createAndShowAUialertview.codesnippet (100%) rename stringWithFormat.codesnippet => formattedString.codesnippet (100%) rename fori-loop.codesnippet => incrementingForLoop.codesnippet (100%) rename allocInit.codesnippet => initalizeAnObject.codesnippet (100%) rename Localizable-keyValue.codesnippet => keyValuePairForLocalization.codesnippet (100%) rename NSLocalizedString.codesnippet => localizeAString.codesnippet (100%) rename pragma-mark.codesnippet => pragmaMark.codesnippet (100%) rename pushController.codesnippet => pushAViewcontroller.codesnippet (100%) rename autoresizingMask.codesnippet => setupAutoresizingOfAView.codesnippet (100%) diff --git a/.pre-commit.hook b/.pre-commit.hook index 9942850..0801c42 100755 --- a/.pre-commit.hook +++ b/.pre-commit.hook @@ -4,6 +4,12 @@ # this will update the readme.md # +# rename snippets +python .renameSnippets.py + +# generate description python .generateDescription.py -git add README.md + +# stage updates files +git add -A diff --git a/.renameSnippets.py b/.renameSnippets.py new file mode 100644 index 0000000..99ad5e4 --- /dev/null +++ b/.renameSnippets.py @@ -0,0 +1,59 @@ +from xml.dom import minidom +import os +import glob +import re + +# define first character lowercase function +first_lower = lambda s: s[:1].lower() + s[1:] if s else '' + +print "Updating codesnippet filenames with their actual titles" + +count = 0 +listing = os.listdir(".") +for fileName in listing: + + # ignore other files than snippets + if not fileName.endswith(".codesnippet"): + continue + + # parse snippet file + xmldoc = minidom.parse(fileName) + keyslist = xmldoc.getElementsByTagName('key') + allChilds = xmldoc.getElementsByTagName('dict')[0].childNodes + + for x in allChilds: + if not x.firstChild: + allChilds.remove(x) + + snippetTitle = None + + # find title + for key in keyslist: + value = key.firstChild.nodeValue + if value == "IDECodeSnippetTitle": + snippetTitle = allChilds[allChilds.index(key)+1].firstChild.nodeValue + + # if snippet has a title + if not snippetTitle == None: + + # build filename (only a-zA-Z) + snippetTitle = snippetTitle.replace("&","and") + allWords = re.findall("[a-zA-Z]+", snippetTitle) + uppercaseWords = map(lambda x: x.title(), allWords) + newName = "".join(uppercaseWords) + ".codesnippet" + newName = first_lower(newName) + + # if name changed, rename file + if not newName == fileName: + os.rename(fileName, newName) + count = count + 1 + + # log renamed files + print " renamed: " + fileName + " -> " + print " " + newName + +# show total count +print str(count) + " snippets renamed." + + + diff --git a/README.md b/README.md index b45ab21..7ed293b 100644 --- a/README.md +++ b/README.md @@ -17,19 +17,24 @@ To run this script automatically before each commit, install the pre-commit hook ## Snippet Descriptions -**allocInit.codesnippet** (Initalize an object) -Shortcut: `alloc` -creates a new object from a given class +**createAndShowAUialertview.codesnippet** (Create & show a UIAlertView) +Shortcut: `alertview` +Shows a newly created alertview - <#ClassName#> *<#variableName#> = [[<#ClassName#> alloc] init]; + UIAlertView* alertView = [[UIAlertView alloc] initWithTitle: <#title#> + message: <#message#> + delegate: <#self#> + cancelButtonTitle: <#nil#> + otherButtonTitles: <#@"OK"#>, nil]; + [alertView show]; -**autoresizingMask.codesnippet** (Setup autoresizing of a view) -Shortcut: `autoresizing` -Set the autoresizing flags of a view +**createAnImageview.codesnippet** (Create an imageView) +Shortcut: `iv` +Inits a new imageView with an image via imageNamed. - <#view#>.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"<#imageName#>"]] -**dequeueTableCell.codesnippet** (Create a reusable TableCell) +**createAReusableTablecell.codesnippet** (Create a reusable TableCell) Shortcut: `tablecell` Initialises / deques a new cell from the tableview using an identifier @@ -42,19 +47,11 @@ Initialises / deques a new cell from the tableview using an identifier return cell; -**fori-loop.codesnippet** (Incrementing For Loop) -Shortcut: `fori` -A For loop incrementing a local variable - - for (NSInteger i=0; i<<#count#>; i++) { - <#statements#> - } - -**imageView.codesnippet** (Create an imageView) -Shortcut: `iv` -Inits a new imageView with an image via imageNamed. +**formattedString.codesnippet** (Formatted String) +Shortcut: `format` +Shortcut for a formatted string - [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"<#imageName#>"]] + [NSString stringWithFormat: @"<#string#>", <#param1#>] **importFramework.codesnippet** (Import Framework) Shortcut: `imp2` @@ -68,45 +65,48 @@ Import a header #import "<#header#>" -**Localizable-keyValue.codesnippet** (Key-Value Pair for Localization) +**incrementingForLoop.codesnippet** (Incrementing For Loop) +Shortcut: `fori` +A For loop incrementing a local variable + + for (NSInteger i=0; i<<#count#>; i++) { + <#statements#> + } + +**initalizeAnObject.codesnippet** (Initalize an object) +Shortcut: `alloc` +creates a new object from a given class + + <#ClassName#> *<#variableName#> = [[<#ClassName#> alloc] init]; + +**keyValuePairForLocalization.codesnippet** (Key-Value Pair for Localization) Shortcut: `key` A localization key and its value "<#keyName#>" = "<#value#>"; -**NSLocalizedString.codesnippet** (Localize a string) +**localizeAString.codesnippet** (Localize a string) Shortcut: `loca` Localizes a string from a given key NSLocalizedString(@"<#keyName#>", nil) -**pragma-mark.codesnippet** (Pragma mark) +**pragmaMark.codesnippet** (Pragma mark) Shortcut: `pragma` Add a new pragma mark #pragma mark <#comment#> -**presentAlertView.codesnippet** (Create & show a UIAlertView) -Shortcut: `alertview` -Shows a newly created alertview - - UIAlertView* alertView = [[UIAlertView alloc] initWithTitle: <#title#> - message: <#message#> - delegate: <#self#> - cancelButtonTitle: <#nil#> - otherButtonTitles: <#@"OK"#>, nil]; - [alertView show]; - -**pushController.codesnippet** (Push a ViewController) +**pushAViewcontroller.codesnippet** (Push a ViewController) Shortcut: `push` Pushes a newly created ViewController on the current NavigationController <#UIViewController#>* viewController = [[<#UIViewController#> alloc] init]; [self.navigationController pushViewController:viewController animated:YES]; -**stringWithFormat.codesnippet** (Formatted String) -Shortcut: `format` -Shortcut for a formatted string +**setupAutoresizingOfAView.codesnippet** (Setup autoresizing of a view) +Shortcut: `autoresizing` +Set the autoresizing flags of a view - [NSString stringWithFormat: @"<#string#>", <#param1#>] + <#view#>.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; diff --git a/dequeueTableCell.codesnippet b/createAReusableTablecell.codesnippet similarity index 100% rename from dequeueTableCell.codesnippet rename to createAReusableTablecell.codesnippet diff --git a/imageView.codesnippet b/createAnImageview.codesnippet similarity index 100% rename from imageView.codesnippet rename to createAnImageview.codesnippet diff --git a/presentAlertView.codesnippet b/createAndShowAUialertview.codesnippet similarity index 100% rename from presentAlertView.codesnippet rename to createAndShowAUialertview.codesnippet diff --git a/stringWithFormat.codesnippet b/formattedString.codesnippet similarity index 100% rename from stringWithFormat.codesnippet rename to formattedString.codesnippet diff --git a/fori-loop.codesnippet b/incrementingForLoop.codesnippet similarity index 100% rename from fori-loop.codesnippet rename to incrementingForLoop.codesnippet diff --git a/allocInit.codesnippet b/initalizeAnObject.codesnippet similarity index 100% rename from allocInit.codesnippet rename to initalizeAnObject.codesnippet diff --git a/Localizable-keyValue.codesnippet b/keyValuePairForLocalization.codesnippet similarity index 100% rename from Localizable-keyValue.codesnippet rename to keyValuePairForLocalization.codesnippet diff --git a/NSLocalizedString.codesnippet b/localizeAString.codesnippet similarity index 100% rename from NSLocalizedString.codesnippet rename to localizeAString.codesnippet diff --git a/pragma-mark.codesnippet b/pragmaMark.codesnippet similarity index 100% rename from pragma-mark.codesnippet rename to pragmaMark.codesnippet diff --git a/pushController.codesnippet b/pushAViewcontroller.codesnippet similarity index 100% rename from pushController.codesnippet rename to pushAViewcontroller.codesnippet diff --git a/autoresizingMask.codesnippet b/setupAutoresizingOfAView.codesnippet similarity index 100% rename from autoresizingMask.codesnippet rename to setupAutoresizingOfAView.codesnippet