public
Description: A SSB OSX application, which at some point will be able to create a new application which wraps a specific web application, (Think Campfire, Twitter etc) and allows the user to use Ruby to create event handlers to be able support things like Growl or whatever you would like.
Clone URL: git://github.com/alloy/webapp-app.git
Search Repo:
- Finished dynamically loading bundles. There should not be any Campfire 
code left in the core.
- Added WebApp::EventHandler.event_handlers which returns an array of 
event handler classes.
alloy (author)
Mon Apr 07 13:37:42 -0700 2008
commit  b9e4f2cd73e44ff16059a5d69a17d7c8ceb8414f
tree    72d68e5949710e7a78d5164e7aec8440411ebab0
parent  ea8d54e6281869b269ceb933e1e3e6903b43807d
...
23
24
25
 
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
...
89
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
93
94
...
23
24
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
29
30
...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
0
@@ -23,26 +23,8 @@
0
     setup_tabBarController!
0
     
0
     @bundle_window_controllers = {}
0
+ load_bundles!
0
     
0
- ["#{Rucola::RCApp.root_path}/bundles/", Rucola::RCApp.application_support_path].each do |bundles|
0
- # Load all event handlers
0
- Dir.glob("#{bundles}/*.wabundle/event_handlers/*.rb").each do |event_handler|
0
- require event_handler
0
- end
0
-
0
- # Load all window controllers
0
- Dir.glob("#{bundles}/*.wabundle/controllers/*.rb").each do |controller|
0
- require controller
0
- klass = File.constantize(controller)
0
-
0
- item = OSX::NSMenuItem.alloc.initWithTitle_action_keyEquivalent("#{klass.name.scan(/([A-Z][a-z]+)/).flatten[0..-2].join(' ')}...", 'openBundleWindowController:', '')
0
- item.target = self
0
- item.representedObject = klass
0
-
0
- @bundlesMenu.addItem(item)
0
- end
0
- end
0
-
0
     # If there are any custom user css rules, now is the time to write them out.
0
     if stylesheet_path = WebApp::EventHandler.write_tmp_stylesheet!
0
       # And assign it to the WebView preferences.
0
@@ -89,6 +71,29 @@
0
   end
0
   
0
   private
0
+
0
+ def load_bundles!
0
+ ["#{Rucola::RCApp.root_path}/bundles/", Rucola::RCApp.application_support_path].each do |bundles|
0
+ # Load all event handlers
0
+ Dir.glob("#{bundles}/*.wabundle/event_handlers/*.rb").each do |event_handler|
0
+ log.debug "Loading event handler: #{event_handler}"
0
+ require event_handler
0
+ end
0
+
0
+ # Load all window controllers
0
+ Dir.glob("#{bundles}/*.wabundle/controllers/*.rb").each do |controller|
0
+ log.debug "Loading controller: #{controller}"
0
+ require controller
0
+ klass = File.constantize(controller)
0
+
0
+ item = OSX::NSMenuItem.alloc.initWithTitle_action_keyEquivalent("#{klass.name.scan(/([A-Z][a-z]+)/).flatten[0..-2].join(' ')}...", 'openBundleWindowController:', '')
0
+ item.target = self
0
+ item.representedObject = klass
0
+
0
+ @bundlesMenu.addItem(item)
0
+ end
0
+ end
0
+ end
0
   
0
   def setup_tabView!
0
     @tabView.removeTabViewItem(@tabView.tabViewItemAtIndex(0))
...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 
109
110
111
112
113
114
115
116
...
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
98
99
100
101
 
102
0
@@ -92,26 +92,12 @@
0
   
0
   def setup_event_handlers!
0
     @event_handlers = []
0
- # event_handler_files = Dir.glob "#{RUBYCOCOA_ROOT + 'lib/event_handlers/'}/campfire.rb"
0
- #
0
- # event_handler_files.each do |event_handler_file|
0
- # require event_handler_file
0
- # #p WebApp::EventHandler::event_handlers
0
- #
0
- # #event_handler = File.constantize(event_handler_file).alloc.init
0
- # event_handler = Campfire::Room.alloc.init
0
- # p event_handler.methods(false)
0
- # # event_handler.webView = @webView
0
- # @event_handlers << event_handler
0
- # end
0
-
0
- [Campfire::All, Campfire::Lobby, Campfire::Room].each do |event_handler_class|
0
+ WebApp::EventHandler.event_handlers.each do |event_handler_class|
0
       event_handler = event_handler_class.alloc.init
0
       event_handler.webViewController = self
0
       event_handler.webView = @webView
0
       @event_handlers << event_handler
0
     end
0
   end
0
-
0
 end
...
1
2
3
4
...
 
1
2
3
0
@@ -1,4 +1,3 @@
0
-log.debug "Loading bundle from here: #{__FILE__}"
0
 module Campfire
0
   class All < WebApp::EventHandler
0
     # Hide the room tabs at the top of the page
...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
19
20
21
...
30
31
32
 
 
 
 
 
 
33
34
35
...
51
52
53
54
55
56
57
58
59
60
61
...
4
5
6
 
 
 
 
 
 
 
 
 
 
 
 
7
8
9
10
...
19
20
21
22
23
24
25
26
27
28
29
30
...
46
47
48
 
 
 
 
 
49
50
51
0
@@ -4,18 +4,7 @@
0
       @klass_counter ||= 0
0
       @klass_counter += 1
0
       
0
- klass = eval %{
0
- class WebApp::NamelessEventHandler_#{@klass_counter} < EventHandler
0
- class << self
0
- def inherited(subklass)
0
- super
0
- subklass.global_url = global_url
0
- end
0
- end
0
-
0
- self
0
- end
0
- }
0
+ klass = eval "class WebApp::NamelessEventHandler_#{@klass_counter} < EventHandler; self; end"
0
       klass.global_url = url
0
       klass
0
     end
0
@@ -30,6 +19,12 @@
0
         @event_handlers ||= []
0
       end
0
       
0
+ def inherited(subklass)
0
+ super
0
+ subklass.global_url = global_url
0
+ EventHandler.event_handlers << subklass unless subklass.name =~ /NamelessEventHandler_/
0
+ end
0
+
0
       # Define custom CSS rules which will all be compiled into 1 stylesheet at startup.
0
       def css(rules)
0
         rules = rules.to_s.unindent
0
@@ -51,11 +46,6 @@
0
           
0
           stylesheet_path
0
         end
0
- end
0
-
0
- def inherited(subklass)
0
- super
0
- event_handlers << subklass unless subklass.name =~ /NamelessEventHandler_/
0
       end
0
     end
0
     
...
407
408
409
 
 
 
 
 
 
 
 
 
 
 
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
0
@@ -407,4 +407,15 @@
0
     end
0
   end
0
 end
0
+
0
+class SubClassOfANamelessEventHandler < WebApp::EventHandler(/.+/)
0
+end
0
+
0
+describe "EventHandler, class methods" do
0
+ it "should return a list of all the available event handler classes" do
0
+ event_handlers = WebApp::EventHandler.event_handlers
0
+ event_handlers.should.include SubClassOfANamelessEventHandler
0
+ event_handlers.all? { |eh| eh.name !=~ /^WebApp::NamelessEventHandler_\d+/ }.should.be true
0
+ end
0
+end

Comments

    No one has commented yet.