plezi 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/CHANGELOG.md +450 -0
  4. data/Gemfile +4 -0
  5. data/KNOWN_ISSUES.md +13 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +341 -0
  8. data/Rakefile +2 -0
  9. data/TODO.md +19 -0
  10. data/bin/plezi +301 -0
  11. data/lib/plezi.rb +125 -0
  12. data/lib/plezi/base/cache.rb +77 -0
  13. data/lib/plezi/base/connections.rb +33 -0
  14. data/lib/plezi/base/dsl.rb +177 -0
  15. data/lib/plezi/base/engine.rb +85 -0
  16. data/lib/plezi/base/events.rb +84 -0
  17. data/lib/plezi/base/io_reactor.rb +41 -0
  18. data/lib/plezi/base/logging.rb +62 -0
  19. data/lib/plezi/base/rack_app.rb +89 -0
  20. data/lib/plezi/base/services.rb +57 -0
  21. data/lib/plezi/base/timers.rb +71 -0
  22. data/lib/plezi/handlers/controller_magic.rb +383 -0
  23. data/lib/plezi/handlers/http_echo.rb +27 -0
  24. data/lib/plezi/handlers/http_host.rb +215 -0
  25. data/lib/plezi/handlers/http_router.rb +69 -0
  26. data/lib/plezi/handlers/magic_helpers.rb +43 -0
  27. data/lib/plezi/handlers/route.rb +272 -0
  28. data/lib/plezi/handlers/stubs.rb +143 -0
  29. data/lib/plezi/server/README.md +33 -0
  30. data/lib/plezi/server/helpers/http.rb +169 -0
  31. data/lib/plezi/server/helpers/mime_types.rb +999 -0
  32. data/lib/plezi/server/protocols/http_protocol.rb +318 -0
  33. data/lib/plezi/server/protocols/http_request.rb +133 -0
  34. data/lib/plezi/server/protocols/http_response.rb +294 -0
  35. data/lib/plezi/server/protocols/websocket.rb +208 -0
  36. data/lib/plezi/server/protocols/ws_response.rb +92 -0
  37. data/lib/plezi/server/services/basic_service.rb +224 -0
  38. data/lib/plezi/server/services/no_service.rb +196 -0
  39. data/lib/plezi/server/services/ssl_service.rb +193 -0
  40. data/lib/plezi/version.rb +3 -0
  41. data/plezi.gemspec +26 -0
  42. data/resources/404.erb +68 -0
  43. data/resources/404.haml +64 -0
  44. data/resources/404.html +67 -0
  45. data/resources/404.slim +63 -0
  46. data/resources/500.erb +68 -0
  47. data/resources/500.haml +63 -0
  48. data/resources/500.html +67 -0
  49. data/resources/500.slim +63 -0
  50. data/resources/Gemfile +85 -0
  51. data/resources/anorexic_gray.png +0 -0
  52. data/resources/anorexic_websockets.html +47 -0
  53. data/resources/code.rb +8 -0
  54. data/resources/config.ru +39 -0
  55. data/resources/controller.rb +139 -0
  56. data/resources/db_ac_config.rb +58 -0
  57. data/resources/db_dm_config.rb +51 -0
  58. data/resources/db_sequel_config.rb +42 -0
  59. data/resources/en.yml +204 -0
  60. data/resources/environment.rb +41 -0
  61. data/resources/haml_config.rb +6 -0
  62. data/resources/i18n_config.rb +14 -0
  63. data/resources/rakefile.rb +22 -0
  64. data/resources/redis_config.rb +35 -0
  65. data/resources/routes.rb +26 -0
  66. data/resources/welcome_page.html +72 -0
  67. data/websocket chatroom.md +639 -0
  68. metadata +141 -0
