class FileEditor

Public Class Methods

editPodfile() click to toggle source
# File lib/furion/file_editor.rb, line 19
def self.editPodfile

  projName = self.getCuriOSProjName

  if projName == nil
    return
  end

  if !FileTest::exist?("podfile")
    self.initPodfile(projName)
  end
  File.open("_Podfile", "w") do |out|
    hasSource = false
    hasAddRequire = false
    File.foreach("Podfile") do |line|
      if !hasAddRequire
        out.puts "source " + $wrapperGitUrl
        out.puts "load 'furionpod'"
        hasAddRequire = true
      end
      out.puts line

      # if line =~ /#*source +'[a-zA-z]+:\/\/[^\s]*'/
      #   hasSource = true
      #   puts "found it"
      # else
      #   if hasSource
      #
      #   end
      #   hasSource = false
      # end

      if line =~ /target +'#{projName}'/
        out.puts "    loadFurionConfigPod()"
      end
    end

  end
  File.delete("Podfile")
  File.rename("_Podfile","Podfile")
end
fillCommonParam(code,params) click to toggle source
# File lib/furion/file_editor.rb, line 133
def self.fillCommonParam(code,params)
    for key in params.keys
      varStr = "$FurionVar_"+key
      if code.include? varStr
          var = varStr
          if params[key].class == String
            var = "@\""+params[key]+"\""
          else
            var = String(params[key])
          end

          result = code.sub(varStr,var)
          return result
      end
    end
    return code
end
getCuriOSProjName() click to toggle source
# File lib/furion/file_editor.rb, line 10
def self.getCuriOSProjName
  Find.find(Dir::pwd) do |path|
    if path.end_with? ".xcodeproj" and File.directory? path
      return File.basename(path, ".*")
      break
    end
  end
end
getTagFromExampleStartLabel(codeString) click to toggle source
# File lib/furion/file_editor.rb, line 151
def self.getTagFromExampleStartLabel(codeString)
    target = codeString[25,(codeString.length - 27)]
    return target
end
initPodfile(target) click to toggle source
# File lib/furion/file_editor.rb, line 61
def self.initPodfile(target)
  File.open("podfile", "w") do |out|
    out.puts "source 'https://gitlab.huya.com/ci_team/Specs.git'"
    out.puts "source 'https://github.com/CocoaPods/Specs.git'"
    out.puts "platform :ios, '9.0'"
    out.puts "target '"+target+"' do"
    out.puts ""
    out.puts "end"
  end
end
insertExampleCode() click to toggle source
# File lib/furion/file_editor.rb, line 72
def self.insertExampleCode

  dict = Plist::parse_xml("MTPSDK.plist")
  #wrapperSDKDict = dict["sdkWrapper"]
  params = dict["commonParams"]
  keys = []#wrapperSDKDict.keys()
  keys.insert(0,"commonCode")
  keys.append("finnalInit")
  targetFilePath = ""
  Find.find(Dir::pwd) do |path|
    if path.end_with? "AppDelegate.m"
      targetFilePath = path
      break
    end
  end

  File.open("_AppDelegate.m", "w") do |out|
    File.foreach(targetFilePath) do |line|
      out.puts line
      if line.include?"#import \"AppDelegate.h\""
        out.puts "#import <Hosttemplate/HostTemplate.h>"
      end
      if line.include? "application:(UIApplication *)application didFinishLaunchingWithOptions:"
        loadWrapperExample(keys,params,out)
      end
    end
  end

  File.delete(targetFilePath)
  File.rename("_AppDelegate.m",targetFilePath)

end
loadWrapperExample(keys,params,file) click to toggle source
# File lib/furion/file_editor.rb, line 105
def self.loadWrapperExample(keys,params,file)

  inRecording = false
  File.foreach("example.code") do |line|

    if line =~ /\#Furion\#end-/
      inRecording = false
    end

    if inRecording
      content = line
      if line.include?"$FurionVar_"
         content = self.fillCommonParam(line,params)
      end
      file.puts content
    end

    if line =~ /\#Furion\#start-/
      target = getTagFromExampleStartLabel(line)
      if keys.include?(target)
         inRecording = true
      end
    end
  end
end