transender 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 0
3
2
  :minor: 2
4
- :patch: 4
3
+ :patch: 5
4
+ :major: 0
@@ -0,0 +1,30 @@
1
+ # a transender bowl
2
+ # defines how transender should transform a MakeMoney cloned iPhone/iPod touch app into another
3
+
4
+ app:
5
+ APP_SERVER_URL: http://kitschmaster.com
6
+ APP_TITLE: moonpreview
7
+ APP_ID: 16
8
+ PRICE: 0.99
9
+ IRS: 0.7
10
+ PRAYER: Serve.
11
+ MANTRA: Make Money.
12
+
13
+ store:
14
+ SKU_NUMBER: Your SKUNUMBER for this app
15
+ DESCRIPTION:
16
+ Your text for app store submit.
17
+ Can have 700 chars.
18
+
19
+ #list the files you want to keep, all else will be deleted
20
+ #if you do not list any files, no files will be deleted
21
+ files:
22
+ Controllers:
23
+ #- MessageViewController
24
+ #- KopterViewController
25
+ Filters:
26
+ #- Filter_twitter
27
+ #- Filter_koornk
28
+ Views:
29
+ #- MessageView
30
+ #- KopterView
data/lib/transender.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'fileutils'
2
- require 'ftools'
3
2
  require 'yaml'
4
3
 
5
4
  module Transender
@@ -63,38 +62,133 @@ module Transender
63
62
  out_file
64
63
  end
65
64
 
66
- def self.extract_app_title(giturl)
67
- giturl.split('/').last.split('.').first
65
+ def self.extract_name(url)
66
+ url.split('/').last.split('.').first
68
67
  end
69
68
 
70
69
  #Transender - Ji
71
70
  class Ji
72
- attr_accessor :options, :app_title, :app_path, :transform, :transform_title, :ji_path, :id
71
+ attr_accessor :options, :app_title, :app_path, :transform, :transform_title, :ji_path, :abowl_path, :abowl_yml, :id
73
72
 
74
73
  # Supply a Hash of options containing:
75
74
  # options[:app_title]:: your fresh apps title
76
75
  # options[:transform]:: git repository of the base project - app_title becomes a clone of it
77
76
  # options[:ji_path]:: output dir
78
77
  def initialize(options)
79
- raise ArgumentError unless options.class == Hash && options[:app_title] && options[:transform] && options[:ji_path]
78
+ raise ArgumentError unless options.class == Hash && options[:app_title] && options[:transform] #&& options[:ji_path]
80
79
  @options = options
80
+ @ji_path = @options[:ji_path] || Dir.getwd
81
+ @ji_path = Dir.getwd if @ji_path.empty?
82
+ puts "Ji path is: #{@ji_path}"
83
+ unless File.exists? @ji_path
84
+ begin
85
+ FileUtils.mkdir @ji_path
86
+ rescue
87
+ puts "Output path could not be created."
88
+ raise ArgumentError
89
+ end
90
+ end
81
91
  @app_title = @options[:app_title]
82
- @transform = @options[:transform]
83
- @transform_title = Transender.extract_app_title(@transform)
84
- @ji_path = @options[:ji_path]
85
92
  @app_path = File.join(@ji_path, @app_title)
