plezi 0.10.10 → 0.10.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/bin/plezi +33 -59
- data/lib/plezi/common/cache.rb +2 -2
- data/lib/plezi/common/dsl.rb +13 -7
- data/lib/plezi/handlers/http_router.rb +1 -1
- data/lib/plezi/version.rb +1 -1
- data/plezi.gemspec +1 -1
- data/resources/mini_app.rb +77 -0
- data/resources/mini_exec.rb +5 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ae320b0b94bf0515e804c8f578919e46147d349
|
4
|
+
data.tar.gz: b82256beacdbd56c48b66755d4b086d0293452fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebeaa5a013faf936e694f5d54fd212d1c299f015631f63667c0e0419958321f86086f8087d94111c194656247101d3d65f621fe15177a2931a83199d0ed3be76
|
7
|
+
data.tar.gz: 8df8144823d9be37ecd9d8d89e01b116c5aed875188781ea5953961b022b5c8765ca84b4c312b20fb2c98ca132f819aa8f296140ea718346d3af914227b3a5c2
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
***
|
4
4
|
|
5
|
+
Change log v.0.10.11
|
6
|
+
|
7
|
+
**Feature**: added the mini-app template, for quick websocket oriented apps that are meant to be attached to other frameworks (use `$ plezi mini appname` or `$ plezi m appname`).
|
8
|
+
|
9
|
+
**Feature**: allow Regexp hosts in the `listen` and `host` methods.
|
10
|
+
|
11
|
+
**Fix**: An error in the chache system was introduced when performing slight performance enhancements (two variable names were switched). The issue is now fixed.
|
12
|
+
|
13
|
+
**Fix**: Correctly handle multiple `listen` calls with the same port number.
|
14
|
+
|
15
|
+
***
|
16
|
+
|
5
17
|
Change log v.0.10.10
|
6
18
|
|
7
19
|
**Fix**: Autopinging wasn't senf doe to a typo (`unless` instead of `if`).. this is now fixed. Autopinging will keep your Websocket connections alive.
|
data/bin/plezi
CHANGED
@@ -34,10 +34,28 @@ require 'securerandom'
|
|
34
34
|
class AppTemplate
|
35
35
|
|
36
36
|
def initialize
|
37
|
-
require 'rubygems'
|
38
|
-
# set end comments
|
39
37
|
@end_comments = []
|
40
38
|
@app_tree ||= {}
|
39
|
+
end
|
40
|
+
def app_tree
|
41
|
+
@app_tree ||= {}
|
42
|
+
end
|
43
|
+
def build_mini
|
44
|
+
require 'plezi/version'
|
45
|
+
@app_tree["#{ARGV[1]}"] ||= IO.read( ::File.expand_path(File.join("..", "..", "resources" ,"mini_exec.rb"), __FILE__)).gsub('appname', ARGV[1])
|
46
|
+
@app_tree["#{ARGV[1]}.rb"] ||= IO.read( ::File.expand_path(File.join("..", "..", "resources" ,"mini_app.rb"), __FILE__)).gsub('appname', ARGV[1]).gsub('appsecret', "#{ARGV[1]}_#{SecureRandom.hex}")
|
47
|
+
app_tree["Procfile"] ||= ""
|
48
|
+
app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{ARGV[1]} -p $PORT\n"
|
49
|
+
app_tree["Gemfile"] ||= ''
|
50
|
+
app_tree["Gemfile"] << "source 'https://rubygems.org'\n\n####################\n# core gems\n\n# include the basic plezi framework and server\ngem 'plezi', '~> #{Plezi::VERSION}'\n"
|
51
|
+
app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
|
52
|
+
finalize
|
53
|
+
end
|
54
|
+
|
55
|
+
def build
|
56
|
+
require 'plezi/version'
|
57
|
+
# plezi run script
|
58
|
+
@app_tree["#{ARGV[1]}"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"code.rb"), __FILE__)
|
41
59
|
|
42
60
|
# set up application files
|
43
61
|
app_tree["app"] ||= {}
|
@@ -68,10 +86,11 @@ class AppTemplate
|
|
68
86
|
app_tree["routes.rb"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"routes.rb"), __FILE__)
|
69
87
|
app_tree["rakefile"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"rakefile"), __FILE__)
|
70
88
|
app_tree["Procfile"] ||= ""
|
71
|
-
app_tree["Procfile"] << "\nweb: bundle exec ./#{ARGV[1]} -p $PORT\n"
|
89
|
+
app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{ARGV[1]} -p $PORT\n"
|
72
90
|
app_tree["Gemfile"] ||= ''
|
73
91
|
app_tree["Gemfile"] << "source 'https://rubygems.org'\n\n####################\n# core gems\n\n# include the basic plezi framework and server\ngem 'plezi', '~> #{Plezi::VERSION}'\n"
|
74
92
|
app_tree["Gemfile"] << IO.read( ::File.expand_path(File.join("..", "..", "resources" ,"Gemfile"), __FILE__))
|
93
|
+
app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
|
75
94
|
|
76
95
|
# set up config files
|
77
96
|
app_tree["config"] ||= {}
|
@@ -108,17 +127,10 @@ class AppTemplate
|
|
108
127
|
app_tree["public"]["assets"] ||= {}
|
109
128
|
app_tree["public"]["assets"]["stylesheets"] ||= {}
|
110
129
|
app_tree["public"]["assets"]["javascripts"] ||= {}
|
111
|
-
app_tree["public"]["images"] ||= {}
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
def app_tree
|
116
|
-
@app_tree ||= {}
|
130
|
+
app_tree["public"]["images"] ||= {}
|
131
|
+
finalize
|
117
132
|
end
|
118
|
-
def
|
119
|
-
# require 'pry'
|
120
|
-
# binding.pry
|
121
|
-
app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
|
133
|
+
def finalize
|
122
134
|
begin
|
123
135
|
Dir.mkdir ARGV[1]
|
124
136
|
puts "created the #{ARGV[1]} application directory.".green
|
@@ -128,7 +140,6 @@ class AppTemplate
|
|
128
140
|
Dir.chdir ARGV[1]
|
129
141
|
puts "starting to write template data...".red
|
130
142
|
puts ""
|
131
|
-
@app_tree["#{ARGV[1]}"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"code.rb"), __FILE__)
|
132
143
|
write_files app_tree
|
133
144
|
File.chmod 0775, "#{ARGV[1]}"
|
134
145
|
puts "tried to update execution permissions. this is system dependent and might have failed.".pink
|
@@ -216,10 +227,9 @@ end
|
|
216
227
|
|
217
228
|
# require 'optparser'
|
218
229
|
|
219
|
-
if ARGV[0] == 'new' || ARGV[0] == 'n' || ARGV[0] == "force"
|
230
|
+
if ARGV[0] == 'new' || ARGV[0] == 'n' || ARGV[0] == "force" || ARGV[0] == 'mini' || ARGV[0] == 'm'
|
220
231
|
#########
|
221
232
|
## set up building environment
|
222
|
-
require 'plezi/version'
|
223
233
|
NO_PLEZI_AUTO_START = true
|
224
234
|
ARGV[1] = ARGV[1].gsub /[^a-zA-Z0-9]/, '_'
|
225
235
|
if Dir.exists?(ARGV[1]) && ARGV[0] != "force"
|
@@ -234,39 +244,9 @@ if ARGV[0] == 'new' || ARGV[0] == 'n' || ARGV[0] == "force"
|
|
234
244
|
Dir.chdir '..'
|
235
245
|
end
|
236
246
|
|
237
|
-
if ARGV.count > 3 && (ARGV[2] == 'with' || ARGV[2] == 'w')
|
238
|
-
|
239
|
-
# gem loading
|
240
|
-
local_gems = Gem::Specification.map {|g| g.name}
|
241
|
-
# this will load all requested gems and allow them to update the AppTemplate
|
242
|
-
if ARGV[3] == "all"
|
243
|
-
puts "loading gems and giving each gem a chance to update the app template:".yellow
|
244
|
-
local_gems.each do |g|
|
245
|
-
begin
|
246
|
-
puts "loaded the #{g} gem." if require g
|
247
|
-
rescue Exception => e
|
248
|
-
puts "couldn't load the #{g} gem... moving on.".red
|
249
|
-
end
|
250
|
-
end
|
251
|
-
else
|
252
|
-
require 'pathname'
|
253
|
-
ARGV[3..-1].each do |g|
|
254
|
-
if local_gems.include? g
|
255
|
-
require g
|
256
|
-
puts "loaded the #{g} gem, and gave it a change to update the template."
|
257
|
-
else
|
258
|
-
puts "Error, the gem: #{g} could not be found!".red
|
259
|
-
puts "try first running: gem install #{g}".green
|
260
|
-
exit
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
true
|
265
|
-
end
|
266
|
-
|
267
247
|
# building
|
268
248
|
template = AppTemplate.new
|
269
|
-
template.build
|
249
|
+
(ARGV[0] == 'mini' || ARGV[0] == 'm' ) ? template.build_mini : template.build
|
270
250
|
elsif ARGV[0] == 'server' || ARGV[0] == 'start' || ARGV[0] == 's'
|
271
251
|
ARGV.shift
|
272
252
|
load File.expand_path(Dir["."][0], (File.expand_path(Dir["."][0]).split(/[\\\/]/).last) ) rescue load( File.expand_path(Dir["."][0], (File.expand_path(Dir["."][0]).split(/[\\\/]/).last ) ) )
|
@@ -288,25 +268,19 @@ else
|
|
288
268
|
puts "option description".yellow
|
289
269
|
puts "new <appname> creates a new application called <appname>."
|
290
270
|
puts "n alias for new."
|
291
|
-
puts "
|
271
|
+
puts "mini <appname> creates a new mini-application called <appname>."
|
272
|
+
puts "m alias for mini."
|
292
273
|
puts "starting up an app:".pink
|
293
|
-
puts "start
|
274
|
+
puts "start attempts to run the app. accepts any parameters the app supports."
|
294
275
|
puts "s alias for start/server."
|
295
276
|
puts "start console innsead of services:".pink
|
296
277
|
puts "console runs the app. accepts any parameters the app supports."
|
297
278
|
puts "c alias for start/server."
|
298
279
|
puts "==============================".green
|
299
|
-
puts "create an app with specific plugins:".pink
|
300
|
-
puts "plezi new app with gem1 gem2"
|
301
|
-
puts "loads the specific gem(s) and allows them to update the template before building the app.".green
|
302
|
-
puts ""
|
303
|
-
puts "create an app with ALL plugins:".pink
|
304
|
-
puts "plezi n app w all"
|
305
|
-
puts "loads the all available gem(s) and allows them to update the template before building the app.".green
|
306
280
|
puts ""
|
307
|
-
puts "
|
308
|
-
puts "
|
309
|
-
puts "
|
281
|
+
puts "Run the app using the app's script with an optional: -p {port number}. i.e."
|
282
|
+
puts " cd ./appname".pink
|
283
|
+
puts " ./appname -p 8080".pink
|
310
284
|
puts ""
|
311
285
|
end
|
312
286
|
|
data/lib/plezi/common/cache.rb
CHANGED
data/lib/plezi/common/dsl.rb
CHANGED
@@ -32,12 +32,6 @@ module Plezi
|
|
32
32
|
# ssl_key:: the public key for the SSL service.
|
33
33
|
# ssl_cert:: the certificate for the SSL service.
|
34
34
|
#
|
35
|
-
# some further options, which are unstable and might be removed in future versions, are:
|
36
|
-
# protocol:: the protocol objects (usually a class, but any object answering `#call` will do).
|
37
|
-
# handler:: an optional handling object, to be called upon by the protocol (i.e. #on_message, #on_connect, etc'). this option is used to allow easy protocol switching, such as from HTTP to Websockets.
|
38
|
-
#
|
39
|
-
# Duringn normal Plezi behavior, the optional `handler` object will be returned if `listen` is called more than once for the same port.
|
40
|
-
#
|
41
35
|
# assets:
|
42
36
|
#
|
43
37
|
# assets support will render `.sass`, `.scss` and `.coffee` and save them as local files (`.css`, `.css`, and `.js` respectively)
|
@@ -55,6 +49,18 @@ module Plezi
|
|
55
49
|
parameters[:assets_public] ||= '/assets'
|
56
50
|
parameters[:assets_public].chomp! '/'
|
57
51
|
|
52
|
+
if !parameters[:port] && defined? ARGV
|
53
|
+
if ARGV.find_index('-p')
|
54
|
+
port_index = ARGV.find_index('-p') + 1
|
55
|
+
parameters[:port] ||= ARGV[port_index].to_i
|
56
|
+
ARGV[port_index] = (parameters[:port] + 1).to_s
|
57
|
+
else
|
58
|
+
ARGV << '-p'
|
59
|
+
ARGV << '3001'
|
60
|
+
parameters[:port] ||= 3000
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
58
64
|
#keeps information of past ports.
|
59
65
|
@listeners ||= {}
|
60
66
|
@listeners_locker = Mutex.new
|
@@ -63,7 +69,7 @@ module Plezi
|
|
63
69
|
@listeners_locker.synchronize do
|
64
70
|
if @listeners[parameters[:port]]
|
65
71
|
puts "WARNING: port aleady in use! returning existing service and attemptin to add host (maybe multiple hosts? use `host` instead)."
|
66
|
-
@active_router = @listeners[parameters[:port]]
|
72
|
+
@active_router = @listeners[parameters[:port]][:http_handler]
|
67
73
|
@active_router.add_host parameters[:host], parameters if @active_router.is_a?(HTTPRouter)
|
68
74
|
return @active_router
|
69
75
|
end
|
@@ -40,7 +40,7 @@ module Plezi
|
|
40
40
|
|
41
41
|
# adds a host to the router (or activates an existing host to add new routes). accepts a host name and any parameters not related to the actual connection (ssl etc') (see {Plezi.listen})
|
42
42
|
def add_host host_name, params = {}
|
43
|
-
host_name = (host_name ? host_name.to_s.downcase : :default)
|
43
|
+
host_name = (host_name ? (host_name.is_a?(String) ? host_name.to_s.downcase : host_name) : :default)
|
44
44
|
@active_host = get_host(host_name) || ( @hosts[host_name] = Host.new(params) )
|
45
45
|
add_alias host_name, *params[:alias] if params[:alias]
|
46
46
|
@active_host
|
data/lib/plezi/version.rb
CHANGED
data/plezi.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "grhttp", "~> 0.0.
|
21
|
+
spec.add_dependency "grhttp", "~> 0.0.14"
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.7"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
## Set working directory, load gems and create logs
|
4
|
+
# Using pathname extentions for setting public folder
|
5
|
+
require 'pathname'
|
6
|
+
#set up root object, it might be used by the environment and\or the plezi extension gems.
|
7
|
+
Root ||= Pathname.new(File.dirname(__FILE__)).expand_path
|
8
|
+
# make sure all file access and file loading is relative to the application's root folder
|
9
|
+
Dir.chdir Root.to_s
|
10
|
+
# using bundler to load gems (including the plezi gem)
|
11
|
+
require 'bundler'
|
12
|
+
Bundler.require(:default, ENV['ENV'].to_s.to_sym)
|
13
|
+
## uncomment to create a log file
|
14
|
+
# GReactor.create_logger File.expand_path(Root.join('server.log').to_s)
|
15
|
+
|
16
|
+
## Options for Scaling the app (across processes or machines):
|
17
|
+
## uncomment to set up forking.
|
18
|
+
# GReactor::Settings.set_forking 4
|
19
|
+
## Redis scaling
|
20
|
+
# Plezi::Settings.redis_channel_name = 'appsecret'
|
21
|
+
# ENV['PL_REDIS_URL'] ||= ENV['REDIS_URL'] || ENV['REDISCLOUD_URL'] || ENV['REDISTOGO_URL'] || "redis://username:password@my.host:6389"
|
22
|
+
|
23
|
+
|
24
|
+
# The basic appname controller, to get you started
|
25
|
+
class MyController
|
26
|
+
# HTTP
|
27
|
+
def index
|
28
|
+
"Hello World!\r\n\r\nThis appname mini-app is an example hello world and websocket chatroom.\r\n
|
29
|
+
\r\nplease visit http://www.websocket.org/echo.html and connect to: ws://localhost:3000/nickname"
|
30
|
+
end
|
31
|
+
def websockets
|
32
|
+
redirect_to "http://www.websocket.org/echo.html"
|
33
|
+
end
|
34
|
+
# Websockets
|
35
|
+
def on_message data
|
36
|
+
data = "#{params[:id]}: #{data}" if params[:id]
|
37
|
+
_print data
|
38
|
+
broadcast :_print, data
|
39
|
+
end
|
40
|
+
def on_open
|
41
|
+
_print 'Welcome!'
|
42
|
+
broadcast :_print, "Somebody joind us :-)"
|
43
|
+
end
|
44
|
+
def on_close
|
45
|
+
broadcast :_print, "Somebody left us :-("
|
46
|
+
end
|
47
|
+
def _print data
|
48
|
+
response << data
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# start a web service to listen on the first default port (3000 or the port set by the command-line).
|
54
|
+
# you can change some of the default settings here.
|
55
|
+
listen host: :default,
|
56
|
+
# root: Root.join('public').to_s,
|
57
|
+
# assets: Root.join('assets').to_s,
|
58
|
+
# assets_public: '/assets',
|
59
|
+
# templates: Root.join('app','views').to_s,
|
60
|
+
ssl: false
|
61
|
+
|
62
|
+
## Optional stuff:
|
63
|
+
## I18n re-write, i.e.: `/en/home` will be rewriten as `/home`, while setting params[:locale] to "en"
|
64
|
+
# route "/:locale{#{I18n.available_locales.join "|"}}/*" , false if defined? I18n
|
65
|
+
#
|
66
|
+
## OAuth2 - Facebook / Google authentication
|
67
|
+
# require 'plezi/oauth'
|
68
|
+
# ENV["FB_APP_ID"] ||= "app id"; ENV["FB_APP_SECRET"] ||= "secret"; ENV['GOOGLE_APP_ID'] = "app id"; ENV['GOOGLE_APP_SECRET'] = "secret"
|
69
|
+
# create_auth_shared_route do |service_name, auth_token, remote_user_id, remote_user_email, remote_response|
|
70
|
+
# # ...callback for authentication.
|
71
|
+
# # This callback should return the app user object or false
|
72
|
+
# # This callback has access to the controller's methods (request, cookies, response, etc')
|
73
|
+
# end
|
74
|
+
|
75
|
+
# Add your routes and controllers by order of priority.
|
76
|
+
route '/(:id)', MyController
|
77
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plezi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boaz Segev
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
19
|
+
version: 0.0.14
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
26
|
+
version: 0.0.14
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +107,8 @@ files:
|
|
107
107
|
- resources/environment.rb
|
108
108
|
- resources/haml_config.rb
|
109
109
|
- resources/i18n_config.rb
|
110
|
+
- resources/mini_app.rb
|
111
|
+
- resources/mini_exec.rb
|
110
112
|
- resources/oauth_config.rb
|
111
113
|
- resources/plezi_websockets.html
|
112
114
|
- resources/rakefile
|