Class: PluginFiles
- Inherits:
-
Object
- Object
- PluginFiles
- Defined in:
- lib/PluginFiles.rb
Instance Method Summary collapse
- #create_android_source_file ⇒ Object
- #create_ios_header_file ⇒ Object
- #create_ios_implementation_file ⇒ Object
- #create_javascript_source_file ⇒ Object
- #create_package_file ⇒ Object
- #create_plugin_readme ⇒ Object
- #create_plugin_xml_file ⇒ Object
-
#initialize(options) ⇒ PluginFiles
constructor
A new instance of PluginFiles.
Constructor Details
#initialize(options) ⇒ PluginFiles
Returns a new instance of PluginFiles.
2 3 4 |
# File 'lib/PluginFiles.rb', line 2 def initialize() @name, @path, @bundle_id, @verbose = [:name], [:path], [:bundle_id], [:verbose] end |
Instance Method Details
#create_android_source_file ⇒ Object
112 113 114 115 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 |
# File 'lib/PluginFiles.rb', line 112 def create_android_source_file if @verbose puts "Creating Android source file" end android_source_template = " /** * #{@name} */ package #{@bundle_id}.#{@name}; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.PluginResult; import org.apache.cordova.PluginResult.Status; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.Iterator; public class CDV#{@name} extends CordovaPlugin { @Override public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException { PluginResult result = null; callbackContext.sendPluginResult(result); return true; } } " Dir.chdir(@path + "/" + @name + "/" + "src/android") File.write(Dir.pwd + "/CDV#{@name}.java", android_source_template) end |
#create_ios_header_file ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/PluginFiles.rb', line 76 def create_ios_header_file if @verbose puts "Creating iOS header file" end ios_header_template = " //CDV#{@name} // #import <Cordova/CDV.h> @interface #{@name} : CDVPlugin @end " Dir.chdir(Dir.pwd + "/src/ios") File.write(Dir.pwd + "/CDV#{@name}.h", ios_header_template) end |
#create_ios_implementation_file ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/PluginFiles.rb', line 95 def create_ios_implementation_file if @verbose puts "Creating iOS source file" end ios_implementation_template = " //CDV#{@name}.m // #import \"CDV#{@name}.h\" @implementation #{@name} @end " File.write(Dir.pwd + "/CDV#{@name}.m", ios_implementation_template) end |
#create_javascript_source_file ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/PluginFiles.rb', line 148 def create_javascript_source_file if @verbose puts "Creating JavaScript source file" end javascript_source_file = " var #{@name} = { }; module.exports = #{@name}; " Dir.chdir(@path + "/" + @name + "/" + "www") File.write(Dir.pwd + "/#{@name}.js", javascript_source_file) end |
#create_package_file ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/PluginFiles.rb', line 53 def create_package_file if @verbose puts "Creating Plugin Package file" end package_template = "{ \"version\": \"0.0.1\", \"name\": \"#{@bundle_id}.#{@name}\", \"cordova_name\": \"#{@name}\", \"description\": \"#{@name}\", \"license\": \"MIT\", \"keywords\": [], \"engines\": [ { \"name\": \"cordova\", \"version\": \">=3.0.0\" } ] }" File.write(Dir.pwd + "/package.json", package_template) end |
#create_plugin_readme ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/PluginFiles.rb', line 45 def create_plugin_readme if @verbose puts "Creating Plugin README file" end File.write(Dir.pwd + "/README.md", "##{@name}") end |
#create_plugin_xml_file ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 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 |
# File 'lib/PluginFiles.rb', line 6 def create_plugin_xml_file if @verbose puts "Creating Plugin XML File" end bundle_id_as_path = @bundle_id.gsub("\.", "\/") plugin_template = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <plugin xmlns=\"http://apache.org/cordova/ns/plugins/1.0\" id=\"#{@bundle_id}.#{@name}\" version=\"0.0.1\"> <name>#{@name}</name> <description>#{@name}</description> <license>Apache 2.0</license> <keywords></keywords> <js-module src=\"www/#{@name}.js\" name=\"#{@name}\"> <clobbers target=\"#{@name}\" /> </js-module> <platform name=\"android\"> <config-file target=\"res/xml/config.xml\" parent=\"/*\"> <feature name=\"#{@name}\"> <param name=\"android-package\" value=\"#{@bundle_id}.#{@name}\" /> </feature> </config-file> <source-file src=\"src/android/CDV#{@name}.java\" target-dir=\"src/#{bundle_id_as_path}/#{@name}/\" /> </platform> <platform name=\"ios\"> <config-file target=\"config.xml\" parent=\"/*\"> <feature name=\"#{@name}\"> <param name=\"ios-package\" value= \"CDV#{@name}\" /> </feature> </config-file> <header-file src=\"src/ios/CDV#{@name}.h\" target-dir=\"#{@name}/Classes\" /> <source-file src=\"src/ios/CDV#{@name}.m\" target-dir=\"#{@name}/Classes\" /> </platform> </plugin>" File.write(Dir.pwd + "/plugin.xml", plugin_template) end |