h2g_ajaxchat 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4a2cf7b50b820656771890f8cb122798afc244978db1f66b2515adab699494d
4
- data.tar.gz: 337be4f988d85f925abd286df7a27be25e67493fa1346e7c7d71bbf3f7abf883
3
+ metadata.gz: fed7c95dd7baa7e075472ce965f71916083e8f662a269292ef90bf195b89c1bc
4
+ data.tar.gz: 104cbd2876daee33558effccd165653bba0bcfd4ca4e691afcb67b257ab488df
5
5
  SHA512:
6
- metadata.gz: 73b8f7645dbca15f7f737f034812a157aa8424281a56a244e8848962509bd380802dc778db3a9d68a1ba0db951efeb27e3d54446e0c5960a86ce6fd93cc145f9
7
- data.tar.gz: bb44bb414122e1eaa926cb5e8e9c0e90c1d419942470f460958adf84545e2743e14601c81cc4a6a8596d6b4586b0bb09898c4dc786da6d633a3db70c5e9afc66
6
+ metadata.gz: b38375b60ea5ae5fac4040e0136e59ae62af25b457ff207feb4f43f397d2296a56fa75a0b4dbcfe670df62f8e3dc537b9871be78c54ae5095ce351d262fbcfaf
7
+ data.tar.gz: 3b8a18a0c8d2240de2947b497d90203f74418ff75f8f2eb3972924f488360969117debf8d49d51b2f1eaee659ad03866667da47a7bd55887868451064f0e334e
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -109,13 +109,11 @@ class ChatCore
109
109
 
110
110
  protected
111
111
 
112
- def append_message(msg)
113
-
114
- u = @session[:username]
115
- id = @session[:session_id].to_s
116
- @users[id] = u.to_s
117
-
118
- @messages << [Time.now, id, u, msg]
112
+ def append_message(t=Time.now, id=@session[:session_id].to_s,
113
+ u=@session[:username], msg)
114
+
115
+ @users[id] = u.to_s
116
+ @messages << [t, id, u, msg]
119
117
 
120
118
  end
121
119
 
@@ -138,6 +136,7 @@ end
138
136
 
139
137
  class WebPage
140
138
 
139
+ attr_reader :name
141
140
  attr_accessor :css, :html, :js, :s
142
141
 
143
142
  def initialize(name, h={} )
@@ -153,8 +152,12 @@ class WebPage
153
152
  def to_js()
154
153
  end
155
154
 
155
+ def s()
156
+ @s ||= html_template()
157
+ end
158
+
156
159
  def to_s()
157
- @s = html_template()
160
+ @s
158
161
  end
159
162
 
160
163
  protected
@@ -189,17 +192,7 @@ class Index < WebPage
189
192
  @name, @h = :index, h
190
193
  end
191
194
 