86
- @id = Time.now.strftime("%Y-%m-%d-%s")
93
+ @abowl_path = File.join(@ji_path, "abowl")
94
+ @abowl_yml = File.join(@abowl_path, "abowl.yml")
95
+ @transform = @options[:transform]
96
+ @transform_title = Transender.extract_name(@transform)
97
+ @id = Time.now.strftime("%Y-%m-%d-%s")
98
+ end
99
+
100
+ #read abowl, transend that information into existing project
101
+ #deleting, copying files in this proces
102
+ def transend
103
+ if read_abowl
104
+
105
+ # handle artwork if any
106
+ files = Dir["#{abowl_path}/Artwork/*"]
107
+ if files&&files.size>0
108
+ #remove original artwork
109
+ FileUtils.rm_rf "#{app_path}/Artwork"
110
+ #copy this bowls artworks
111
+ FileUtils.cp_r "#{abowl_path}/Artwork", "#{app_path}/"
112
+ end
113
+
114
+ # handle transends if any
115
+ files = Dir["#{abowl_path}/Transends/*"]
116
+ if files&&files.size>0
117
+ #remove original transends
118
+ FileUtils.rm_rf "#{app_path}/Transends"
119
+ #copy this bowls transends
120
+ FileUtils.cp_r "#{abowl_path}/Transends", "#{app_path}/"
121
+ end
122
+
123
+ # handle files
124
+ ['Controllers', 'Filters'].each do |type|
125
+ filenames = @abowl['files'][type]
126
+ if filenames&&filenames.size>0
127
+ Dir["#{app_path}/Classes/#{type}/*.{m,h}"].each do |file|
128
+ name = Transender.extract_name(file)
129
+ FileUtils.rm file unless filenames.member? name
130
+ end
131
+ end
132
+ end
133
+ filenames = @abowl['files']['Views']
134
+ if filenames&&filenames.size>0
135
+ Dir["#{app_path}/Views/*.{xib, nib}"].each do |file|
136
+ name = Transender.extract_name(file)
137
+ FileUtils.rm file unless filenames.member? name
138
+ end
139
+ end
140
+
141
+ #handle app delegate defines
142
+ defines = @abowl['app']
143
+ appDelegate = "#{app_path}/Classes/Application/#{app_title}AppDelegate.h"
144
+ appDelegate_temp = "#{app_path}/Classes/Application/#{app_title}AppDelegate.h.temp"
145
+ File.open(appDelegate_temp, "w") do |outfile|
146
+ File.open(appDelegate, "r") do |infile|
147
+ while (line = infile.gets)
148
+ if line =~ /#define/
149
+ key = line.split[1]
150
+ if defines.has_key? key
151
+ value = defines[key]
152
+ if value.to_s =~ /^(\d)*\.(\d)*$/ #is numerical
153
+ outfile << (line.gsub /^#define #{key} .*$/, "#define #{key} #{value}")
154
+ puts "#define #{key} #{value}"
155
+ else
156
+ outfile << (line.gsub /^#define #{key} .*$/, "#define #{key} @\"#{value}\"")
157
+ puts "#define #{key} #{value}"
158
+ end
159
+ end
160
+ else
161
+ outfile << line
162
+ end
163
+ end
164
+ end
165
+ end
166
+ FileUtils.mv appDelegate_temp, appDelegate
167
+
168
+ puts "Transended #{@abowl['app']['APP_TITLE']}."
169
+
170
+ else #try to make a bowl then
171
+ make_abowl
172
+ end
87
173
  end
88
174
 
89
175
  #clones from transform then removes git
90
176
  def clone_and_remove_git
91
177
  #prepare destination without any warning
92
- `rm -rf #{@app_path}`
93
- #clone that git repo and rename at the same time, use --work-tree, otherwise rake spec fails miserably
94
- `git --work-tree=#{@app_path} clone --no-hardlinks #{@transform} #{@app_path}`
178
+ FileUtils.rm_rf @app_path #`rm -rf #{@app_path}`
179
+
180
+ if Object.const_defined? 'RSPEC'
181
+ #todo
182
+ #this does not create a .git inside the cloned project
183
+ `git --work-tree=#{@app_path} --git-dir=#{@app_path}/.git clone --no-hardlinks #{@transform} #{@app_path}`
184
+ else
185
+ `git clone --no-hardlinks #{@transform} #{@app_path}`
186
+ end
187
+
95
188
  #remove any past life remains from the fresh project
96
- `rm -rf #{File.join(@app_path, 'build')}`
97
- `rm -rf #{File.join(@app_path, '.git')}`
189
+ FileUtils.rm_rf File.join(@app_path, 'build') #`rm -rf #{File.join(@app_path, 'build')}`
190
+ FileUtils.rm_rf File.join(@app_path, '.git') #`rm -rf #{File.join(@app_path, '.git')}`
191
+
98
192
  puts "Cloned from #{@transform} into #{@app_path}."
99
193
  end
100
194
 
@@ -115,8 +209,12 @@ module Transender
115
209
 
116
210
  def zip
117
211
  z = File.join(ji_path, "#{app_title}.zip")
118
- `rm -rf #{z}` #remove any previous zips without any warnings
212
+ FileUtils.rm_rf z #`rm -rf #{z}` #remove any previous zips without any warnings
213
+
214
+ #cd into and zip
119
215
  `cd #{ji_path}; tar cvfz #{app_title}.zip #{app_title}/`
216
+
217
+ #return path to zip
120
218
  puts "Zipped #{app_title} into #{z}" if File.exists?(z)
121
219
  z
122
220
  end
@@ -127,12 +225,34 @@ module Transender
127
225
  zip
128
226
  end
129
227
 
228
+ def transendize
229
+ clone_and_remove_git
230
+ rename
231
+ transend
232
+ zip
233
+ end
234
+
130
235
  #Use maybe like this: Transender::Ji.transform_and_zip(ahash) {|zip| render :text => zip}
131
236
  def self.transform_and_zip(t={}, &block)
132
237
  zip = Ji.new(t).transformize
133
238
  yield zip if block
134
239
  end
135
240
 
241
+ #Use maybe like this: Transender::Ji.transend_and_zip(ahash) {|zip| render :text => zip}
242
+ def self.transend_and_zip(t={}, &block)
243
+ zip = Ji.new(t).transendize
244
+ yield zip if block
245
+ end
246
+
247
+ #Transender::Ji.transend
248
+ #if there is abowl, it will be used for transending
249
+ def self.transend(t={})
250
+ ji = Ji.new(t)
251
+ ji.clone_and_remove_git
252
+ ji.rename
253
+ ji.transend
254
+ end
255
+
136
256
  private
137
257
 
138
258
  def rename_files
@@ -142,7 +262,7 @@ module Transender
142
262
  FileUtils.mv filename, filename.gsub(/#{transform_title}/, app_title)
143
263
  end
144
264
  end
145
- Dir["#{app_path}/Classes/*.{m,h}"].each do |filename|
265
+ Dir["#{app_path}/Classes/**/*.{m,h}"].each do |filename|
146
266
  if filename =~ /#{transform_title}/
147
267
  FileUtils.mv filename, filename.gsub(/#{transform_title}/, app_title)
148
268
  end
@@ -169,6 +289,27 @@ module Transender
169
289
  false
170
290
  end
171
291
 
292
+ private
293
+
294
+ def has_abowl?
295
+ File.exists? @abowl_yml
296
+ end
297
+
298
+ def make_abowl
299
+ unless File.exists? @abowl_yml #do not overwrite
300
+ FileUtils.cp_r File.join(LIBPATH, "abowl"), @ji_path
301
+ end
302
+ rescue
303
+ puts "Could not make abowl."
304
+ end
305
+
306
+ def read_abowl
307
+ @abowl = YAML.load_file @abowl_yml
308
+ rescue
309
+ puts "Could not read abowl."
310
+ nil
311
+ end
312
+
172
313
  end # class Ji
173
314
 
174
315
  end # module Transender
@@ -1,5 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), %w[spec_helper])
2
2
  include Transender
3
+ RSPEC=:yes
3
4
 
4
5
  describe Transender do
5
6
 
@@ -27,7 +28,6 @@ describe Transender do
27
28
  puts File.exists?(File.join(ji.app_path)).should be(true)
28
29
  end
29
30
 
30
-
31
31
  it "should transform and zip" do
32
32
  proc do
33
33
  Ji.transform_and_zip({:app_title=>"xyzproject", :transform=>File.join(File.dirname(__FILE__), %w[.. iproject]), :ji_path => File.join(File.dirname(__FILE__), %w[.. tmp]) }) do |zip|
@@ -46,4 +46,10 @@ describe Transender do
46
46
  end.should_not raise_error
47
47
  end
48
48
 
49
+ it "should transform and transend" do
50
+ proc do
51
+ Ji.transend({:app_title=>"aproject", :transform=>File.join(File.dirname(__FILE__), %w[.. iproject]), :ji_path => File.join(File.dirname(__FILE__), %w[.. tmp aproject]) })
52
+ end.should_not raise_error
53
+ end
54
+
49
55
  end
data/transender.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{transender}
5
- s.version = "0.2.4"
5
+ s.version = "0.2.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mihael"]
9
- s.date = %q{2009-07-06}
9
+ s.date = %q{2009-08-03}
10
10
  s.default_executable = %q{transender}
11
11
  s.email = %q{kitschmaster@gmail.com}
12
12
  s.executables = ["transender"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION.yml",
28
28
  "bin/transender",
29
+ "lib/abowl/abowl.yml",
29
30
  "lib/tasks/pushup.rake",
30
31
  "lib/transender.rb",
31
32
  "spec/spec_helper.rb",
@@ -38,7 +39,7 @@ Gem::Specification.new do |s|
38
39
  s.rdoc_options = ["--charset=UTF-8"]
39
40
  s.require_paths = ["lib"]
40
41
  s.rubyforge_project = %q{transender}
41
- s.rubygems_version = %q{1.3.4}
42
+ s.rubygems_version = %q{1.3.5}
42
43
  s.summary = %q{Use Transender whenever you need to git-clone and rename XCode iPhone SDK projects.}
43
44
  s.test_files = [
44
45
  "spec/spec_helper.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mihael
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-06 00:00:00 +02:00
12
+ date: 2009-08-03 00:00:00 +02:00
13
13
  default_executable: transender
14
14
  dependencies: []
15
15
 
@@ -34,6 +34,7 @@ files:
34
34
  - Rakefile
35
35
  - VERSION.yml
36
36
  - bin/transender
37
+ - lib/abowl/abowl.yml
37
38
  - lib/tasks/pushup.rake
38
39
  - lib/transender.rb
39
40
  - spec/spec_helper.rb
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  requirements: []
66
67
 
67
68
  rubyforge_project: transender
68
- rubygems_version: 1.3.4
69
+ rubygems_version: 1.3.5
69
70
  signing_key:
70
71
  specification_version: 3
71
72
  summary: Use Transender whenever you need to git-clone and rename XCode iPhone SDK projects.