Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -W
- # 10/5/13
- # script to covert a storyboard to a collection of xib files
- # NOTE: this is experimental and is not perfect!
- # 1) find each view ("<objects>" node) and its name
- # 2) write out each xib individually
- # - using previously-found name
- # - resizing; otherwise the xibs come out too wide/short
- use strict;
- my $inFile = shift;
- if(!$inFile) {
- die "Argument needed: path to storyboard file.\n";
- }
- open(INFILE, $inFile) or die "$!\n";
- my $sceneStarted = 0;
- my $sceneStr = '';
- my $xibBeginStr = qq^<?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
- <dependencies>
- <deployment defaultVersion="1280" identifier="iOS"/>
- <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3742"/>
- </dependencies>^;
- my $xibEndStr = "</document>";
- #we need to resize the items
- my $newSizeStr = qq^<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>^;
- my $sizeSeen = 0;
- my %scenes;
- my $currentIndex = 0;
- my $xibName = '';
- while(<INFILE>) {
- if(/<!--([\s\S]+)-->/) {
- print "Found scene '$1'\n";
- $xibName = $1;
- #remove spaces
- $xibName =~ s/\s//g;
- next;
- }
- if(/<objects>/) {
- #<scene sceneID="[\s\S]+">/i) {
- $sceneStarted = 1;
- $sceneStr = $_;
- }
- elsif(/<\/objects>/) {
- #<\/scene>/i) {
- $sceneStr .= $_;
- ##push(@scenes, $sceneStr);
- if(!$xibName) {
- print "WARNING: no name found for this xib\n";
- $xibName = "xib$currentIndex";
- $currentIndex++;
- }
- $scenes{$xibName} = $sceneStr;
- $sceneStr = '';
- $sceneStarted = 0;
- $xibName = '';
- $sizeSeen = 0;
- }
- elsif($sceneStarted) {
- #resize this view
- if(!$sizeSeen && /<rect/) {
- print "\treplacing '$_' with '$newSizeStr'\n";
- $_ = $newSizeStr;
- $sizeSeen = 1;
- }
- $sceneStr .= $_;
- }
- }
- close INFILE;
- my $count = scalar (keys %scenes);
- print "$count scenes found.";
- my $currentIndex = 1;
- my $xibName = '';
- foreach(keys %scenes) {
- $xibName = "$_.xib";
- #"$currentIndex.xib"
- print "Creating xib file $xibName\n";
- open (OUTFILE, ">$xibName") or die "Could not create $xibName. ($!)\n";
- my $_xibStr = $scenes{$_};
- my $xibStr = "$xibBeginStr\n$_xibStr$xibEndStr";
- print OUTFILE $xibStr;
- close OUTFILE;
- $currentIndex++;
- }
- print "DONE\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement