droiuby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/drby +66 -0
- data/lib/droiuby/project.rb +149 -0
- data/lib/droiuby/templates/ruby/application.css.erb +1 -0
- data/lib/droiuby/templates/ruby/config.droiuby.erb +11 -0
- data/lib/droiuby/templates/ruby/gitignore.erb +1 -0
- data/lib/droiuby/templates/ruby/index.rb.erb +10 -0
- data/lib/droiuby/templates/ruby/index.xml.erb +6 -0
- data/lib/droiuby.rb +1 -0
- metadata +166 -0
data/bin/drby
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "droiuby"
|
4
|
+
|
5
|
+
command = ARGV[0]
|
6
|
+
|
7
|
+
case command
|
8
|
+
when 'new'
|
9
|
+
if ARGV.size < 2
|
10
|
+
puts "Create a new droiuby app"
|
11
|
+
puts "usage: "
|
12
|
+
puts "drby new [project name]"
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
project_name = ARGV[1]
|
16
|
+
project = Project.new
|
17
|
+
project.create(project_name,'')
|
18
|
+
when 'pack'
|
19
|
+
project_name = nil
|
20
|
+
if ARGV.size == 2
|
21
|
+
project_name = ARGV[1]
|
22
|
+
else
|
23
|
+
if !File.exists?('config.droiuby')
|
24
|
+
puts 'current directory is not a valid droiuby project'
|
25
|
+
exit(1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
project = Project.new
|
29
|
+
project.package(project_name)
|
30
|
+
when 'gopack'
|
31
|
+
project_name = nil
|
32
|
+
if ARGV.size == 3
|
33
|
+
project_name = ARGV[1]
|
34
|
+
device_ip = ARGV[2]
|
35
|
+
elsif ARGV.size == 2
|
36
|
+
device_ip = ARGV[1]
|
37
|
+
else
|
38
|
+
puts "zips and uploads app to device"
|
39
|
+
puts "usage: "
|
40
|
+
puts "drby gopack [device IP]"
|
41
|
+
puts "drby gopack [folder] [device IP]"
|
42
|
+
exit(1)
|
43
|
+
end
|
44
|
+
project = Project.new
|
45
|
+
project.execute(project_name, device_ip, '')
|
46
|
+
when 'live'
|
47
|
+
project_name = nil
|
48
|
+
if ARGV.size == 3
|
49
|
+
project_name = ARGV[1]
|
50
|
+
device_ip = ARGV[2]
|
51
|
+
elsif ARGV.size == 2
|
52
|
+
device_ip = ARGV[1]
|
53
|
+
else
|
54
|
+
puts "starts a live web server and point droiuby to it"
|
55
|
+
puts "usage: "
|
56
|
+
puts "drby live [device IP]"
|
57
|
+
puts "drby live [folder] [device IP]"
|
58
|
+
exit(1)
|
59
|
+
end
|
60
|
+
project = Project.new
|
61
|
+
project.live(project_name, device_ip, nil, '')
|
62
|
+
else
|
63
|
+
puts "invalid command"
|
64
|
+
puts "Should be:"
|
65
|
+
puts " drby [new|live|gopack|pack]"
|
66
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/http/post/multipart'
|
5
|
+
require 'zip'
|
6
|
+
require 'thor'
|
7
|
+
require "uri"
|
8
|
+
require 'cgi'
|
9
|
+
|
10
|
+
require 'active_support/core_ext/object'
|
11
|
+
require 'active_support/core_ext/string'
|
12
|
+
|
13
|
+
class Project < Thor
|
14
|
+
|
15
|
+
include Thor::Actions
|
16
|
+
|
17
|
+
source_root 'templates'
|
18
|
+
|
19
|
+
desc "launch device IP [URL]","Tell droiuby to connect to app hosted at URL"
|
20
|
+
def launch(device_ip, url)
|
21
|
+
url_str = "http://#{device_ip}:4000/control?cmd=launch&url=#{CGI::escape(url)}"
|
22
|
+
puts "loading application at url #{url}"
|
23
|
+
puts url_str
|
24
|
+
uri = URI.parse(url_str)
|
25
|
+
# Shortcut
|
26
|
+
response = Net::HTTP.get_response(uri)
|
27
|
+
# Will print response.body
|
28
|
+
Net::HTTP.get_print(uri)
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "create NAME [WORKSPACE_DIR]","create a new droiuby project with NAME"
|
32
|
+
def create(name, output_dir = 'projects')
|
33
|
+
@name = name
|
34
|
+
@description = name
|
35
|
+
@launcher_icon = ''
|
36
|
+
@base_url = ''
|
37
|
+
@main_xml = 'index.xml'
|
38
|
+
|
39
|
+
dest_folder = File.join(output_dir,"#{name}")
|
40
|
+
template File.join('ruby','config.droiuby.erb'), File.join(dest_folder,"config.droiuby")
|
41
|
+
template File.join('ruby','gitignore.erb'), File.join(dest_folder,".gitignore")
|
42
|
+
template File.join('ruby','index.xml.erb'), File.join(dest_folder,"index.xml")
|
43
|
+
template File.join('ruby','application.css.erb'), File.join(dest_folder,"application.css")
|
44
|
+
template File.join('ruby','index.rb.erb'), File.join(dest_folder,"index.rb")
|
45
|
+
empty_directory File.join(dest_folder,"lib")
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "package NAME [WORKSPACE_DIR] [true|false]","package a project"
|
49
|
+
|
50
|
+
def package(name, source_dir = 'projects', force = "false")
|
51
|
+
src_folder = File.join(source_dir,"#{name}")
|
52
|
+
say "compress #{src_folder}"
|
53
|
+
compress(src_folder, force)
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "live NAME DEVICE_IP [HOST NAME] [SOURCE]", "Allow live editing of apps by starting a web server and pointing droiuby to the local instance"
|
57
|
+
def live(name, device_ip, host_name, source_dir)
|
58
|
+
require 'webrick'
|
59
|
+
include WEBrick
|
60
|
+
source_dir_args = source_dir ? source_dir : 'projects'
|
61
|
+
host_name_args = host_name ? host_name : Socket.gethostname
|
62
|
+
src_dir = source_dir_args.blank? ? '' : File.join(source_dir_args, name)
|
63
|
+
port = 2000
|
64
|
+
|
65
|
+
ready = false
|
66
|
+
|
67
|
+
Thread.new do
|
68
|
+
while !ready
|
69
|
+
end
|
70
|
+
`adb shell am start -W -S --activity-clear-top --activity-brought-to-front -n com.droiuby.client/.CanvasActivity`
|
71
|
+
launch(device_ip, "http://#{host_name_args}:#{port}/config.droiuby")
|
72
|
+
end
|
73
|
+
|
74
|
+
puts "Starting server: http://#{host_name_args}:#{port}"
|
75
|
+
server = HTTPServer.new(:Port=>port,:DocumentRoot=> src_dir,:StartCallback => Proc.new {
|
76
|
+
ready = true
|
77
|
+
})
|
78
|
+
trap("INT"){ server.shutdown }
|
79
|
+
server.start
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
desc "upload NAME DEVICE_IP [WORKSPACE_DIR]","uploads a droiuby application to target device running droiuby client"
|
84
|
+
def upload(name, device_ip, source_dir = 'projects')
|
85
|
+
src_package = File.join(source_dir,name,'build',"#{name}.zip")
|
86
|
+
|
87
|
+
url_str = "http://#{device_ip}:4000/upload"
|
88
|
+
uri = URI.parse(url_str)
|
89
|
+
say "uploading to #{url_str} -> #{uri.host}:#{uri.port}"
|
90
|
+
File.open(src_package) do |zip|
|
91
|
+
req = Net::HTTP::Post::Multipart.new uri.path,
|
92
|
+
"name" => name,
|
93
|
+
"run" => "true",
|
94
|
+
"file" => UploadIO.new(zip, "application/zip", src_package,"content-disposition" => "form-data; name=\"file\"; filename=\"#{File.basename(src_package)}\"\r\n")
|
95
|
+
|
96
|
+
retries = 0
|
97
|
+
while (retries < 3)
|
98
|
+
sleep 1 + retries
|
99
|
+
begin
|
100
|
+
res = Net::HTTP.start(uri.host, uri.port) do |http|
|
101
|
+
http.request(req)
|
102
|
+
end
|
103
|
+
break
|
104
|
+
rescue Errno::EHOSTUNREACH
|
105
|
+
retries += 1
|
106
|
+
next
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
if res.code == "200"
|
112
|
+
say_status 'upload', src_package
|
113
|
+
else
|
114
|
+
say 'upload failed.'
|
115
|
+
say res.body
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
desc "execute NAME DEVICE_IP [WORKSPACE_DIR]","package and execute a droiuby application to target device running droiuby client"
|
122
|
+
def execute(name, device_ip, source_dir = 'projects')
|
123
|
+
`adb shell am start -W -S --activity-clear-top --activity-brought-to-front -n com.droiuby.client/.CanvasActivity`
|
124
|
+
package name, source_dir, "true"
|
125
|
+
upload name, device_ip, source_dir
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def compress(path, force = "false")
|
131
|
+
path.sub!(%r[/$],'')
|
132
|
+
unless Dir.exists?(File.join(path,'build'))
|
133
|
+
Dir.mkdir(File.join(path,'build'))
|
134
|
+
end
|
135
|
+
archive = File.join(path,'build',"#{File.basename(path)}.zip")
|
136
|
+
if force=='true' || file_collision(archive)
|
137
|
+
|
138
|
+
FileUtils.rm archive, :force=>true
|
139
|
+
|
140
|
+
Zip::File.open(archive, Zip::File::CREATE) do |zipfile|
|
141
|
+
Dir["#{path}/**/**"].reject{ |f| f==archive || f.match(/\/build/) }.each do |file|
|
142
|
+
say_status 'adding', file
|
143
|
+
zipfile.add(file.sub(path+'/',''),file)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
say_status 'create', archive
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
/* place application wide css here */
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<app_descriptor>
|
2
|
+
<name><%= @name %></name>
|
3
|
+
<description><%= @description %></description>
|
4
|
+
<launcher_icon><%= @launcher_icon %></launcher_icon>
|
5
|
+
<base_url><%= @base_url%></base_url>
|
6
|
+
<main><%= @main_xml %></main>
|
7
|
+
<framework>droiuby</framework>
|
8
|
+
<assets>
|
9
|
+
<resource name="lib" type="lib"/>
|
10
|
+
</assets>
|
11
|
+
</app_descriptor>
|
@@ -0,0 +1 @@
|
|
1
|
+
build/**/*
|
data/lib/droiuby.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'droiuby/project'
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: droiuby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joseph Emmanuel Dayo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :runtime
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
none: false
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :runtime
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: thor
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
none: false
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
none: false
|
60
|
+
prerelease: false
|
61
|
+
type: :runtime
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rubyzip
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.0
|
69
|
+
none: false
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.0.0
|
75
|
+
none: false
|
76
|
+
prerelease: false
|
77
|
+
type: :runtime
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: multipart-post
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
none: false
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
none: false
|
92
|
+
prerelease: false
|
93
|
+
type: :runtime
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: properties-ruby
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
none: false
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
none: false
|
108
|
+
prerelease: false
|
109
|
+
type: :runtime
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: activesupport
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
none: false
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
none: false
|
124
|
+
prerelease: false
|
125
|
+
type: :runtime
|
126
|
+
description: Android development using ruby
|
127
|
+
email: joseph.dayo@gmail.com
|
128
|
+
executables:
|
129
|
+
- drby
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- lib/droiuby.rb
|
134
|
+
- lib/droiuby/project.rb
|
135
|
+
- lib/droiuby/templates/ruby/config.droiuby.erb
|
136
|
+
- lib/droiuby/templates/ruby/gitignore.erb
|
137
|
+
- lib/droiuby/templates/ruby/index.rb.erb
|
138
|
+
- lib/droiuby/templates/ruby/index.xml.erb
|
139
|
+
- lib/droiuby/templates/ruby/application.css.erb
|
140
|
+
- bin/drby
|
141
|
+
homepage: http://rubygems.org/gems/droiuby
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
none: false
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
none: false
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 1.8.24
|
163
|
+
signing_key:
|
164
|
+
specification_version: 3
|
165
|
+
summary: Droiuby GEM
|
166
|
+
test_files: []
|