Permalink
Browse files

Added a Perl script by Rudi Farkas to perform batch transformations o…

…f nib files in folders
  • Loading branch information...
1 parent 1a7c628 commit b50e853797edac2303c4e503e6d05232c65a3bae Adrian Kosmaczewski committed Dec 13, 2009
Showing with 112 additions and 2 deletions.
  1. +14 −2 LICENSE
  2. +4 −0 README.textile
  3. +94 −0 nibs2objc.pl
View
16 LICENSE
@@ -1,7 +1,19 @@
2009 March 16
-The author disclaims copyright to this source code. In place of a legal notice, here is a blessing:
+Adrian Kosmaczewski disclaims copyright to this source code. In place of a legal notice, here is a blessing:
May you do good and not evil.
May you find forgiveness for yourself and forgive others.
-May you share freely, never taking more than you give.
+May you share freely, never taking more than you give.
+
+
+---
+
+The nibs2objc.pl file has the following license:
+
+----------------------------------------------------------------------------
+"THE BEER-WARE LICENSE" (Revision 42):
+Rudi Farkas wrote this file. As long as you retain this notice you
+can do whatever you want with this stuff. If we meet some day, and you think
+this stuff is worth it, you can buy me a beer in return (Guiness if possible).
+----------------------------------------------------------------------------
View
@@ -46,3 +46,7 @@ h2. Limitations
* For the moment this utility only works for UIKit views (iPhone), but it should be easy to extend to those of the AppKit too.
* It cannot output the values of UIImage, NSLocale or NSTimeZone properties, because ibtool does not support them.
* It does not distinguishes default values for properties, and as such, it outputs all the information it can find about a particular instance.
+
+h3. Contributions
+
+This project includes the *nibs2objc.pl* Perl script by Rudi Farkas, which allows users to perform batch transformations of nib files in a folder. Thanks Rudi for the contribution!
View
@@ -0,0 +1,94 @@
+#!/usr/bin/perl
+
+# Rudi Farkas 12 Dec 2009
+
+# ----------------------------------------------------------------------------
+# "THE BEER-WARE LICENSE" (Revision 42):
+# Rudi Farkas wrote this file. As long as you retain this notice you
+# can do whatever you want with this stuff. If we meet some day, and you think
+# this stuff is worth it, you can buy me a beer in return (Guiness if possible).
+# ----------------------------------------------------------------------------
+
+
+# Searches the Xcode directory and its subdirectories xib files
+# for each file yyy.xib creates the corresponding yyy.txt file
+# which contains the output from akosma's utility nib2objc which uses ibtool
+
+# Also replaces variable names matching /view\w+/ by UI-type dependent variable names
+# for example "view25" => "tabBarItem25"
+
+# Requires Mac OSX utility nib2objc from http://github.com/akosma/nib2objc to be installed as /usr/local/bin/nib2objc
+
+# Version 1.1
+# Now using a hash %{$oldtonew} to manage multiple old to new substitutions
+
+
+
+my $usage = "$0 <directory>";
+
+use strict;
+use File::Find;
+use File::Slurp;
+
+my $dir = '';
+
+my $dir = shift || '';
+die "*** bad directory : '$dir'\nusage: $usage\n\n" unless -d $dir;
+
+my $nib2objc = "/usr/local/bin/nib2objc";
+
+my $nf = 0;
+
+File::Find::find( { wanted => \&wanted, no_chdir => 1 }, $dir);
+
+#print "$nf files seen\n";
+
+exit;
+
+
+sub wanted {
+ my $path = $File::Find::name;
+ return if -d $path;
+ ++$nf;
+ if ($path =~ /\.xib$/i) {
+ nib2objc($path);
+ }
+}
+
+sub nib2objc {
+ my $infilepath = shift;
+ my $outfilepath = $infilepath;
+ $outfilepath =~ s/\.xib$/.txt/i;
+ my @output = `$nib2objc $infilepath`;
+
+ printf "$infilepath : file seen (%d lines)\n", 0 + @output;
+
+ my $oldtonew = {}; # ref to empty hash
+ for (@output) {
+ # detect a UI var and create substitute
+ if (my ($uitype, $uivarsuffix) = $_ =~ /^UI(\w+) \*view(\d+) =/) {
+ my $newuivar = lcfirst $uitype;
+ $newuivar .= $uivarsuffix;
+ my $olduivar = "view$uivarsuffix";
+ printf " olduivar=%s => newuivar=%s\n", $olduivar, $newuivar;
+ $oldtonew->{$olduivar} = $newuivar;
+ }
+ # use substitutes created so far
+ for my $olduivar (keys %{$oldtonew}) {
+ my $newuivar = $oldtonew->{$olduivar};
+ if (s/\b$olduivar\b/$newuivar/g) {
+ #print;
+ }
+ }
+ }
+
+ if (write_file $outfilepath, @output) {
+ print "$outfilepath : file written\n";
+ }
+ else {
+ print "$outfilepath : failed to write\n";
+ }
+
+
+}
+

0 comments on commit b50e853

Please sign in to comment.