Package: baler
Baler is a Python-based tool that makes it easy to bundle and use resources (images,
strings files, etc.) in an iOS static library.Thecard.ioandPayPal iOS SDKprojects use baler to include images and
other non-code assets in their SDK static libraries. Developers only
need to add the.hheaders and.aarchive, which includes all
resources.Baler isnota good way to handle assets in a regular consumer-facing
app!FeaturesPreserves all subdirectory structure (useful for localization via.lprojsubbundles)Optional transparent libz compression (good for text, not helpful for images
only).Resolution- and device-aware image loading very similar toUIImage's +imageNamed:.To see the full set of options, runbale-h.To use the generated code, look at the generated header file. It should
be documented and self-explanatory. If the help flag to the python
script or the header file is not sufficient documentation, pleasefile
an issue!The included Xcode project is not needed to use baler. It is useful for
developing baler itself, and for an example integration.RequirementsPython 2 >= 2.6 (pull requests to also support Python 3 welcomed)ARC, deployment target of iOS 6.0+, and Xcode 5+pipInstallationInstall with pip:pip install balerOr download and install from source:python setup.py installUsageBaler generates code. A python script (bale) accepts a directory of
assets and generates an Objective-C class that bundles those assets.Options are documented in the built-in help:bale -hExample invocation:bale resources/bundle_assets/,resources/strings Classes/ --overwrite-delay 0 -z -c BalerBundleThis would use the files inresources/bundle_assetsandresources/stringsto generate a bundle class written toClasses/BalerBundle.handClasses/BalerBundle.m, with
compression and no overwrite delay. Be sure to use a class
name more appropriate to your SDK than “BalerBundle”, to
avoid possible collisions with other SDKs using baler.Once the class files are generated, go ahead and add them to your project, then
in your code import the generated header:#import "MyBalerBundle.h"And then get and use your bundle normally:NSBundle *aBundle = [[PPZebraBundle sharedInstance] NSBundle]Or take advantage of theimageNamedmethod:UIImage *img = [[MyBalerBundle sharedInstance] imageNamed:@"baler-logo.jpg"];IntegrationYou can integrate baler into your build process in two ways:Manually, by running it whenever you alter your assets.Automatically, by integrating it into your Xcode build.Manual UseA quick way to get running is to manually invoke baler whenever you
change, add, delete, or move assets.Install baler as described above.Runbale <dir_containing_assets> <dir_for_output_code>.Add the output code to your project. Refer to the header file
(e.g.BalerBundle.h) for usage.If using compression, addlibz.dylibin the Link Binary With
Libraries build phase.Automated UseInstead of runningbalemanually each time you want to update the generated code, you can add abalestep into your Xcode project.Install baler as described above.Place the assets that you want to include in a subdirectory (e.g.baled_assets), usually alongside your.xcodeprojbundle. Optional: You can add this directory to your
Xcode project if you want, but be sure not add them to any targets.Create aRun Scriptbuild phase. In your project/target’s Build Phases tab – before the Compile Sources phase – add an appropriate invocation ofbale, e.g./path/to/python/env/bin/bale baled_assets Classes --overwrite-delay 0 -c BalerBundleThis will regenerate the bundle from the assets each time you build. See tips below for more further advice.Add the generated files (e.g.Classes/BalerBundle.[h|m]) to your Xcode project as usual. Refer to the header file (e.g.BalerBundle.h) for usage.If using compression, addlibz.dylibin the Link Binary With Libraries build phase.Optional: Add the generated classes’ self-tests to your unit tests.SetBALER_DEBUG=1in your test target settings, then use the bundle instance’spassesSelfTestmethod:NSError *bundleSelfTestError = nil;
BOOL pass = [[BalerBundle sharedInstance] passesSelfTest:&bundleSelfTestError];
STAssertTrue(pass, @"BalerBundle failed self-test with error %@", bundleSelfTestError);Run Script tipsSkip if baler isn’t set upYou can ensure the build progresses even if the baler invocation fails by having the shell command swallow the non-zero return code from baler, e.g./path/to/python/env/bin/bale baled_assets Classes --overwrite-delay 0 || echo "Failed to generate bundle"This keeps the coupling with baler a little looser, so other contributors won’t need baler to build the project.BYOB (Bring Your Own Baler)You may want to let your teammates specify which baler to use in a.gitignore’d shell script. For example, a.env:export PATH="/path/to/python/env/bin:$PATH"Then your Run Script would look like this:[ -f .env ] && source .env 2>/dev/null
bale ...ContributePull requests and new issues are welcome. SeeCONTRIBUTING.mdfor details.ThanksLogo imageThe baler logo is modified and shared with permission of Wikimedia Commons using the sameCreative Commons Attribution-Share Alike 3.0 Unported license.See also theoriginal image and license.ContributorsDave GoldmanRoman PunskkyJosh Bleecher SnyderBrent FitzgeraldBrought to you byPayPal.