Class: FileEditor
- Inherits:
-
Object
- Object
- FileEditor
- Defined in:
- lib/furion/file_editor.rb
Class Method Summary collapse
- .editPodfile ⇒ Object
- .fillCommonParam(code, params) ⇒ Object
- .getCuriOSProjName ⇒ Object
- .getTagFromExampleStartLabel(codeString) ⇒ Object
- .initPodfile(target) ⇒ Object
- .insertExampleCode ⇒ Object
- .loadWrapperExample(keys, params, file) ⇒ Object
Class Method Details
.editPodfile ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# 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 ⇒ Object
10 11 12 13 14 15 16 17 |
# 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) ⇒ Object
151 152 153 154 |
# File 'lib/furion/file_editor.rb', line 151 def self.getTagFromExampleStartLabel(codeString) target = codeString[25,(codeString.length - 27)] return target end |
.initPodfile(target) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# 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 ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# 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) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# 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 |