Method: Transender::Ji#transend

Defined in:
lib/transender.rb

#transendObject

read abowl, transend that information into existing project deleting, copying files in this proces



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/transender.rb', line 116

def transend
  if read_abowl 
    
    # handle classes&views files
    if @abowl['files']
      dirz = @abowl['files'].keys
      dirz.each do |type|
        dir_string = "#{app_path}/Classes/#{type}/*.{m,h}"
        dir_string = "#{app_path}/Views/*.{xib, nib}" if type == "Views"
        filenames = @abowl['files'][type]
        if filenames&&filenames.size>0
          unless filenames.size == 1 && filenames[0] == "all"
            Dir[dir_string].each do |file|
              name = Transender.extract_name(file)
              FileUtils.rm file unless filenames.member? name
            end
          end
        else
          FileUtils.rm_rf(Dir.glob(dir_string))
        end
      end
    end
    
    #handle app delegate defines
    defines = @abowl['app']
    appDelegate = "#{app_path}/Classes/Application/#{app_title}AppDelegate.h"
    appDelegate_temp = "#{app_path}/Classes/Application/#{app_title}AppDelegate.h.temp"
    File.open(appDelegate_temp, "w") do |outfile|
      File.open(appDelegate, "r") do |infile|
        while (line = infile.gets)
          if line =~ /#define/
            key = line.split[1]
            if defines.has_key? key
              value = defines[key]
              if value.to_s =~ /^(\d)*\.(\d)*$/ #is numerical
                outfile << (line.gsub /^#define #{key} .*$/, "#define #{key} #{value}")
                puts "#define #{key} #{value}"
              else
                outfile << (line.gsub /^#define #{key} .*$/, "#define #{key} @\"#{value}\"")
                puts "#define #{key} #{value}"
              end
            end
          else
            outfile << line
          end
        end
      end
    end
    FileUtils.mv appDelegate_temp, appDelegate
    
    puts "Transended #{@abowl['app']['APP_TITLE']}."

  else #try to make a bowl then
    make_abowl
  end
end