Skip to content

Commit

Permalink
added rename snippets skript
Browse files Browse the repository at this point in the history
  • Loading branch information
calimarkus committed Feb 15, 2013
1 parent 14e971b commit 7929410
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 41 deletions.
8 changes: 7 additions & 1 deletion .pre-commit.hook
Expand Up @@ -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

59 changes: 59 additions & 0 deletions .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."



80 changes: 40 additions & 40 deletions README.md
Expand Up @@ -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

Expand All @@ -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`
Expand All @@ -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;

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7929410

Please sign in to comment.