192
- def to_css()
193
- @css ||= '
194
- body {font-family: Arial;}
195
- #chatbox {overflow: scroll; height: 40%}
196
- div p span {colour: #dde}
197
- '
198
- end
199
-
200
- def to_html()
201
-
202
- b = binding
195
+ def html()
203
196
 
204
197
  @html ||= <<EOF
205
198
  <body onload="refresh()">
@@ -215,10 +208,24 @@ div p span {colour: #dde}
215
208
  </div>
216
209
  EOF
217
210
 
211
+ end
212
+
213
+ def to_css()
214
+ @css ||= '
215
+ body {font-family: Arial;}
216
+ #chatbox {overflow: scroll; height: 40%}
217
+ div p span {colour: #dde}
218
+ '
219
+ end
220
+
221
+ def to_html()
222
+
223
+ b = binding
224
+
218
225
  ERB.new(@html).result(b)
219
226
  end
220
227
 
221
- def to_js()
228
+ def js()
222
229
 
223
230
  @js ||= <<EOF
224
231
 
@@ -267,7 +274,11 @@ function ajaxCall2() {
267
274
 
268
275
  EOF
269
276
 
270
- end
277
+ end
278
+
279
+ def to_js()
280
+ @js
281
+ end
271
282
 
272
283
  end
273
284
 
@@ -277,7 +288,7 @@ class Login < WebPage
277
288
  @name = :login
278
289
  end
279
290
 
280
- def to_html()
291
+ def html()
281
292
 
282
293
  @html ||= '
283
294
  <div id="loginform">
@@ -292,6 +303,10 @@ class Login < WebPage
292
303
 
293
304
  end
294
305
 
306
+ def to_html()
307
+ @html
308
+ end
309
+
295
310
  end
296
311
 
297
312
  class Logout < WebPage
@@ -300,7 +315,7 @@ class Logout < WebPage
300
315
  @name = :logout
301
316
  end
302
317
 
303
- def to_html()
318
+ def html()
304
319
 
305
320
  @html ||= '
306
321
  <div id="logoutform">
@@ -314,6 +329,10 @@ class Logout < WebPage
314
329
 
315
330
  end
316
331
 
332
+ def to_html()
333
+ @html
334
+ end
335
+
317
336
  end
318
337
 
319
338
  class LogoutPost < WebPage
@@ -322,18 +341,22 @@ class LogoutPost < WebPage
322
341
  @name = :logout_post
323
342
  end
324
343
 
325
- def to_s()
344
+ def s()
326
345
 
327
346
  @s ||= 'You have successfully logged out'
328
347
 
329
348
  end
330
349
 
350
+ def to_s()
351
+ @s
352
+ end
353
+
331
354
  end
332
355
 
333
356
 
334
357
  class AjaxChat
335
358
 
336
- attr_reader :rws
359
+ attr_reader :rws, :views
337
360
 
338
361
  def initialize(chatobj, rws=DummyRws.new(self), config: nil, debug: false)
339
362
 
@@ -342,7 +365,7 @@ class AjaxChat
342
365
  plugins = if config then
343
366
 
344
367
  SimpleConfig.new(config).to_h.map do |name, settings|
345
-
368
+ puts 'name: ' + name.inspect if @debug
346
369
  settings = {} if settings.is_a? String
347
370
 
348
371
  pluginklass_name = 'AjaxChatPlugin' + name.to_s
@@ -362,21 +385,46 @@ class AjaxChat
362
385
  @index, @login, @logout, @logout_post = \
363
386
  [Index, Login, Logout, LogoutPost].map do |klass|
364
387
 
365
- obj = klass.new @h
366
-
367
- plugins.each {|plugin| plugin.apply obj }
368
-
369
- obj
388
+ klass.new @h
370
389
 
371
390
  end
372
391
 
392
+ @views = {
393
+ index: @index,
394
+ login: @login,
395
+ logout: @logout,
396
+ logout_post: @logout_post
397
+ }
398
+
399
+ plugins.each {|plugin| plugin.apply(self) if plugin.respond_to? :apply }
400
+
373
401
  end
374
402
 
375
403
  def chatter(newmsg=nil)
376
404
 
377
405
  id, users = @rws.req.session[:session_id].to_s, @chat.users
406
+
407
+ chat = @chat
408
+
409
+ # check for new messages to be added via the plugins
410
+ @plugins.each do |plugin|
411
+
412
+ next unless plugin.respond_to? :messages
413
+ plugin.messages.each {|x| chat.append_message *x }
414
+
415
+ end
378
416
 
379
417
  @chat.chatter(@rws.req, newmsg) do |t, uid, username, msg|
418
+
419
+ @plugins.each do |plugin|
420
+
421
+ plugin.messages.each do |x|
422
+
423
+ x.on_newmesage(t, uid, username, msg) if x.respond_to? :on_newmessage
424
+
425
+ end
426
+
427
+ end
380
428
 
381
429
  s2 = if id == uid then
382
430
  "you: %s" % msg
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: h2g_ajaxchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file