@@ -0,0 +1,68 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <style>
4
+ body, html
5
+ {
6
+ background-color: #eee;
7
+ padding: 0; margin: 0;
8
+ width: 100%;
9
+ }
10
+ h1
11
+ {
12
+ background-color: #ddd;
13
+ color: #008;
14
+ text-align: center;
15
+ border-bottom: 1px solid #000;
16
+ margin: 0;
17
+ padding: 0.5em;
18
+ width: auto;
19
+ }
20
+ p
21
+ {
22
+ color:#004;
23
+ font-size: 1.2em;
24
+ padding: 0 1em;
25
+ }
26
+ #wrapper
27
+ {
28
+ background-color: #fff;
29
+ margin: 1em 5%;
30
+ padding: 0 0 2% 0;
31
+ border-radius: 20px;
32
+ min-height: 50%;
33
+ color: #007;
34
+ }
35
+ #wrapper h2
36
+ {
37
+ background-color: #ddd;
38
+ color: #008;
39
+ text-align: center;
40
+ margin: 0 0 1em 0;
41
+ padding: 0.5em 0;
42
+ width: 100%;
43
+ border-radius: 20px;
44
+ }
45
+ #wrapper p{ padding: 0 2%;}
46
+ #wrapper #missing
47
+ {
48
+ color:#904;
49
+ font-size: 1.4em;
50
+ padding: 0.5em 0;
51
+ text-align: center;
52
+ background-color: #fee;
53
+ border-bottom: 1px solid #800;
54
+ margin: 0;
55
+ }
56
+ </style>
57
+ </head>
58
+ <body>
59
+ <h1>Plezi 500 error code (broken?!)...</h1>
60
+ <div id='wrapper'>
61
+ <h2 id='missing'>
62
+ something went wrong with:
63
+ <%= defined?(request) ? request.path : "what you're looking for..." %>
64
+ </h2>
65
+ <p>Sorry, something went wrong trying to process your request...</p>
66
+ <p>.... Please try again soon and if this issue persists, please let us know.</p>
67
+ </div>
68
+ </body>
@@ -0,0 +1,63 @@
1
+ !!!5
2
+ %head
3
+ :css
4
+ body, html
5
+ {
6
+ background-color: #eee;
7
+ padding: 0; margin: 0;
8
+ width: 100%;
9
+ }
10
+ h1
11
+ {
12
+ background-color: #ddd;
13
+ color: #008;
14
+ text-align: center;
15
+ border-bottom: 1px solid #000;
16
+ margin: 0;
17
+ padding: 0.5em;
18
+ width: auto;
19
+ }
20
+ p
21
+ {
22
+ color:#004;
23
+ font-size: 1.2em;
24
+ padding: 0 1em;
25
+ }
26
+ #wrapper
27
+ {
28
+ background-color: #fff;
29
+ margin: 1em 5%;
30
+ padding: 0 0 2% 0;
31
+ border-radius: 20px;
32
+ min-height: 50%;
33
+ color: #007;
34
+ }
35
+ #wrapper h2
36
+ {
37
+ background-color: #ddd;
38
+ color: #008;
39
+ text-align: center;
40
+ margin: 0 0 1em 0;
41
+ padding: 0.5em 0;
42
+ width: 100%;
43
+ border-radius: 20px;
44
+ }
45
+ #wrapper p{ padding: 0 2%;}
46
+ #wrapper #missing
47
+ {
48
+ color:#904;
49
+ font-size: 1.4em;
50
+ padding: 0.5em 0;
51
+ text-align: center;
52
+ background-color: #fee;
53
+ border-bottom: 1px solid #800;
54
+ margin: 0;
55
+ }
56
+ %body
57
+ %h1< Plezi 500 error code (broken?!)...
58
+ #wrapper
59
+ %h2#missing
60
+ something went wrong with:
61
+ = defined?(request) ? request.path : "what you're looking for..."
62
+ %p Sorry, something went wrong trying to process your request...
63
+ %p ... Please try again soon and if this issue persists, please let us know.
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <style>
4
+ body, html
5
+ {
6
+ background-color: #eee;
7
+ padding: 0; margin: 0;
8
+ width: 100%;
9
+ }
10
+ h1
11
+ {
12
+ background-color: #ddd;
13
+ color: #008;
14
+ text-align: center;
15
+ border-bottom: 1px solid #000;
16
+ margin: 0;
17
+ padding: 0.5em;
18
+ width: 100%;
19
+ }
20
+ p
21
+ {
22
+ color:#004;
23
+ font-size: 1.2em;
24
+ padding: 0 1em;
25
+ }
26
+ #wrapper
27
+ {
28
+ background-color: #fff;
29
+ margin: 1em 5%;
30
+ padding: 0 0 2%;
31
+ border-radius: 20px;
32
+ height: auto;
33
+ color: #007;
34
+ }
35
+ #wrapper h2
36
+ {
37
+ background-color: #ddd;
38
+ color: #008;
39
+ text-align: center;
40
+ margin: 0 0 1em 0;
41
+ padding: 0.5em 0;
42
+ width: 100%;
43
+ border-radius: 20px;
44
+ }
45
+ #wrapper p{ padding: 0 2%;}
46
+ #wrapper #missing
47
+ {
48
+ color:#904;
49
+ font-size: 1.4em;
50
+ padding: 0.5em 0;
51
+ text-align: center;
52
+ background-color: #fee;
53
+ border-bottom: 1px solid #800;
54
+ margin: 0;
55
+ }
56
+ </style>
57
+ </head>
58
+ <body>
59
+ <h1>Plezi 500 error code (broken?!)...</h1>
60
+ <div id='wrapper'>
61
+ <h2 id='missing'>
62
+ something went wrong with your request...
63
+ </h2>
64
+ <p>Sorry, something went wrong trying to process your request...</p>
65
+ <p>.... Please try again soon and if this issue persists, please let us know.</p>
66
+ </div>
67
+ </body>
@@ -0,0 +1,63 @@
1
+ doctype html
2
+ head
3
+ css:
4
+ body, html
5
+ {
6
+ background-color: #eee;
7
+ padding: 0; margin: 0;
8
+ width: 100%;
9
+ }
10
+ h1
11
+ {
12
+ background-color: #ddd;
13
+ color: #008;
14
+ text-align: center;
15
+ border-bottom: 1px solid #000;
16
+ margin: 0;
17
+ padding: 0.5em;
18
+ width: auto;
19
+ }
20
+ p
21
+ {
22
+ color:#004;
23
+ font-size: 1.2em;
24
+ padding: 0 1em;
25
+ }
26
+ #wrapper
27
+ {
28
+ background-color: #fff;
29
+ margin: 1em 5%;
30
+ padding: 0 0 2% 0;
31
+ border-radius: 20px;
32
+ min-height: 50%;
33
+ color: #007;
34
+ }
35
+ #wrapper h2
36
+ {
37
+ background-color: #ddd;
38
+ color: #008;
39
+ text-align: center;
40
+ margin: 0 0 1em 0;
41
+ padding: 0.5em 0;
42
+ width: 100%;
43
+ border-radius: 20px;
44
+ }
45
+ #wrapper p { padding: 0 2%; }
46
+ #wrapper #missing
47
+ {
48
+ color:#904;
49
+ font-size: 1.4em;
50
+ padding: 0.5em 0;
51
+ text-align: center;
52
+ background-color: #fee;
53
+ border-bottom: 1px solid #800;
54
+ margin: 0;
55
+ }
56
+ body
57
+ h1 Plezi 500 error code (broken?!)...
58
+ #wrapper
59
+ h2#missing
60
+ | something went wrong with:
61
+ =< defined?(request) ? request.path : "what you're looking for..."
62
+ p Sorry, something went wrong trying to process your request...
63
+ p ... Please try again soon and if this issue persists, please let us know.
@@ -0,0 +1,85 @@
1
+ source "https://rubygems.org"
2
+
3
+ ####################
4
+ # core gems
5
+
6
+ # include the basic plezi framework and server
7
+ gem 'plezi'
8
+
9
+ ####################
10
+ # development gems
11
+
12
+ # use pry gem for basic debug ( put `binding.pry` at breake point )?
13
+ # gem 'pry'
14
+
15
+
16
+ # active support can run without rails and extends the Ruby language.
17
+ # it might be heavy, be warned.
18
+ # see: http://guides.rubyonrails.org/active_support_core_extensions.html
19
+ #
20
+ # gem 'activesupport', :require => ['active_support', 'active_support/core_ext']
21
+ # or:
22
+ # gem 'activesupport', :require => ['active_support', active_support/all']
23
+
24
+
25
+ ####################
26
+ # gems for easy markup
27
+
28
+ ## Slim is very recommended for HTML markup, it's both easy and fast.
29
+ # gem 'slim'
30
+
31
+ ## Sass makes CSS easy
32
+ # gem "sass"
33
+
34
+ ## erb for HTML fanatics:
35
+ # gem 'erb'
36
+
37
+ ## we love Haml, even though it can be slow:
38
+ # gem 'haml'
39
+
40
+ ## and maybe coffee script? (although, we just use javascript, really)
41
+ # gem "coffee-script"
42
+
43
+ ####################
44
+ # Internationalization
45
+
46
+ ## I18n is the only one I know of.
47
+ # gem 'i18n'
48
+
49
+ ####################
50
+ # WebSocket Scaling
51
+
52
+ ## redis servers are used to allow websocket scaling.
53
+ ## the :broadcast and :collect methods will work only for the current process.
54
+ ## using Redis, we can publish messages and subscribe to 'chunnels' across processes
55
+ # (limited support for :broadcast and NO support for :collect while Redis is running).
56
+
57
+ # gem 'redis'
58
+
59
+ ####################
60
+ # gems for databases and models
61
+
62
+ ## if you want to use a database, here are a few common enough options:
63
+ # gem 'mysql2'
64
+ # gem 'sqlite3'
65
+ # gem 'pg'
66
+
67
+ ## MongoDB is a very well known NoSQL DB
68
+ ## https://github.com/mongodb/mongo-ruby-driver
69
+ # gem 'mongo'
70
+ ## for a performance boost, the C extentions can be used (NOT JRuby - bson_ext isn't used with JRuby).
71
+ # gem 'bson_ext'
72
+ ## you can also have a look at the Mongo Mapper ORM
73
+ ## http://mongomapper.com
74
+ # gem 'mongo_mapper'
75
+
76
+ ## someone told me good things about sequel:
77
+ ## http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html
78
+ ## http://sequel.jeremyevans.net/rdoc/files/doc/cheat_sheet_rdoc.html
79
+ ## this seems greate, but we left out any auto-config for this one... seems to work out of the box.
80
+ # gem 'sequel'
81
+
82
+ ## if you want to use ActiveRecord, uncomment the following line(s)...
83
+ ## but first, please remember that AcriveRecord needs extra attention when multi-threading
84
+ # gem 'activerecord', :require => 'active_record'
85
+ # gem 'bcrypt', '~> 3.1.7'
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <head>
3
+ <meta charset='UTF-8'>
4
+ <style>
5
+ html, body {width: 100%; height:100%;}
6
+ body {font-size: 1.5em; background-color: #eee;}
7
+ p {padding: 0.2em; margin: 0;}
8
+ .received { color: #00f;}
9
+ .sent { color: #f0f;}
10
+ .connection { color: #0f0;}
11
+ .error { color: #f00;}
12
+ input, #output {font-size: 1em; width: 60%; margin: 0.5em 19%; padding: 0.5em 1%;}
13
+ #output {height: 60%; overflow: auto; background-color: #fff;}
14
+ </style>
15
+ <script>
16
+ var websocket = NaN;
17
+ function connect() { websocket = new WebSocket('ws://' + window.location.hostname + (window.location.port == '' ? '' : (':' + window.location.port) ) + "/" ); }
18
+ function init()
19
+ {
20
+ connect()
21
+ websocket.onopen = function(evt) { WriteMessage("Connected.", "connection") };
22
+ websocket.onclose = function(evt) { WriteMessage("Disconnected.", "connection");connect(); };
23
+ websocket.onmessage = function(evt) {
24
+ WriteMessage(evt.data);
25
+ };
26
+ websocket.onerror = function(evt) { WriteMessage(evt.data, 'error'); };
27
+ }
28
+ function WriteMessage( message, message_type )
29
+ {
30
+ if (!message_type) message_type = 'received'
31
+ var msg = document.createElement("p");
32
+ msg.className = message_type;
33
+ msg.innerHTML = message;
34
+ document.getElementById("output").appendChild(msg);
35
+ }
36
+ function Send(message)
37
+ {
38
+ WriteMessage(message, 'sent');
39
+ websocket.send(message);
40
+ }
41
+ window.addEventListener("load", init, false);
42
+ </script>
43
+ </head>
44
+ <body>
45
+ <div id='output'>test</div>
46
+ <input type='text' placeholder='your message goes here.' value='' />
47
+ </body>
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # load all framework and gems
5
+ load ::File.expand_path(File.join("..", "environment.rb"), __FILE__)
6
+
7
+ # set up the routes
8
+ load ::File.expand_path(File.join("..", "routes.rb"), __FILE__)
@@ -0,0 +1,39 @@
1
+ ########################
2
+ # RackServer rack interface
3
+ #
4
+ # using Rack with Plezi poses some limitations...:
5
+ #
6
+ # 1. only the first service (and all it's virtual hosts) will be running.
7
+ # (only the first `listen` call and all it's related `host` calls)
8
+ #
9
+ # 2. there is NO WebSockets support for Rack apps.
10
+ #
11
+ # 3. this WILL BREAKE any streaming / asynchronous methods calls that use the Plezi events engine.
12
+ #
13
+ # 4. Plezi parameters and file uploads are different then Rack - HTML Form code might be incompatible!
14
+ # This MIGHT BREAKE YOUR CODE! (changing this requires Plezi to re-parse the HTML, and costs in performance).
15
+ #
16
+ # also, all Plezi server specific configuration will be ignored.
17
+ #
18
+ # on the other hand, there is an upside:
19
+ #
20
+ # 1. you can choose a well tested server written in C that might (or might not) bring a performance boost.
21
+ #
22
+ # 2. you have better control over Middleware then you could have with Plezi.
23
+ # ("wait", you might say, "there is no Middleware in Plezi!"... "Ahhh", I will answer, "so much to discover...")
24
+
25
+
26
+ working_dir = ::File.expand_path(Dir.pwd)
27
+ app_path = ::File.expand_path(File.join(".."), __FILE__)
28
+ app_file_name = app_path.split(/[\\\/]/).last + ".rb"
29
+
30
+ # # make sure plezi doesn't set up sockets nor starts the event cycle.
31
+ PLEZI_ON_RACK = true
32
+
33
+ #load the Plezi application file
34
+ Dir.chdir app_path
35
+ require File.join(app_path, app_file_name)
36
+
37
+ Dir.chdir working_dir
38
+
39
+ run Plezi