Permalink
Browse files

Use symbols instead of strings, use array.zip, exit with correct exit…

… code
  • Loading branch information...
1 parent 57833ba commit fa489b049053f73a5811a9af462c92909ebeb10c @BaseInfinity BaseInfinity committed Feb 22, 2013
Showing with 36 additions and 35 deletions.
  1. +36 −35 easyAppOven.rb
View
@@ -3,7 +3,7 @@
#####
# This script will create the code needed when someone comes to us and asks for
# a custom iOS app. We still need to make sure image assets are in the correct
-# folder and all images are named accordingly. This script takes about 95% of
+# folder and all images are named accordingly.
#
# How it works: We have comments within the iOS app that the script will use as
# markers, to know where to place new addition of code. It essentially uses
@@ -37,34 +37,34 @@
####
# Each dictionary in the recipe's array is a 'clump' of code changes
-# 'file' == Path to Class file
-# 'pattern' == Marker we use to search for, ie: /*EAOConfig*/
-# 'ingredient' == Code to replace found pattern
+# :file == Path to Class file
+# :pattern == Marker we use to search for, ie: /*EAOConfig*/
+# :ingredient == Code to replace found pattern
#
-# Important: If you have a file that needs multiple 'pattern'(s) that will
+# Important: If you have a file that needs multiple :pattern(s) that will
# perform multiple replacements, use an array, with the corresponding
# string replacement stored in an array in 'ingredients'.
####
recipes = [
# Add logo title image, along with resizing logic for portrait/landscape
- { 'file' => 'Classes/Config.h',
- 'pattern' => /\/\*EAOConfig\*\//,
- 'ingredient' => "#{configName},\n" + "\s" * 4 + "/*EAOConfig*/" },
+ { :file => 'Classes/Config.h',
+ :pattern => /\/\*EAOConfig\*\//,
+ :ingredient => "#{configName},\n" + "\s" * 4 + "/*EAOConfig*/" },
# Add header logo image for iPads when viewing Guide Intro
- { 'file' => 'Classes/GuideIntroViewController.m',
- 'pattern' => /\/\*EAOGuideIntro\*\//,
- 'ingredient' => "case #{configName}:\n" +
+ { :file => 'Classes/GuideIntroViewController.m',
+ :pattern => /\/\*EAOGuideIntro\*\//,
+ :ingredient => "case #{configName}:\n" +
"\t" * 4 + "image = [UIImage imageNamed:@\"logo_#{nanoSite}.png\"];\n" +
"\t" * 4 + "headerImageLogo.frame = CGRectMake(headerImageLogo.frame.origin.x, headerImageLogo.frame.origin.y, image.size.width, image.size.height);\n" +
"\t" * 4 + "headerImageLogo.image = image;\n" +
"\t" * 4 + "[image release];\n" +
"\t" * 4 + "break;\n\t" + "\t" * 2 + "/*EAOGuideIntro*/" },
# Add config settings such as base url and other options
- { 'file' => 'Classes/Config.m',
- 'pattern' => /\/\*EAOOptions\*\//,
- 'ingredient' => "case #{configName}:\n" +
+ { :file => 'Classes/Config.m',
+ :pattern => /\/\*EAOOptions\*\//,
+ :ingredient => "case #{configName}:\n" +
"\t" * 3 + "self.host = @\"#{nanoSite}.dozuki.com\";\n" +
"\t" * 3 + "self.baseURL = @\"http://#{nanoSite}.dozuki.com\";\n" +
"\t" * 3 + "answersEnabled = NO;\n" +
@@ -73,9 +73,9 @@
"\t" * 3 + "break;\n" + "\t" * 2 + "/*EAOOptions*/" },
# Add title image logo and resizing logic for title image logo
- { 'file' => 'Classes/CategoriesViewController.m',
- 'pattern' => [ /\/\*EAOTitle\*\//, /\/\*EAOLandscapeResize\*\//, /\/\*EAOPortraitResize\*\// ],
- 'ingredient' => [ "case #{configName}:\n" +
+ { :file => 'Classes/CategoriesViewController.m',
+ :pattern => [ /\/\*EAOTitle\*\//, /\/\*EAOLandscapeResize\*\//, /\/\*EAOPortraitResize\*\// ],
+ :ingredient => [ "case #{configName}:\n" +
"\t" * 4 + "titleImage = [UIImage imageNamed:@\"titleImage#{nanoSite.capitalize}.png\"];\n" +
"\t" * 4 + "imageTitle = [[UIImageView alloc] initWithImage:titleImage];\n" +
"\t" * 4 + "self.navigationItem.titleView = imageTitle;\n" +
@@ -96,9 +96,9 @@
"break;\n" + "\t" * 3 + "/*EAOPortraitResize*/" ] },
# Add large background iPad logo and resizing logic for logo
- { 'file' => 'Classes/DetailIntroViewController.m',
- 'pattern' => [ /\/\*EAOLandscape\*\//, /\/\*EAOPortrait\*\//, /\/\*EAOiPadLogo\*\// ],
- 'ingredient' => [ "case #{configName}:\n" +
+ { :file => 'Classes/DetailIntroViewController.m',
+ :pattern => [ /\/\*EAOLandscape\*\//, /\/\*EAOPortrait\*\//, /\/\*EAOiPadLogo\*\// ],
+ :ingredient => [ "case #{configName}:\n" +
"\t" * 4 + "frame.origin.y = 0.0;\n" +
"\t" * 4 + "frame.origin.x = 0.0;\n" +
"\t" * 4 + "break;\n\t" + "\t" * 2 + "/*EAOLandscape*/",
@@ -114,9 +114,9 @@
"\t" * 3 + "break;\n" + "\t" * 2 + "/*EAOiPadLogo*/" ] },
# Add code to our bash script that switches between iOS apps
- { 'file' => 'dozuki.sh',
- 'pattern' => /#EAOPlist/,
- 'ingredient' => "elif [ \"$1\" == \"#{nanoSite}\" ]; then\n" +
+ { :file => 'dozuki.sh',
+ :pattern => /#EAOPlist/,
+ :ingredient => "elif [ \"$1\" == \"#{nanoSite}\" ]; then\n" +
"\s" * 3 + "echo \"#{nanoSite.capitalize}\"\n" +
"\s" * 3 + "cp Graphics/Sites/#{nanoSite.capitalize}/*png .\n" +
"\s" * 3 + "sed -i '.bak' -e 's/com.ifixit.ifixit/com.dozuki.#{nanoSite}/g' iFixit-Info.plist\n" +
@@ -128,27 +128,28 @@
####
# Search for the correct place to insert new code.
-# recipe['file'] => Pointing to path of file to search through
-# recipe['pattern'] => Regex Pattern to search for to insert new code
-# recipe['ingredient'] => New code to insert
+# recipe[:file] => Pointing to path of file to search through
+# recipe[:pattern] => Regex Pattern to search for to insert new code
+# recipe[:ingredient] => New code to insert
####
def bakeRecipe(recipe)
- if File.file?(recipe['file'])
- fileContents = File.read(recipe['file'])
+ if File.file?(recipe[:file])
+ fileContents = File.read(recipe[:file])
# If pattern is an array, we have multiple inserts to do
- if recipe['pattern'].is_a? Array
- for i in 0..(recipe['pattern'].count - 1)
- fileContents.sub!(recipe['pattern'][i], recipe['ingredient'][i])
+ if recipe[:pattern].is_a? Array
+ # Zip: [[pattern1, ingredient1], [pattern2, ingredient2]]
+ recipe[:pattern].zip(recipe[:ingredient]).each do |recipeArray|
+ fileContents.sub!(recipeArray[0], recipeArray[1])
end
else
- fileContents.sub!(recipe['pattern'], recipe['ingredient'])
+ fileContents.sub!(recipe[:pattern], recipe[:ingredient])
end
- File.write(recipe['file'], fileContents)
+ File.write(recipe[:file], fileContents)
else
- puts "Could not find file: #{recipe['file']}, unplug the oven!"
- exit
+ puts "Could not find file: #{recipe[:file]}, unplug the oven!"
+ exit 1
end
end

0 comments on commit fa489b0

Please sign in to comment.