Top Level Namespace

Includes:
REXML

Defined Under Namespace

Modules: ElmPlugin

Instance Method Summary collapse

Instance Method Details

#addXcodeprojObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/elm_plugin.rb', line 207

def  addXcodeproj

	project = Xcodeproj::Project.open($project_dic.to_s+$projectName.to_s)  
	target = project.targets.first  
	group = project.main_group.find_subpath(File.join('Plugins'), true)  
	group.set_source_tree('SOURCE_ROOT') 
	Dir::entries($project_dic.to_s+$main_dir.to_s+'/Plugins/'+$plugin_name.to_s).each do |f|
  		if f =~ /\.m$/i
  	    	file_ref = group.new_reference($project_dic.to_s+$main_dir.to_s+'/Plugins/'+$plugin_name.to_s+'/'+f)  
      		target.add_file_references([file_ref]) 
  		end
  		if f =~ /\.h$/i
  			file_ref = group.new_reference($project_dic.to_s+$main_dir.to_s+'/Plugins/'+$plugin_name.to_s+'/'+f)   
  		end
	end 
	project.save  

end

#copyjsObject



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
# File 'lib/elm_plugin.rb', line 19

def copyjs

	if !File::exist?($project_dic+'www')
	 	Dir.mkdir($project_dic+'www')
	end


	if !File::exist?($project_dic+'www/'+$plugin_name)
		Dir.mkdir($project_dic+'www/'+$plugin_name)
	end

    if !File::exist?($project_dic+'www/'+'plugins/'+$plugin_name)
       Dir.mkdir($project_dic+'www/'+'plugins/'+$plugin_name)
    end 
    FileUtils.cp_r(Dir[$tmpPath+'/www'], $project_dic+'www/'+'plugins/'+$plugin_name)
    Dir::entries($project_dic+'www/'+'plugins/'+$plugin_name+'/www').each do |f|
       if f =~ /\.js$/
       	  file = File.open($project_dic+'www/'+'plugins/'+$plugin_name+'/www'+'/'+f, "rb")
          contents = file.read
          file.close
          if contents =~ /^\s*cordova.define\s*\(\s*\"\s*cordova-plugin-console.logger\s*\"\s*,\s*function\s*\(\s*require\s*,\s*exports\s*,\s*module\s*\)\s*\{/
            puts 'has cordova.define'
    	    else
    	  	  contents = "cordova.define(\"cordova-plugin-console.logger\", function(require, exports, module) {\n" +contents +"\n});" 
    	  	  file=File.new($project_dic+'www/'+'plugins/'+$plugin_name+'/www'+'/'+f, 'w+')
              file.write(contents)
              puts 'dont match'
    	  end	
    	  file.close
       end
    	 
    end
end

#copySourceObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/elm_plugin.rb', line 54

def copySource

	if !File::exist?($project_dic+$main_dir+'/Plugins')
		error = 'error: you project don\'t have '+$main_dir+'/Plugins'+'in workspace'
		puts error.red
		exit(0)   
	end	

  if !File::exist?($project_dic+$main_dir+'/Plugins/'+$plugin_name)
      Dir.mkdir($project_dic+$main_dir+'/Plugins/'+$plugin_name) 
  end
	Dir::entries($tmpPath+'/src'+'/ios').each do |f|
  		puts 'copy source to plugins dic'
  		if f =~ /\.[hm]$/i
  	 		FileUtils.cp($tmpPath+'/src'+'/ios/'+f, $project_dic+$main_dir+'/Plugins/'+$plugin_name)
  		end
	end 
end

#findXmlConfigObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/elm_plugin.rb', line 98

def findXmlConfig
 	
  	Dir::entries($project_dic).each do |f|
  		if f == 'config.xml'
  			writeConfigXml($project_dic + 'config.xml')
  			return 
  		end
 	end 

 	Find.find($project_dic+$main_dir) do |f|
 
  		if f =~ /config.xml$/i
  			writeConfigXml(f)
    		break  
  		end
 	end
end

#main_dirObject



10
11
12
13
14
15
16
17
# File 'lib/elm_plugin.rb', line 10

def  main_dir
	Dir::entries($project_dic).each do |f|
  		if f =~ /\.xcodeproj$/i
  			main_dir = File.basename($project_dic+"/"+f, '.xcodeproj')
  			return main_dir
  		end
 	end 
end

#writeConfigXml(fileName) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/elm_plugin.rb', line 117

def writeConfigXml(fileName) 
	puts 'config'+fileName
	fw = File.open(fileName)
    docw = Document.new(fw)
    root = docw.root
    puts root
    f = File.open($project_dic+'ELMPlugins/'+$plugin_name+'/plugin.xml')
    doc = Document.new(f)  
    doc.elements.each("*/platform") { |e|

    	if e.attributes["name"] == 'ios'
    		e.elements.each('config-file/feature') { |se|
    			puts se
    			root.add_element se
    			puts root

    		}
    	end
     
    }
    docw.write(File.open(fileName,"w"), 2)
    fw.close
    f.close
end

#writeJsObject

<js-module src=“www/logger.js” name=“logger”>

    <clobbers target="cordova.logger" />
</js-module>


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/elm_plugin.rb', line 155

def writeJs
	write = false
    tempfile=File.new($project_dic+'www/'+'temp.js', 'w+')
    f=File.new($project_dic+'www/'+'cordova_plugins.js')
    xmlf = File.open($project_dic+'ELMPlugins/'+$plugin_name+'/plugin.xml')
    doc = Document.new(xmlf)
    id = doc.root.attributes['id'] 
    version = doc.root.attributes['version']
    f.each do |line|
    	if line =~ /^(\s)*module.exports(\s)*=(\s)*\[(\s)*\]/
    	   	doc.elements.each("*/js-module") { |e|
       	    		puts e
            		jsId = id + '.' + e.attributes['name']
            		jssSrc = 'plugins/'+$plugin_name +'/'+e.attributes['src']
    				e.elements.each('clobbers') { |se|

    	      	 	clobbers = se.attributes['target']
    	       		tempfile<<"module.exports = \[ \n  {\n       \"File\": "+"\""+jssSrc+"\",\n"+"       \"id\": "+"\""+jsId+"\",\n"+"       \"clobbers\": "+"[\n"+"           \""+clobbers+"\"\n"+"       ]\n"+"    }\n\];\n"
            		}
       			}
    	else
        	tempfile<<line
        	if line.downcase=~ /^(\s)*module.exports(\s)*=(\s)*/
       			doc.elements.each("*/js-module") { |e|
       	    		puts e
            		jsId = id + '.' + e.attributes['name']
            		jssSrc = 'plugins/'+$plugin_name +'/'+e.attributes['src']
    				e.elements.each('clobbers') { |se|

    	      	 	clobbers = se.attributes['target']
    	       		tempfile<<"    {\n       \"File\": "+"\""+jssSrc+"\",\n"+"       \"id\": "+"\""+jsId+"\",\n"+"       \"clobbers\": "+"[\n"+"           \""+clobbers+"\"\n"+"       ]\n"+"    },\n"
              
            		}
       			}
   			end
    	end
    	if  write
    		write = false
        	# "org.apache.cordova.device": "0.2.14-dev"
        	tempfile<< "    \""+id+"\": "+"\""+version+"\",\n" 
    	end

    	if line =~/^(\s)*\/\/ (\s)*TOP (\s)*OF(\s)* METADATA(\s)*/
    		write = true
    	end  
    end 
    f.close
    tempfile.close
    FileUtils.mv($project_dic+'www/'+'temp.js', $project_dic+'www/'+'cordova_plugins.js')
end

#writePodfileAndUpdateObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/elm_plugin.rb', line 74

def writePodfileAndUpdate

	puts $project_dic+'Podfile'

	if File::exist?($project_dic+'Podfile')
	   f=File.new($project_dic+'Podfile', 'a+')
	   f.puts "\npod \'" +$plugin_name+'\''
	   f.close
	   puts 'update pod........................'.green
		 result =`pod update`
	   puts result
  else
     puts 'create Podfile.....'
     `touch Podfile`
     f=File.new($project_dic+'Podfile', 'a+')
     f.puts "source \'[email protected]:arch.mobile/iOS_specs.git\'\nsource \'https://github.com/CocoaPods/Specs.git\'\nplatform :ios, \'7.0\'"
	   f.puts "\npod \'" +$plugin_name+'\''
	   f.close
	   puts 'update pod........................'.green
		 result =`pod install`
     puts result
    end 	
end