plezi 0.10.15 → 0.10.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac2ec66d7213346b5414d5e6dda9bfee10d135c5
4
- data.tar.gz: 0631b6f21c1f5576ccd6cbc88fafcdb8d47a1638
3
+ metadata.gz: 9ba53dc3edc704550c8afdc060088aed2cd9db01
4
+ data.tar.gz: 7aa792d205aabce90e999f1c5637a882c40de10a
5
5
  SHA512:
6
- metadata.gz: eea85e77d2bdf4fe1aaa6877e4945d35834c3c98d42f3b1a10381a7601765e6795273a45ef5eef971f5e6541f8e7ce0a985f4ae298e1cfd3b498f3b162480eae
7
- data.tar.gz: 60750c0fea68213ebdc91c1930032e8c7317b5bd4757946139af3d7ffe59f1dee35c3b57917aabd42d909fd0f1c598f1242282115c6b874626847839a4ea99c6
6
+ metadata.gz: 667725a7647a0c49e81991e0d164c3729c639ecbd37e56de37cb0131ed91cf059039e2b9eba121bef365b23e89e8b0dcca57b7bcdc0b75fa547bb3949fd29161
7
+ data.tar.gz: 44a1bb1546727e1e96fecfbe3e65607dcd0f9093ac4f1fb8a9161d33a119f23c739f93f9ea761abfe1536f4763a96518117b912c19de9382f6e7a6d4bbd598e9
@@ -1,8 +1,20 @@
1
1
  #Change Log
2
2
 
3
+ ***
4
+
5
+ Change log v.0.10.16
6
+
7
+ **Fix**: Requires a newer version of the GRHttp server, which fixs an issue with Firefox's websocket implementation.
8
+
9
+ **New Feature**: Persistent and synchronized Session data(!) using Redis (if supplied) with a fallback to temporary memory storage. Session lifetime is 5 days.
10
+
11
+ ***
12
+
3
13
  Change log v.0.10.15
4
14
 
5
- **Fix**: Fixed the autostart feature that was diabled to to changed in the GRHttp server.
15
+ **Fix**: Fixed the autostart feature that was diabled due to a changed in the GRHttp server's code for Rack support.
16
+
17
+ ***
6
18
 
7
19
  Change log v.0.10.14
