├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── lib ├── generators │ └── phonegap_rails │ │ └── install │ │ ├── install_generator.rb │ │ └── templates │ │ └── config │ │ └── phonegap_rails.yml ├── phonegap-rails.rb ├── phonegap │ └── rails │ │ ├── engine.rb │ │ ├── tasks │ │ └── rails.rake │ │ └── version.rb ├── phonegap_rails.rb └── public │ └── android_index.html.erb └── phonegap-rails.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in phonegap-rails.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Josep Casals 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Phonegap::Rails 2 | [](https://gemnasium.com/joscas/phonegap-rails) 3 | 4 | This gem provides generators for the Phonegap APIs. It is intended to be used within the scope of single page web applications that have a Ruby on Rails API backend. For example, Ember.js / Rails apps. 5 | 6 | This gem will export assets included in the rails project as a Phonegap project. This gem won't be able to export applications where content is generated dynamically by the server (e.g applications making use of eRuby). 7 | 8 | ## Installation 9 | 10 | Add this line to your application's Gemfile: 11 | 12 | gem 'phonegap-rails' 13 | 14 | And then execute: 15 | 16 | $ bundle 17 | 18 | Or install it yourself as: 19 | 20 | $ gem install phonegap-rails 21 | 22 | Initialize: 23 | 24 | $ rails g phonegap_rails:install 25 | 26 | Edit your config file according to your environment: 27 | 28 | config/phonegap_rails.yml 29 | 30 | ## Usage 31 | 32 | ### Create android project 33 | 34 | $ rake phonegap:rails:android:create 35 | 36 | Perform all steps to create android project and run 37 | (connect phone via USB if you want to install on your terminal) 38 | 39 | $ rake phonegap:rails:android:initall 40 | 41 | ### Other useful tasks 42 | 43 | Export application application assets to the android Phonegap project 44 | 45 | $ rake phonegap:rails:android:export 46 | 47 | Build project 48 | 49 | $ rake phonegap:rails:android:build 50 | 51 | Launch emulator 52 | 53 | $ rake phonegap:rails:android:emulate 54 | 55 | Clean 56 | 57 | $ rake phonegap:rails:android:clean 58 | 59 | Log 60 | 61 | $ rake phonegap:rails:android:log 62 | 63 | #### Requirements 64 | - Phonegap 65 | - Android SDK [http://developer.android.com](http://developer.android.com) 66 | 67 | 68 | ### Export ios project 69 | 70 | Xcode must be installed 71 | 72 | TODO: This section is still pending implementation 73 | 74 | $ rake Phonegap:rails:ios:export 75 | 76 | ## Contributing 77 | 78 | 1. Fork it 79 | 2. Create your feature branch (`git checkout -b my-new-feature`) 80 | 3. Commit your changes (`git commit -am 'Add some feature'`) 81 | 4. Push to the branch (`git push origin my-new-feature`) 82 | 5. Create new Pull Request 83 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /lib/generators/phonegap_rails/install/install_generator.rb: -------------------------------------------------------------------------------- 1 | require 'rails/generators' 2 | 3 | module PhonegapRails 4 | module Generators 5 | class InstallGenerator < Rails::Generators::Base 6 | desc "Create config file" 7 | source_root File.expand_path('../templates', __FILE__) 8 | 9 | def create_config_file 10 | copy_file "config/phonegap_rails.yml" 11 | end 12 | 13 | def create_android_dir 14 | empty_directory Rails.root.join("phonegap/android") 15 | end 16 | 17 | def create_ios_dir 18 | empty_directory Rails.root.join("phonegap/ios") 19 | end 20 | 21 | end 22 | end 23 | end -------------------------------------------------------------------------------- /lib/generators/phonegap_rails/install/templates/config/phonegap_rails.yml: -------------------------------------------------------------------------------- 1 | ## 2 | ## General settings 3 | ## 4 | #phonegap_path: '~/Development/phonegap-2.6.0' 5 | #api_server: 'http://example.com' //This will be accessible through API_SERVER global var 6 | 7 | ## Android settings 8 | #android: 9 | # package: 'com.example.appname' 10 | -------------------------------------------------------------------------------- /lib/phonegap-rails.rb: -------------------------------------------------------------------------------- 1 | require 'phonegap_rails' 2 | 3 | -------------------------------------------------------------------------------- /lib/phonegap/rails/engine.rb: -------------------------------------------------------------------------------- 1 | class Engine < ::Rails::Engine 2 | rake_tasks do 3 | load "phonegap/rails/tasks/rails.rake" 4 | end 5 | end -------------------------------------------------------------------------------- /lib/phonegap/rails/tasks/rails.rake: -------------------------------------------------------------------------------- 1 | namespace :phonegap do 2 | namespace :rails do 3 | config_path = File.join(Rails.root, 'config', 'phonegap_rails.yml') 4 | if File.exist?(config_path) 5 | config_file = File.read(config_path) 6 | config = YAML.load(config_file) 7 | unless config.nil? or config === false 8 | unless config['phonegap_path'].nil? 9 | phonegap_path = config['phonegap_path'] 10 | scripts_path = phonegap_path + '/lib/android/bin' 11 | end 12 | main_activity = Rails.application.class.to_s.split("::").first 13 | project_path = 'phonegap/android/' + main_activity 14 | unless config['android'].nil? 15 | package = config['android']["package"] unless config['android']["package"].nil? 16 | end 17 | @api_server = config['api_server'] unless config['api_server'].nil? 18 | end 19 | end 20 | 21 | namespace :android do 22 | 23 | desc 'Perform all tasks required to run the application as an Android project' 24 | task :initall => [:create,:export,:build,:emulate] do 25 | end 26 | 27 | desc 'create Phonegap project for android' 28 | task :create => :environment do 29 | if phonegap_path.blank? 30 | puts "You have to specify phonegap path at config/phonegap_rails.yml" 31 | abort 32 | end 33 | if package.blank? 34 | puts "You have to specify an android package at config/phonegap_rails.yml" 35 | abort 36 | end 37 | puts "Creating android project" 38 | command = "#{scripts_path}/create #{project_path} #{package} #{main_activity}" 39 | puts "creating project: #{command}" 40 | puts `#{command}` 41 | end 42 | desc 'export application assets to android phonegap project' 43 | task :export => :environment do 44 | puts "Exporting android project" 45 | environment = Rails.application.assets 46 | ## Export js assets 47 | puts '* javascript assets' 48 | file = File.open("#{project_path}/assets/www/js/application.js", "w") 49 | file.write environment['application.js'] 50 | file.close 51 | ## Export css assets 52 | puts '* css assets' 53 | file = File.open("#{project_path}/assets/www/css/application.css", "w") 54 | file.write environment['application.css'] 55 | file.close 56 | ## Export images and fonts 57 | puts '* images and fonts' 58 | FileUtils.mkdir_p "#{project_path}/assets/www/assets" 59 | other_paths = Rails.configuration.assets.paths.select {|x| x =~ /\/fonts$|\/images$/} 60 | other_paths.each do |path| 61 | files = Dir.glob("#{path}/**/*.*") 62 | files.each do |file| 63 | FileUtils.cp file, "#{project_path}/assets/www/assets" 64 | end 65 | end 66 | ## Export public folder 67 | puts '* public folder' 68 | Dir.glob("public/**/*.*").each do |file| 69 | FileUtils.cp file, "#{project_path}/assets/www/" unless file =~ /public\/assets\// 70 | end 71 | puts '* index.html' 72 | @app_title = main_activity 73 | public_source = File.expand_path('../../../../public', __FILE__) 74 | file = File.open("#{project_path}/assets/www/index.html", "w") 75 | file.write ERB.new(File.read("#{public_source}/android_index.html.erb")).result 76 | file.close 77 | ## Fix relative paths and configure API server 78 | css_file_path = "#{project_path}/assets/www/css/application.css" 79 | css_file = File.read(css_file_path) 80 | new_css_file = css_file.gsub(/\/assets/, '../assets') 81 | file = File.open(css_file_path, "w") 82 | file.puts new_css_file 83 | file.close 84 | js_file_path = "#{project_path}/assets/www/js/application.js" 85 | js_file = File.read(js_file_path) 86 | new_js_file = js_file.gsub(/src=\\"\//, 'src=\"') 87 | if @api_server.blank? 88 | puts "Warning: No API server is specified for this app" 89 | else 90 | if new_js_file =~ /href=\\"\// 91 | puts "Relative paths found. Making absolute to reference API: #{@api_server}" 92 | new_js_file.gsub!(/href=\\"\//, 'href=\"'+@api_server+'/') 93 | end 94 | end 95 | file = File.open(js_file_path, "w") 96 | file.puts new_js_file 97 | file.close 98 | 99 | end 100 | desc 'build android phonegap project' 101 | task :build => :environment do 102 | command = "#{project_path}/cordova/build" 103 | puts "Building project: #{command}" 104 | puts `#{command}` 105 | end 106 | desc 'Launch emulator for android phonegap project' 107 | task :emulate => :environment do 108 | command = "#{project_path}/cordova/run" 109 | puts "Launching emulator: #{command}" 110 | puts `#{command}` 111 | end 112 | desc 'Clean android phonegap project' 113 | task :clean => :environment do 114 | command = "#{project_path}/cordova/clean" 115 | puts "Cleaning project: #{command}" 116 | puts `#{command}` 117 | end 118 | desc 'Log' 119 | task :log => :environment do 120 | command = "#{project_path}/cordova/log" 121 | puts "Log: #{command}" 122 | puts `#{command}` 123 | end 124 | end 125 | namespace :ios do 126 | desc 'export Phonegap project for ios' 127 | task :export => :environment do 128 | # TODO: export project 129 | puts "Not implemented" 130 | end 131 | end 132 | end 133 | end -------------------------------------------------------------------------------- /lib/phonegap/rails/version.rb: -------------------------------------------------------------------------------- 1 | module Phonegap 2 | module Rails 3 | VERSION = "0.0.12" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/phonegap_rails.rb: -------------------------------------------------------------------------------- 1 | require 'phonegap/rails/version' 2 | 3 | module Phonegap 4 | module Rails 5 | require "phonegap/rails/engine" if defined?(Rails) 6 | end 7 | end -------------------------------------------------------------------------------- /lib/public/android_index.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 |
22 | 23 | 24 | 25 | 26 |