rhodes 0.3.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +0 -61
- data/Rakefile +11 -13
- data/lib/rhodes.rb +2 -2
- metadata +33 -77
- data/History.txt +0 -40
- data/README.rdoc +0 -2
- data/bin/rhogen +0 -8
- data/generators/rhogen.rb +0 -131
- data/generators/templates/application/application.rb +0 -4
- data/generators/templates/application/index.erb +0 -11
- data/generators/templates/application/layout.erb +0 -17
- data/generators/templates/model/config.rb +0 -3
- data/generators/templates/model/controller.rb +0 -49
- data/generators/templates/model/edit.erb +0 -21
- data/generators/templates/model/index.erb +0 -10
- data/generators/templates/model/new.erb +0 -16
- data/generators/templates/model/show.erb +0 -6
- data/generators/templates/source/source_adapter.rb +0 -56
- data/lib/ServeME.rb +0 -7
- data/lib/TestServe.rb +0 -9
- data/lib/bsearch.rb +0 -120
- data/lib/builtinME.rb +0 -588
- data/lib/date.rb +0 -1792
- data/lib/date/format.rb +0 -1339
- data/lib/dateME.rb +0 -24
- data/lib/erb.rb +0 -896
- data/lib/find.rb +0 -81
- data/lib/rational.rb +0 -19
- data/lib/rationalME.rb +0 -530
- data/lib/rho.rb +0 -1
- data/lib/rho/render.rb +0 -51
- data/lib/rho/rho.rb +0 -240
- data/lib/rho/rhoapplication.rb +0 -36
- data/lib/rho/rhocontact.rb +0 -110
- data/lib/rho/rhocontroller.rb +0 -35
- data/lib/rho/rhofsconnector.rb +0 -32
- data/lib/rho/rhosupport.rb +0 -139
- data/lib/rho/rhoviewhelpers.rb +0 -121
- data/lib/rhoframework.rb +0 -38
- data/lib/rhofsconnector.rb +0 -1
- data/lib/rhom.rb +0 -1
- data/lib/rhom/rhom.rb +0 -58
- data/lib/rhom/rhom_db_adapter.rb +0 -185
- data/lib/rhom/rhom_db_adapterME.rb +0 -93
- data/lib/rhom/rhom_object.rb +0 -65
- data/lib/rhom/rhom_object_factory.rb +0 -197
- data/lib/rhom/rhom_source.rb +0 -60
- data/lib/singleton.rb +0 -137
- data/lib/time.rb +0 -489
- data/spec/app_generator_spec.rb +0 -33
- data/spec/app_manifest.txt +0 -3
- data/spec/configs/account.rb +0 -3
- data/spec/configs/case.rb +0 -3
- data/spec/configs/employee.rb +0 -3
- data/spec/generator_spec_helper.rb +0 -12
- data/spec/model_generator_spec.rb +0 -36
- data/spec/rho_controller_spec.rb +0 -139
- data/spec/rho_spec.rb +0 -61
- data/spec/rhom_object_factory_spec.rb +0 -132
- data/spec/rhom_spec.rb +0 -45
- data/spec/source_generator_spec.rb +0 -27
- data/spec/spec_helper.rb +0 -48
- data/spec/stubs.rb +0 -31
- data/spec/syncdbtest.sqlite +0 -0
- data/tasks/rspec.rake +0 -34
data/lib/rho.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'rho/rho'
|
data/lib/rho/render.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rho/rhoapplication'
|
2
|
-
|
3
|
-
module Rho
|
4
|
-
class RhoController
|
5
|
-
|
6
|
-
def self.layout(name)
|
7
|
-
@layout = name
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.get_layout_name
|
11
|
-
@layout.nil? ? 'layout' : @layout
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.renderfile(filename)
|
15
|
-
if File.extname(filename) == '.iseq'
|
16
|
-
render_index(filename)
|
17
|
-
else
|
18
|
-
IO.read(filename)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.render_index(filename)
|
23
|
-
layout = File.dirname(filename) + "/layout_erb.iseq"
|
24
|
-
@content = eval_compiled_file(filename, binding)
|
25
|
-
@content = eval_compiled_file(layout, binding) if File.exist?(layout)
|
26
|
-
@content
|
27
|
-
end
|
28
|
-
|
29
|
-
def render(options = nil)
|
30
|
-
options = {} if options.nil? or !options.is_a?(Hash)
|
31
|
-
options[:action] = :index if options[:action].nil?
|
32
|
-
|
33
|
-
@content = eval_compiled_file(@request[:modelpath]+options[:action].to_s+'_erb.iseq', binding )
|
34
|
-
|
35
|
-
if xhr? and options[:use_layout_on_ajax] != true
|
36
|
-
options[:layout] = false
|
37
|
-
elsif options[:layout].nil? or options[:layout] == true
|
38
|
-
options[:layout] = self.class.get_layout_name
|
39
|
-
end
|
40
|
-
|
41
|
-
if options[:layout] != false
|
42
|
-
layoutfile = RhoApplication::get_app_path(@request['application']) + options[:layout].to_s + "_erb.iseq"
|
43
|
-
puts 'Layout file: ' + layoutfile
|
44
|
-
@content = eval_compiled_file(layoutfile, binding ) if File.exist?(layoutfile)
|
45
|
-
end
|
46
|
-
|
47
|
-
@content
|
48
|
-
end
|
49
|
-
|
50
|
-
end # RhoController
|
51
|
-
end # Rho
|
data/lib/rho/rho.rb
DELETED
@@ -1,240 +0,0 @@
|
|
1
|
-
require 'time'
|
2
|
-
require 'rho/render'
|
3
|
-
require 'rho/rhoapplication'
|
4
|
-
require 'rhom'
|
5
|
-
require 'rhofsconnector'
|
6
|
-
|
7
|
-
module Rho
|
8
|
-
class RHO
|
9
|
-
APPLICATIONS = {}
|
10
|
-
|
11
|
-
def initialize(app_manifest_filename=nil)
|
12
|
-
puts "Calling RHO.initialize"
|
13
|
-
Rhom::RhomDbAdapter::open(Rho::RhoFSConnector::get_db_fullpathname)
|
14
|
-
if app_manifest_filename
|
15
|
-
process_model_dirs(app_manifest_filename)
|
16
|
-
else
|
17
|
-
process_model_dirs(Rho::RhoFSConnector::get_app_manifest_filename)
|
18
|
-
end
|
19
|
-
init_sources
|
20
|
-
end
|
21
|
-
|
22
|
-
# make sure we close the database file
|
23
|
-
def self.finalize
|
24
|
-
Rhom::RhomDbAdapter::close
|
25
|
-
end
|
26
|
-
|
27
|
-
# Return the directories where we need to load configuration files
|
28
|
-
def process_model_dirs(app_manifest_filename=nil)
|
29
|
-
File.open(app_manifest_filename).each do |line|
|
30
|
-
require File.join(File.dirname(app_manifest_filename), line.chop)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# setup the sources table and model attributes for all applications
|
35
|
-
def init_sources
|
36
|
-
if defined? Rho::RhoConfig::sources
|
37
|
-
|
38
|
-
# quick and dirty way to get unique array of hashes
|
39
|
-
uniq_sources = Rho::RhoConfig::sources.values.inject([]) { |result,h|
|
40
|
-
result << h unless result.include?(h); result
|
41
|
-
}
|
42
|
-
|
43
|
-
# generate unique source list in database for sync
|
44
|
-
uniq_sources.each do |source|
|
45
|
-
|
46
|
-
src_id = source['source_id']
|
47
|
-
url = source['url']
|
48
|
-
if !self.source_initialized?(src_id)
|
49
|
-
Rhom::RhomDbAdapter::insert_into_table('sources',
|
50
|
-
{"source_id"=>src_id,"source_url"=>url})
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def source_initialized?(source_id)
|
57
|
-
Rhom::RhomDbAdapter::select_from_table('sources','*', 'source_id'=>source_id).size > 0 ? true : false
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_app(appname)
|
61
|
-
if (APPLICATIONS[appname].nil?)
|
62
|
-
require RhoApplication::get_app_path(appname)+'application'
|
63
|
-
APPLICATIONS[appname] = Object.const_get(appname+'Application').new
|
64
|
-
end
|
65
|
-
APPLICATIONS[appname]
|
66
|
-
end
|
67
|
-
|
68
|
-
def get_start_path
|
69
|
-
Rho::RhoConfig.start_path
|
70
|
-
end
|
71
|
-
|
72
|
-
def get_rhobundle_zip_url
|
73
|
-
Rho::RhoConfig.rhobundle_zip_url
|
74
|
-
end
|
75
|
-
|
76
|
-
def get_rhobundle_zip_pwd
|
77
|
-
Rho::RhoConfig.rhobundle_zip_pwd
|
78
|
-
end
|
79
|
-
|
80
|
-
def serve(req)
|
81
|
-
begin
|
82
|
-
puts 'inside RHO.serve...'
|
83
|
-
res = init_response
|
84
|
-
get_app(req['application']).send :serve, req, res
|
85
|
-
return send_response(res)
|
86
|
-
rescue Exception => e
|
87
|
-
return send_error(e.message)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def serve_hash(req)
|
92
|
-
begin
|
93
|
-
puts 'inside RHO.serve...'
|
94
|
-
res = init_response
|
95
|
-
get_app(req['application']).send :serve, req, res
|
96
|
-
return send_response_hash(res)
|
97
|
-
rescue Exception => e
|
98
|
-
return send_error(e.message,500,true)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def serve_index(index_name)
|
103
|
-
begin
|
104
|
-
puts 'inside RHO.serve_index: ' + index_name
|
105
|
-
res = init_response
|
106
|
-
res['request-body'] = RhoController::renderfile(index_name)
|
107
|
-
return send_response(res)
|
108
|
-
rescue Exception => e
|
109
|
-
return send_error(e.message)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def serve_index_hash(index_name)
|
114
|
-
begin
|
115
|
-
puts 'inside RHO.serve_index: ' + index_name
|
116
|
-
res = init_response
|
117
|
-
res['request-body'] = RhoController::renderfile(index_name)
|
118
|
-
return send_response_hash(res)
|
119
|
-
rescue Exception => e
|
120
|
-
return send_error(e.message, 500, true)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def init_response(status=200,message="OK",body="")
|
125
|
-
res = Hash.new
|
126
|
-
res['status'] = status
|
127
|
-
res['message'] = message
|
128
|
-
res['headers'] =
|
129
|
-
{
|
130
|
-
'Date' => Time.now.httpdate,
|
131
|
-
'Content-Type' => 'text/html',
|
132
|
-
'Content-Length' => 0,
|
133
|
-
'Connection' => 'close'
|
134
|
-
}
|
135
|
-
res['request-body'] = body
|
136
|
-
res
|
137
|
-
end
|
138
|
-
|
139
|
-
CR = "\x0d"
|
140
|
-
LF = "\x0a"
|
141
|
-
CRLF = "\x0d\x0a"
|
142
|
-
|
143
|
-
def send_response(res)
|
144
|
-
res['headers']['Content-Length'] = res['request-body'].nil? ? 0 : res['request-body'].length
|
145
|
-
data = "HTTP/1.1 #{res['status'].to_s} #{res['message']}" + CRLF
|
146
|
-
res['headers'].each{|key, value|
|
147
|
-
tmp = key.gsub(/\bwww|^te$|\b\w/){|s| s.upcase }
|
148
|
-
data << "#{tmp}: #{value}" << CRLF
|
149
|
-
}
|
150
|
-
data << CRLF
|
151
|
-
data << res['request-body']
|
152
|
-
data
|
153
|
-
end
|
154
|
-
|
155
|
-
def send_response_hash(res)
|
156
|
-
resp = Hash.new
|
157
|
-
res['headers']['Content-Length'] = res['request-body'].nil? ? 0 : res['request-body'].length
|
158
|
-
res['headers'].each{|key, value|
|
159
|
-
tmp = key.gsub(/\bwww|^te$|\b\w/){|s| s.upcase }
|
160
|
-
resp[tmp] = value
|
161
|
-
}
|
162
|
-
resp['request-body'] = res['request-body']
|
163
|
-
resp['status'] = res['status']
|
164
|
-
resp['message'] = res['message']
|
165
|
-
|
166
|
-
resp
|
167
|
-
end
|
168
|
-
|
169
|
-
def send_error(msg="",status=500,hash=false)
|
170
|
-
body=''
|
171
|
-
body << <<-_HTML_STRING_
|
172
|
-
<html>
|
173
|
-
<head>
|
174
|
-
<title>Server Error</title>
|
175
|
-
<meta name="viewport" content="width=320"/>
|
176
|
-
</head>
|
177
|
-
<body>
|
178
|
-
<p>
|
179
|
-
_HTML_STRING_
|
180
|
-
body << 'Error message: ' << msg
|
181
|
-
body << <<-_HTML_STRING_
|
182
|
-
</p>
|
183
|
-
</body>
|
184
|
-
</html>
|
185
|
-
|
186
|
-
_HTML_STRING_
|
187
|
-
if ( hash )
|
188
|
-
send_response_hash(init_response(status,"Server error",body))
|
189
|
-
else
|
190
|
-
send_response(init_response(status,"Server error",body))
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end # RHO
|
194
|
-
|
195
|
-
# Generic configuration class which accepts hashes with unique keys
|
196
|
-
class RhoConfig
|
197
|
-
@@sources = {}
|
198
|
-
@@start_path = '/'
|
199
|
-
@@rhobundle_zip_url = nil
|
200
|
-
@@rhobundle_zip_pwd = nil
|
201
|
-
|
202
|
-
class << self
|
203
|
-
def sources
|
204
|
-
@@sources
|
205
|
-
end
|
206
|
-
|
207
|
-
def start_path
|
208
|
-
@@start_path
|
209
|
-
end
|
210
|
-
|
211
|
-
def start_path=(path=nil)
|
212
|
-
@@start_path = path if path
|
213
|
-
end
|
214
|
-
|
215
|
-
def rhobundle_zip_url
|
216
|
-
@@rhobundle_zip_url
|
217
|
-
end
|
218
|
-
|
219
|
-
def rhobundle_zip_url=(url=nil)
|
220
|
-
@@rhobundle_zip_url = url
|
221
|
-
end
|
222
|
-
|
223
|
-
def rhobundle_zip_pwd
|
224
|
-
@@rhobundle_zip_pwd
|
225
|
-
end
|
226
|
-
|
227
|
-
def rhobundle_zip_pwd=(pwd=nil)
|
228
|
-
@@rhobundle_zip_pwd = pwd
|
229
|
-
end
|
230
|
-
|
231
|
-
def add_source(modelname, new_source=nil)
|
232
|
-
if new_source
|
233
|
-
unless @@sources[new_source]
|
234
|
-
@@sources[modelname] = new_source
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end # RhoConfig
|
240
|
-
end # Rho
|
data/lib/rho/rhoapplication.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'rhom'
|
2
|
-
require 'rhofsconnector'
|
3
|
-
|
4
|
-
module Rho
|
5
|
-
class RhoApplication
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
if @rhom.nil?
|
9
|
-
@rhom = Rhom::Rhom.new
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class << self
|
14
|
-
|
15
|
-
def get_app_path(appname)
|
16
|
-
Rho::RhoFSConnector::get_app_path(appname)
|
17
|
-
end
|
18
|
-
|
19
|
-
def get_base_app_path
|
20
|
-
Rho::RhoFSConnector::get_base_app_path
|
21
|
-
end
|
22
|
-
|
23
|
-
def get_model_path(appname, modelname)
|
24
|
-
Rho::RhoFSConnector::get_model_path(appname, modelname)
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def serve(req,res)
|
30
|
-
req[:modelpath] = self.class.get_model_path req['application'], req['model']
|
31
|
-
require req[:modelpath]+'controller'
|
32
|
-
res['request-body'] = (Object.const_get(req['model']+'Controller').new).send :serve, @rhom, req, res
|
33
|
-
end
|
34
|
-
|
35
|
-
end # RhoApplication
|
36
|
-
end # Rho
|
data/lib/rho/rhocontact.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'bsearch'
|
2
|
-
|
3
|
-
module Rho
|
4
|
-
class RhoContact
|
5
|
-
class << self
|
6
|
-
def find(param)
|
7
|
-
pb = Phonebook::openPhonebook
|
8
|
-
if pb.nil?
|
9
|
-
puts "Can't open phonebook"
|
10
|
-
return nil
|
11
|
-
elsif param == :all or param == 'all'
|
12
|
-
records = Phonebook::getallPhonebookRecords(pb)
|
13
|
-
Phonebook::closePhonebook(pb)
|
14
|
-
return records
|
15
|
-
else
|
16
|
-
record = Phonebook::getPhonebookRecord(pb,param)
|
17
|
-
Phonebook::closePhonebook(pb)
|
18
|
-
return record
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def create!(properties)
|
23
|
-
pb = Phonebook::openPhonebook
|
24
|
-
unless pb.nil?
|
25
|
-
record = Phonebook::createRecord(pb)
|
26
|
-
if record.nil?
|
27
|
-
puts "Can't find record " + properties['id']
|
28
|
-
else
|
29
|
-
properties.each do |key,value|
|
30
|
-
Phonebook::setRecordValue(record,key,value)
|
31
|
-
end
|
32
|
-
Phonebook::addRecord(pb,record)
|
33
|
-
end
|
34
|
-
Phonebook::closePhonebook(pb)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def destroy(recordId)
|
39
|
-
pb = Phonebook::openPhonebook
|
40
|
-
unless pb.nil?
|
41
|
-
record = Phonebook::openPhonebookRecord(pb,recordId)
|
42
|
-
if record.nil?
|
43
|
-
puts "Can't find record " + recordId
|
44
|
-
else
|
45
|
-
Phonebook::deleteRecord(pb,record)
|
46
|
-
end
|
47
|
-
Phonebook::closePhonebook(pb)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def update_attributes(properties)
|
52
|
-
pb = Phonebook::openPhonebook
|
53
|
-
unless pb.nil?
|
54
|
-
record = Phonebook::openPhonebookRecord(pb,properties['id'])
|
55
|
-
if record.nil?
|
56
|
-
puts "Can't find record " + properties['id']
|
57
|
-
else
|
58
|
-
properties.each do |key,value|
|
59
|
-
Phonebook::setRecordValue(record,key,value)
|
60
|
-
end
|
61
|
-
Phonebook::saveRecord(pb,record)
|
62
|
-
end
|
63
|
-
Phonebook::closePhonebook(pb)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Examples of how to use select method:
|
68
|
-
#
|
69
|
-
# selected = Rho::RhoContact.select('first_name' => 'David') { |x| x[1]['last_name']=='Taylor' }
|
70
|
-
# ==> returns record(s) of the David Taylor
|
71
|
-
#
|
72
|
-
# selected = Rho::RhoContact.select('first_name' => 'Kate')
|
73
|
-
# ==> Returns all records of Kate
|
74
|
-
#
|
75
|
-
# selected = Rho::RhoContact.select('last_name' => 'User') do |x|
|
76
|
-
# x[1]['first_name']=='Test' and x[1]['company_name']=="rhomobile"
|
77
|
-
# end
|
78
|
-
# ==> returns all records of the Test User from the company rhomobile
|
79
|
-
#
|
80
|
-
def select(index, &block)
|
81
|
-
key, value = index.keys[0], index.values[0]
|
82
|
-
if @contacts.nil? or @key != key
|
83
|
-
@key, @contacts = key, find(:all).to_a.sort! {|x,y| x[1][key] <=> y[1][key] }
|
84
|
-
end
|
85
|
-
found = @contacts[@contacts.bsearch_range {|x| x[1][key] <=> value}]
|
86
|
-
unless found.nil? or block.nil?
|
87
|
-
return found.select(&block)
|
88
|
-
end
|
89
|
-
return found
|
90
|
-
end
|
91
|
-
|
92
|
-
def select_by_name(first_last_name, &block)
|
93
|
-
if @contacts.nil?
|
94
|
-
@contacts = find(:all).to_a.sort! do |x,y|
|
95
|
-
x[1]['first_name'] + " " + x[1]['last_name'] <=> y[1]['first_name'] + " " + y[1]['last_name']
|
96
|
-
end
|
97
|
-
end
|
98
|
-
range = @contacts.bsearch_range do |x|
|
99
|
-
x[1]['first_name'] + " " + x[1]['last_name'] <=> first_last_name
|
100
|
-
end
|
101
|
-
found = @contacts[range]
|
102
|
-
unless found.nil? or block.nil?
|
103
|
-
return found.select(&block)
|
104
|
-
end
|
105
|
-
return found
|
106
|
-
end
|
107
|
-
|
108
|
-
end #<< self
|
109
|
-
end # class RhoContact
|
110
|
-
end # module Rho
|
data/lib/rho/rhocontroller.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'rho/render'
|
2
|
-
require 'rho/rhosupport'
|
3
|
-
require 'rho/rhoviewhelpers'
|
4
|
-
|
5
|
-
module Rho
|
6
|
-
class RhoController
|
7
|
-
|
8
|
-
def default_action
|
9
|
-
return Hash['GET','show','PUT','update','POST','update',
|
10
|
-
'DELETE','delete'][@request['request-method']] unless @request['id'].nil?
|
11
|
-
return Hash['GET','index','POST','create'][@request['request-method']]
|
12
|
-
end
|
13
|
-
|
14
|
-
def serve(object_mapping,req,res)
|
15
|
-
@request, @response = req, res;
|
16
|
-
@object_mapping = object_mapping
|
17
|
-
@params = RhoSupport::query_params req
|
18
|
-
send req['action'].nil? ? default_action : req['action']
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns true if the request's header contains "XMLHttpRequest".
|
22
|
-
def xml_http_request?
|
23
|
-
not /XMLHttpRequest/i.match(@request['headers']['X-Requested-With']).nil?
|
24
|
-
end
|
25
|
-
alias xhr? :xml_http_request?
|
26
|
-
|
27
|
-
def redirect(url_params = {},options = {})
|
28
|
-
@response['status'] = options['status'] || 302
|
29
|
-
@response['headers']['Location'] = url_for(url_params)
|
30
|
-
@response['message'] = options['message'] || 'Moved temporarily'
|
31
|
-
return ''
|
32
|
-
end
|
33
|
-
|
34
|
-
end # RhoController
|
35
|
-
end # Rho
|