8
20
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Plezi, The Ruby framework for realtime web-apps
1
+ # [Plezi](https://github.com/boazsegev/plezi), The Ruby framework for realtime web-apps
2
2
  [![Gem Version](https://badge.fury.io/rb/plezi.svg)](http://badge.fury.io/rb/plezi)
3
3
  [![Inline docs](http://inch-ci.org/github/boazsegev/plezi.svg?branch=master)](http://www.rubydoc.info/github/boazsegev/plezi/master)
4
4
 
data/bin/plezi CHANGED
@@ -4,198 +4,10 @@ $0="Plezi Builder"
4
4
 
5
5
  require 'irb'
6
6
  require 'securerandom'
7
+ require 'plezi/builders/builder'
8
+ require 'plezi/builders/app_builder'
7
9
 
8
10
 
9
- ##########
10
- # this is the template writer
11
- #
12
- # you can update it by aliasing the old initialize and writing adding to it:
13
- #
14
- # if defined? BUILDING_PLEZI_TEMPLATE
15
- # class AppTemplate
16
- # alias :my_new_gem_old_init :initialize
17
- # def initialize
18
- # # start with the old initialize, to set the template up
19
- # my_new_gem_old_init appname
20
- # # add your gem to the gemfile
21
- # app_tree["Gemfile"] << "\n# feed GEMNAME to plezi"
22
- # app_tree["Gemfile"] << "\ngem 'GEMNAME'"
23
- # # make sure your folder exists, but don't overwrite!!!
24
- # # if you overwrite!!! you might destroy other gems additions.
25
- # app_tree["lib"] ||= {}
26
- # app_tree["MY_SPECIAL_GEM"] ||= {}
27
- # # once your folder exists, create your file
28
- # app_tree["lib]["MY_SPECIAL_GEM"]["filename.rb"] = "# code goes here..."
29
- # app_tree["file_without_folder.rb"] ||= "# more code goes here..."
30
- # end
31
- # end
32
- # end
33
- #
34
- class AppTemplate
35
-
36
- def initialize
37
- @end_comments = []
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
- app_tree["templates"] ||= {}
53
- app_tree["templates"]["404.html.erb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"404.erb"), __FILE__))
54
- app_tree["templates"]["500.html.erb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"500.erb"), __FILE__))
55
- app_tree["templates"]["welcome.html.erb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"mini_welcome_page.html"), __FILE__)).gsub('appname', ARGV[1])
56
- app_tree["assets"] ||= {}
57
- app_tree["assets"]["websocket.js"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"websockets.js"), __FILE__)).gsub('appname', ARGV[1])
58
- finalize
59
- end
60
-
61
- def build
62
- require 'plezi/version'
63
- # plezi run script
64
- @app_tree["#{ARGV[1]}"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"code.rb"), __FILE__)
65
-
66
- # set up application files
67
- app_tree["app"] ||= {}
68
- app_tree["app"]["controllers"] ||= {}
69
- app_tree["app"]["controllers"]["sample_controller.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"controller.rb"), __FILE__))
70
- app_tree["app"]["models"] ||= {}
71
- app_tree["app"]["views"] ||= {}
72
-
73
- # set up templates for status error codes
74
- app_tree["app"]["views"]["404.html"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"404.html"), __FILE__))
75
- app_tree["app"]["views"]["500.html"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"500.html"), __FILE__))
76
- app_tree["app"]["views"]["404.html.erb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"404.erb"), __FILE__))
77
- app_tree["app"]["views"]["500.html.erb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"500.erb"), __FILE__))
78
- app_tree["app"]["views"]["404.html.slim"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"404.slim"), __FILE__))
79
- app_tree["app"]["views"]["500.html.slim"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"500.slim"), __FILE__))
80
- app_tree["app"]["views"]["404.html.haml"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"404.haml"), __FILE__))
81
- app_tree["app"]["views"]["500.html.haml"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"500.haml"), __FILE__))
82
-
83
- # set up the assets folder
84
- app_tree["assets"] ||= {}
85
- app_tree["assets"]["stylesheets"] ||= {}
86
- app_tree["assets"]["javascripts"] ||= {}
87
- app_tree["assets"]["javascripts"]["websocket.js"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"websockets.js"), __FILE__)).gsub('appname', ARGV[1])
88
- app_tree["assets"]["welcome.html"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"welcome_page.html"), __FILE__)).gsub('appname', ARGV[1])
89
-
90
- # app core files.
91
- app_tree["environment.rb"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"environment.rb"), __FILE__)
92
- app_tree["routes.rb"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"routes.rb"), __FILE__)
93
- app_tree["rakefile"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"rakefile"), __FILE__)
94
- app_tree["Procfile"] ||= ""
95
- app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{ARGV[1]} -p $PORT\n"
96
- app_tree["Gemfile"] ||= ''
97
- 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"
98
- app_tree["Gemfile"] << IO.read( ::File.expand_path(File.join("..", "..", "resources" ,"Gemfile"), __FILE__))
99
- app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
100
-
101
- # set up config files
102
- app_tree["config"] ||= {}
103
- app_tree["config"]["oauth.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"oauth_config.rb"), __FILE__))
104
- app_tree["config"]["active_record.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"db_ac_config.rb"), __FILE__))
105
- app_tree["config"]["sequel.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"db_sequel_config.rb"), __FILE__))
106
- app_tree["config"]["datamapper.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"db_dm_config.rb"), __FILE__))
107
- app_tree["config"]["haml.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"haml_config.rb"), __FILE__))
108
- app_tree["config"]["slim.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"slim_config.rb"), __FILE__))
109
- app_tree["config"]["i18n.rb"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"i18n_config.rb"), __FILE__))
110
- app_tree["config"]["redis.rb"] ||= (IO.read(::File.expand_path(File.join("..", "..", "resources" ,"redis_config.rb"), __FILE__))).gsub('appsecret', "#{ARGV[1]}_#{SecureRandom.hex}")
111
-
112
- #set up database stub folders
113
- app_tree["db"] ||= {}
114
- app_tree["db"]["migrate"] ||= {}
115
- app_tree["db"]["fixtures"] ||= {}
116
- app_tree["db"]["config.yml"] ||= IO.read(::File.expand_path(File.join("..", "..", "resources" ,"database.yml"), __FILE__))
117
-
118
- #set up the extras folder, to be filled with future goodies.
119
- # app_tree["extras"] ||= {}
120
- # app_tree["extras"]["config.ru"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"config.ru"), __FILE__)
121
-
122
- #set up I18n stub
123
- app_tree["locales"] ||= {}
124
- app_tree["locales"]["en.yml"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"en.yml"), __FILE__)
125
-
126
- # create library, log and tmp folders
127
- app_tree["logs"] ||= {}
128
- app_tree["lib"] ||= {}
129
- app_tree["tmp"] ||= {}
130
-
131
-
132
- # set up a public folder for static file service
133
- app_tree["public"] ||= {}
134
- app_tree["public"]["assets"] ||= {}
135
- app_tree["public"]["assets"]["stylesheets"] ||= {}
136
- app_tree["public"]["assets"]["javascripts"] ||= {}
137
- app_tree["public"]["images"] ||= {}
138
- finalize
139
- end
140
- def finalize
141
- begin
142
- Dir.mkdir ARGV[1]
143
- puts "created the #{ARGV[1]} application directory.".green
144
- rescue Exception => e
145
- puts "the #{ARGV[1]} application directory exists - trying to rebuild (no overwrite).".pink
146
- end
147
- Dir.chdir ARGV[1]
148
- puts "starting to write template data...".red
149
- puts ""
150
- write_files app_tree
151
- File.chmod 0775, "#{ARGV[1]}"
152
- puts "tried to update execution permissions. this is system dependent and might have failed.".pink
153
- puts "use: chmod +x ./#{ARGV[1]} to set execution permissions on Unix machines."
154
- puts ""
155
- puts "done."
156
- puts "\n#{@end_comments.join("\n")}" unless @end_comments.empty?
157
- puts ""
158
- puts "please change directory into the app directory: cd #{ARGV[1]}"
159
- puts ""
160
- puts "run the #{ARGV[1]} app using: ./#{ARGV[1]} or using: plezi s"
161
- puts ""
162
- end
163
-
164
- def write_files files, parent = "."
165
- if files.is_a? Hash
166
- files.each do |k, v|
167
- if v.is_a? Hash
168
- begin
169
- Dir.mkdir k
170
- puts " created #{parent}/#{k}".green
171
- rescue Exception => e
172
- puts " exists #{parent}/#{k}".red
173
- end
174
- Dir.chdir k
175
- write_files v, (parent + "/" + k)
176
- Dir.chdir ".."
177
- elsif v.is_a? String
178
- if ::File.exists? k
179
- if false #%w{Gemfile rakefile.rb}.include? k
180
- # old = IO.read k
181
- # old = (old.lines.map {|l| "\##{l}"}).join
182
- # IO.write k, "#####################\n#\n# OLD DATA COMMENTED OUT - PLEASE REVIEW\n#\n##{old}\n#{v}"
183
- # puts " #{parent}/#{k} WAS OVERWRITTEN, old data was preserved by comenting it out.".pink
184
- # puts " #{parent}/#{k} PLEASE REVIEW.".pink
185
- # @end_comments << "#{parent}/#{k} WAS OVERWRITTEN, old data was preserved by comenting it out. PLEASE REVIEW."
186
- else
187
- puts " EXISTS(!) #{parent}/#{k}".red
188
- end
189
- else
190
- IO.write k, v
191
- puts " wrote #{parent}/#{k}".yellow
192
- end
193
- end
194
- end
195
- end
196
- end
197
- end
198
-
199
11
 
200
12
  ######################################################################
201
13
  # tweek the string class for termial coloring options
@@ -252,7 +64,7 @@ if ARGV[0] == 'new' || ARGV[0] == 'n' || ARGV[0] == "force" || ARGV[0] == 'mini'
252
64
  end
253
65
 
254
66
  # building
255
- template = AppTemplate.new
67
+ template = Plezi::AppBuilder.new
256
68
  (ARGV[0] == 'mini' || ARGV[0] == 'm' ) ? template.build_mini : template.build
257
69
  elsif ARGV[0] == 'server' || ARGV[0] == 'start' || ARGV[0] == 's'
258
70
  ARGV.shift
@@ -50,6 +50,7 @@ require 'plezi/handlers/controller_magic.rb'
50
50
  require 'plezi/handlers/controller_core.rb'
51
51
  require 'plezi/handlers/placebo.rb'
52
52
  require 'plezi/handlers/stubs.rb'
53
+ require 'plezi/handlers/session.rb'
53
54
 
54
55
 
55
56
  ##############################################################################
@@ -0,0 +1,135 @@
1
+ require 'plezi/builders/builder'
2
+ module Plezi
3
+
4
+
5
+ class AppBuilder
6
+ def initialize
7
+ @end_comments = []
8
+ @app_tree ||= {}
9
+ @root = ::Plezi::Builder::GEM_ROOT
10
+ end
11
+ def app_tree
12
+ @app_tree ||= {}
13
+ end
14
+ def build_mini
15
+ require 'plezi/version'
16
+ @app_tree["#{ARGV[1]}"] ||= IO.read( File.join(@root, "resources" ,"mini_exec.rb")).gsub('appname', ARGV[1])
17
+ @app_tree["#{ARGV[1]}.rb"] ||= IO.read( File.join(@root, "resources" ,"mini_app.rb")).gsub('appname', ARGV[1]).gsub('appsecret', "#{ARGV[1]}_#{SecureRandom.hex}")
18
+ app_tree["Procfile"] ||= ""
19
+ app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{ARGV[1]} -p $PORT\n"
20
+ app_tree["Gemfile"] ||= ''
21
+ 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"
22
+ app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
23
+ app_tree["templates"] ||= {}
24
+ app_tree["templates"]["404.html.erb"] ||= IO.read(File.join(@root, "resources" ,"404.erb"))
25
+ app_tree["templates"]["500.html.erb"] ||= IO.read(File.join(@root, "resources" ,"500.erb"))
26
+ app_tree["templates"]["welcome.html.erb"] ||= IO.read(File.join(@root, "resources" ,"mini_welcome_page.html")).gsub('appname', ARGV[1])
27
+ app_tree["assets"] ||= {}
28
+ app_tree["assets"]["websocket.js"] ||= IO.read(File.join(@root, "resources" ,"websockets.js")).gsub('appname', ARGV[1])
29
+ finalize
30
+ end
31
+
32
+ def build
33
+ require 'plezi/version'
34
+ # plezi run script
35
+ @app_tree["#{ARGV[1]}"] ||= IO.read File.join(@root,"resources" ,"code.rb")
36
+
37
+ # set up application files
38
+ app_tree["app"] ||= {}
39
+ app_tree["app"]["controllers"] ||= {}
40
+ app_tree["app"]["controllers"]["sample_controller.rb"] ||= IO.read(File.join(@root,"resources" ,"controller.rb"))
41
+ app_tree["app"]["models"] ||= {}
42
+ app_tree["app"]["views"] ||= {}
43
+
44
+ # set up templates for status error codes
45
+ app_tree["app"]["views"]["404.html"] ||= IO.read(File.join(@root,"resources" ,"404.html"))
46
+ app_tree["app"]["views"]["500.html"] ||= IO.read(File.join(@root,"resources" ,"500.html"))
47
+ app_tree["app"]["views"]["404.html.erb"] ||= IO.read(File.join(@root,"resources" ,"404.erb"))
48
+ app_tree["app"]["views"]["500.html.erb"] ||= IO.read(File.join(@root,"resources" ,"500.erb"))
49
+ app_tree["app"]["views"]["404.html.slim"] ||= IO.read(File.join(@root,"resources" ,"404.slim"))
50
+ app_tree["app"]["views"]["500.html.slim"] ||= IO.read(File.join(@root,"resources" ,"500.slim"))
51
+ app_tree["app"]["views"]["404.html.haml"] ||= IO.read(File.join(@root,"resources" ,"404.haml"))
52
+ app_tree["app"]["views"]["500.html.haml"] ||= IO.read(File.join(@root,"resources" ,"500.haml"))
53
+
54
+ # set up the assets folder
55
+ app_tree["assets"] ||= {}
56
+ app_tree["assets"]["stylesheets"] ||= {}
57
+ app_tree["assets"]["javascripts"] ||= {}
58
+ app_tree["assets"]["javascripts"]["websocket.js"] ||= IO.read(File.join(@root,"resources" ,"websockets.js")).gsub('appname', ARGV[1])
59
+ app_tree["assets"]["welcome.html"] ||= IO.read(File.join(@root,"resources" ,"welcome_page.html")).gsub('appname', ARGV[1])
60
+
61
+ # app core files.
62
+ app_tree["environment.rb"] ||= IO.read File.join(@root,"resources" ,"environment.rb")
63
+ app_tree["routes.rb"] ||= IO.read File.join(@root,"resources" ,"routes.rb")
64
+ app_tree["rakefile"] ||= IO.read File.join(@root,"resources" ,"rakefile")
65
+ app_tree["Procfile"] ||= ""
66
+ app_tree["Procfile"] << "\nweb: bundle exec ruby ./#{ARGV[1]} -p $PORT\n"
67
+ app_tree["Gemfile"] ||= ''
68
+ 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"
69
+ app_tree["Gemfile"] << IO.read( File.join(@root,"resources" ,"Gemfile"))
70
+ app_tree["Gemfile"] << "\n\n\nruby '#{RUBY_VERSION}'\n"
71
+
72
+ # set up config files
73
+ app_tree["config"] ||= {}
74
+ app_tree["config"]["oauth.rb"] ||= IO.read(File.join(@root,"resources" ,"oauth_config.rb"))
75
+ app_tree["config"]["active_record.rb"] ||= IO.read(File.join(@root,"resources" ,"db_ac_config.rb"))
76
+ app_tree["config"]["sequel.rb"] ||= IO.read(File.join(@root,"resources" ,"db_sequel_config.rb"))
77
+ app_tree["config"]["datamapper.rb"] ||= IO.read(File.join(@root,"resources" ,"db_dm_config.rb"))
78
+ app_tree["config"]["haml.rb"] ||= IO.read(File.join(@root,"resources" ,"haml_config.rb"))
79
+ app_tree["config"]["slim.rb"] ||= IO.read(File.join(@root,"resources" ,"slim_config.rb"))
80
+ app_tree["config"]["i18n.rb"] ||= IO.read(File.join(@root,"resources" ,"i18n_config.rb"))
81
+ app_tree["config"]["redis.rb"] ||= (IO.read(File.join(@root,"resources" ,"redis_config.rb"))).gsub('appsecret', "#{ARGV[1]}_#{SecureRandom.hex}")
82
+
83
+ #set up database stub folders
84
+ app_tree["db"] ||= {}
85
+ app_tree["db"]["migrate"] ||= {}
86
+ app_tree["db"]["fixtures"] ||= {}
87
+ app_tree["db"]["config.yml"] ||= IO.read(File.join(@root,"resources" ,"database.yml"))
88
+
89
+ #set up the extras folder, to be filled with future goodies.
90
+ # app_tree["extras"] ||= {}
91
+ # app_tree["extras"]["config.ru"] ||= IO.read File.join(@root,"resources" ,"config.ru")
92
+
93
+ #set up I18n stub
94
+ app_tree["locales"] ||= {}
95
+ app_tree["locales"]["en.yml"] ||= IO.read File.join(@root,"resources" ,"en.yml")
96
+
97
+ # create library, log and tmp folders
98
+ app_tree["logs"] ||= {}
99
+ app_tree["lib"] ||= {}
100
+ app_tree["tmp"] ||= {}
101
+
102
+
103
+ # set up a public folder for static file service
104
+ app_tree["public"] ||= {}
105
+ app_tree["public"]["assets"] ||= {}
106
+ app_tree["public"]["assets"]["stylesheets"] ||= {}
107
+ app_tree["public"]["assets"]["javascripts"] ||= {}
108
+ app_tree["public"]["images"] ||= {}
109
+ finalize
110
+ end
111
+ def finalize
112
+ begin
113
+ Dir.mkdir ARGV[1]
114
+ puts "created the #{ARGV[1]} application directory.".green
115
+ rescue Exception => e
116
+ puts "the #{ARGV[1]} application directory exists - trying to rebuild (no overwrite).".pink
117
+ end
118
+ Dir.chdir ARGV[1]
119
+ puts "starting to write template data...".red
120
+ puts ""
121
+ Builder.write_files app_tree
122
+ File.chmod 0775, "#{ARGV[1]}"
123
+ puts "tried to update execution permissions. this is system dependent and might have failed.".pink
124
+ puts "use: chmod +x ./#{ARGV[1]} to set execution permissions on Unix machines."
125
+ puts ""
126
+ puts "done."
127
+ puts "\n#{@end_comments.join("\n")}" unless @end_comments.empty?
128
+ puts ""
129
+ puts "please change directory into the app directory: cd #{ARGV[1]}"
130
+ puts ""
131
+ puts "run the #{ARGV[1]} app using: ./#{ARGV[1]} or using: plezi s"
132
+ puts ""
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,41 @@
1
+ module Plezi
2
+ module Builder
3
+
4
+ GEM_ROOT = ::File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
5
+
6
+ def self.write_files files, parent = "."
7
+ if files.is_a? Hash
8
+ files.each do |k, v|
9
+ if v.is_a? Hash
10
+ begin
11
+ Dir.mkdir k
12
+ puts " created #{parent}/#{k}".green
13
+ rescue Exception => e
14
+ puts " exists #{parent}/#{k}".red
15
+ end
16
+ Dir.chdir k
17
+ write_files v, (parent + "/" + k)
18
+ Dir.chdir ".."
19
+ elsif v.is_a? String
20
+ if ::File.exists? k
21
+ if false #%w{Gemfile rakefile.rb}.include? k
22
+ # old = IO.read k
23
+ # old = (old.lines.map {|l| "\##{l}"}).join
24
+ # IO.write k, "#####################\n#\n# OLD DATA COMMENTED OUT - PLEASE REVIEW\n#\n##{old}\n#{v}"
25
+ # puts " #{parent}/#{k} WAS OVERWRITTEN, old data was preserved by comenting it out.".pink
26
+ # puts " #{parent}/#{k} PLEASE REVIEW.".pink
27
+ # @end_comments << "#{parent}/#{k} WAS OVERWRITTEN, old data was preserved by comenting it out. PLEASE REVIEW."
28
+ else
29
+ puts " EXISTS(!) #{parent}/#{k}".red
30
+ end
31
+ else
32
+ IO.write k, v
33
+ puts " wrote #{parent}/#{k}".yellow
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,24 @@
1
+ require 'plezi/builders/builder'
2
+
3
+ module Plezi
4
+
5
+ module FormBuilder
6
+
7
+ FORM_BUILDERS = %w{ Slim ERB }
8
+ MODEL_BUILDERS = %w{ Squel }
9
+
10
+ DB_TYPES = %w{primary_key string text integer float decimal datetime time date binary boolean}
11
+
12
+ @gem_root = ::Plezi::Builder::GEM_ROOT
13
+ def self.parse_args
14
+ return unless ARGS[0][0] == 'g'
15
+ struct = {}
16
+ ARGS[1..-1].each do |s|
17
+ s = s.split /[\:\.]/
18
+ raise "Cannot parse parameters - need to be defined as name.type or name:type." if s.count !=2
19
+ struct[s[0]] = DB_TYPES[s[1].downcase] || (raise "Unrecognized type #{s[1]}.")
20
+ end
21
+ struct
22
+ end
23
+ end
24
+ end
@@ -119,7 +119,7 @@ module Plezi
119
119
  # to broadcast Plezi messages to other Plezi processes - allowing for scalable intigration of Plezi into other frameworks.
120
120
  def start_placebo
121
121
  GReactor.clear_listeners
122
- redis_connection # make sure the redis connection is activated
122
+ redis # make sure the redis connection is activated
123
123
  puts "* Plezi #{Plezi::VERSION} Services will start with no Server...\n"
124
124
  start_async
125
125
  end
@@ -93,6 +93,9 @@ unless defined? PLEZI_NON_DSL
93
93
  # sets information to be used when restarting
94
94
  $PL_SCRIPT = $0
95
95
  $PL_ARGV = $*.dup
96
+
97
+ # sets up a generic session-token name based on the script name
98
+ GRHttp.session_token = "#{($0).split(/[\\\/]/).last.split(/[\s]+/).first}_uuid"
96
99
  # restarts the Plezi app with the same arguments as when it was started.
97
100
  #
98
101
  # EXPERIMENTAL
@@ -10,7 +10,7 @@ module Plezi
10
10
  # ENV['PL_REDIS_URL'] = ENV['REDISCLOUD_URL']`
11
11
  # or
12
12
  # ENV['PL_REDIS_URL'] = "redis://username:password@my.host:6379"
13
- def redis_connection
13
+ def redis
14
14
  return @redis if (@redis_sub_thread && @redis_sub_thread.alive?) && @redis
15
15
  return false unless defined?(Redis) && ENV['PL_REDIS_URL']
16
16
  @redis_locker ||= Mutex.new
@@ -47,5 +47,6 @@ module Plezi
47
47
  Reactor.error e
48
48
  false
49
49
  end
50
+ alias :redis_connection :redis
50
51
  end
51
52
 
@@ -19,6 +19,7 @@ module Plezi
19
19
  @host_params = request.io[:params]
20
20
  @response = response
21
21
  @cookies = request.cookies
22
+ @session = response.session
22
23
  # # \@response["content-type"] ||= ::Plezi.default_content_type
23
24
  super()
24
25
  end
@@ -46,7 +47,7 @@ module Plezi
46
47
  @response = ws
47
48
  ws.autoping Plezi::Settings.autoping if Plezi::Settings.autoping
48
49
  # create the redis connection (in case this in the first instance of this class)
49
- Plezi.redis_connection
50
+ Plezi.redis
50
51
  super() if defined?(super)
51
52
  end
52
53
  # handles websocket messages.
@@ -29,11 +29,14 @@ module Plezi
29
29
  # the :params variable contains all the parameters set by the request (/path?locale=he => params ["locale"] == "he").
30
30
  attr_reader :params
31
31
 
32
- # a cookie-jar to get and set cookies (set: `cookie [:name] = data` or get: `cookie [ :name ]`).
32
+ # A cookie-jar to get and set cookies (set: `cookie [:name] = data` or get: `cookie [ :name ]`).
33
33
  #
34
34
  # Cookies and some other data must be set BEFORE the response's headers are sent.
35
35
  attr_reader :cookies
36
36
 
37
+ # Session data can be stored here (for now, session data doesn't scale - coming soon).
38
+ attr_reader :session
39
+
37
40
  # the HTTPResponse **OR** the WSResponse object that formats the response and sends it. use `response << data`. This object can be used to send partial data (such as headers, or partial html content) in blocking mode as well as sending data in the default non-blocking mode.
38
41
  attr_reader :response
39
42
 
@@ -0,0 +1,84 @@
1
+ module Plezi
2
+ module Base
3
+ module SessionStorage
4
+ module_function
5
+ # returns a session object
6
+ def fetch id
7
+ @session_cache[id] || (@session_cache[id] = Plezi::Session.new(id))
8
+ end
9
+ @session_cache = {}
10
+ end
11
+ end
12
+ # A hash like interface for storing request session data.
13
+ # The store must implement: store(key, value) (aliased as []=);
14
+ # fetch(key, default = nil) (aliased as []);
15
+ # delete(key); clear;
16
+ class Session
17
+
18
+ # The session's lifetime in seconds = 5 days. This is only true when using the built in support for the Redis persistent storage.
19
+ SESSION_LIFETIME = 432_000
20
+ # called by the Plezi framework to initiate a session with the id requested
21
+ def initialize id
22
+ @id = id
23
+ if (conn=Plezi.redis)
24
+ @data=conn.hgetall(id)
25
+ end
26
+ @data ||= {}
27
+ end
28
+ # Get a key from the session data store. If a Redis server is supplied, it will be used to synchronize session data.
29
+ #
30
+ # Due to scaling considirations, all keys will be converted to strings, so that `"name" == :name` and `1234 == "1234"`.
31
+ # If you store two keys that evaluate as the same string, they WILL override each other.
32
+ def [] key
33
+ key = key.to_s
34
+ if conn=Plezi.redis
35
+ conn.expire @id, SESSION_LIFETIME
36
+ @data[key] = conn.hget @id, key
37
+ end
38
+ @data[key]
39
+ end
40
+ alias :fetch :[]
41
+
42
+ # Stores a key in the session's data store. If a Redis server is supplied, it will be used to synchronize session data.
43
+ #
44
+ # Due to scaling considirations, all keys will be converted to strings, so that `"name" == :name` and `1234 == "1234"`.
45
+ # If you store two keys that evaluate as the same string, they WILL override each other.
46
+ def []= key, value
47
+ key = key.to_s
48
+ if (conn=Plezi.redis)
49
+ conn.hset @id, key, value
50
+ conn.expire @id, SESSION_LIFETIME
51
+ end
52
+ @data[key] = value
53
+ end
54
+ alias :store :[]=
55
+
56
+ # @return [Hash] returns a shallow copy of the current session data as a Hash.
57
+ def to_h
58
+ if (conn=Plezi.redis)
59
+ conn.expire @id, SESSION_LIFETIME
60
+ return (@data=conn.hgetall(@id)).dup
61
+ end
62
+ @data.dup
63
+ end
64
+
65
+ # Removes a key from the session's data store.
66
+ def delete key
67
+ key = key.to_s
68
+ if (conn=Plezi.redis)
69
+ conn.expire @id, SESSION_LIFETIME
70
+ conn.hdel @id, key
71
+ end
72
+ @data.delete key
73
+ end
74
+
75
+ # Clears the session's data.
76
+ def clear
77
+ if (conn=Plezi.redis)
78
+ conn.del @id
79
+ end
80
+ @data.clear
81
+ end
82
+ end
83
+ GRHttp::SessionManager.storage = Plezi::Base::SessionStorage
84
+ end
@@ -192,7 +192,7 @@ module Plezi
192
192
  end
193
193
 
194
194
  def __inner_redis_broadcast data
195
- return unless conn = Plezi.redis_connection
195
+ return unless conn = Plezi.redis
196
196
  data[:server] = Plezi::Settings.uuid
197
197
  return conn.publish( ( data[:to_server] ? data[:to_server] : Plezi::Settings.redis_channel_name ), data.to_yaml ) if conn
198
198
  false
@@ -1,3 +1,3 @@
1
1
  module Plezi
2
- VERSION = "0.10.15"
2
+ VERSION = "0.10.16"
3
3
  end
@@ -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.19"
21
+ spec.add_dependency "grhttp", "~> 0.0.21"
22
22
  spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
 
@@ -26,6 +26,9 @@ require 'tilt/sass' if defined?(::Slim) && defined?(::Sass)
26
26
  # set up Plezi's logs - Heroku logs to STDOUT, this machine logs to log file
27
27
  GReactor.create_logger File.expand_path(File.join 'logs','server.log'), ENV["RACK_ENV"]=="development" unless ENV['DYNO']
28
28
 
29
+ # set the session token name
30
+ GRHttp.session_token = 'appname_uui'
31
+
29
32
  ## Allow forking? ONLY if your code is fully scalable across processes.
30
33
  # GReactor::Settings.set_forking 4
31
34
 
@@ -5,6 +5,8 @@
5
5
  require 'pathname'
6
6
  ## Set up root object, it might be used by the environment and\or the plezi extension gems.
7
7
  Root ||= Pathname.new(File.dirname(__FILE__)).expand_path
8
+ ## Set a persistant session token id name
9
+ GRHttp.session_token = 'appname_uui'
8
10
  ## make sure all file access and file loading is relative to the application's root folder
9
11
  # Dir.chdir Root.to_s
10
12
  ## load code from a subfolder called 'code'
@@ -208,7 +208,7 @@ module PleziTestTasks
208
208
 
209
209
  rescue => e
210
210
  puts " **** Update RESTful path test FAILED TO RUN!!!"
211
- puts e
211
+ puts e.message
212
212
  end
213
213
  def test_delete
214
214
  puts " * Delete RESTful path test: #{RESULTS[Net::HTTP.post_form( URI.parse("http://localhost:3000/"), id: 3, _method: :delete).body == 'delete 3']}"
@@ -475,7 +475,7 @@ Plezi.start_async
475
475
  PleziTestTasks.run_tests
476
476
 
477
477
  # ENV['PL_REDIS_URL'] ||= ENV['REDIS_URL'] || ENV['REDISCLOUD_URL'] || ENV['REDISTOGO_URL'] || "redis://test:1234@pub-redis-11008.us-east-1-4.5.ec2.garantiadata.com:11008"
478
- # # GReactor::Settings.set_forking 4
478
+ # GReactor::Settings.set_forking 4
479
479
  # GR.run_async { PleziTestTasks.run_tests }
480
480
  # start_services
481
481
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plezi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.15
4
+ version: 0.10.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grhttp
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.19
19
+ version: 0.0.21
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.19
26
+ version: 0.0.21
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -69,6 +69,9 @@ files:
69
69
  - Rakefile
70
70
  - bin/plezi
71
71
  - lib/plezi.rb
72
+ - lib/plezi/builders/app_builder.rb
73
+ - lib/plezi/builders/builder.rb
74
+ - lib/plezi/builders/form_builder.rb
72
75
  - lib/plezi/common/api.rb
73
76
  - lib/plezi/common/cache.rb
74
77
  - lib/plezi/common/defer.rb
@@ -80,6 +83,7 @@ files:
80
83
  - lib/plezi/handlers/http_router.rb
81
84
  - lib/plezi/handlers/placebo.rb
82
85
  - lib/plezi/handlers/route.rb
86
+ - lib/plezi/handlers/session.rb
83
87
  - lib/plezi/handlers/stubs.rb
84
88
  - lib/plezi/handlers/ws_object.rb
85
89
  - lib/plezi/helpers/http_sender.rb