public
Description: This contains various plugins for Feather
Clone URL: git://github.com/eldiablo/feather-plugins.git
Click here to lend your support to: feather-plugins and make a donation at www.pledgie.com !
some fixes to try and make dynamic snippets run better across multiple 
processes
eldiablo (author)
Sat Apr 12 18:20:44 -0700 2008
commit  c25de58bd5f60f64a5b500714899064d7f5ec298
tree    ce8e2aade5b4778da17b3fc1bd009e02a454bcf4
parent  06e32bf95a83f0b99b16a8d1e9611850794cabfd
...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
 
 
 
25
26
27
...
11
12
13
 
 
 
 
 
 
 
 
 
 
 
14
15
16
17
18
19
20
0
@@ -11,16 +11,9 @@ Hooks::Menu.add_menu_item do
0
   {:text => "Snippets", :url => "/admin/snippets" }
0
 end
0
 
0
-##
0
-# Re-opening the main controller just to register any snippets as required
0
-class Application < Merb::Controller
0
- before :load_snippets
0
-
0
- ##
0
- # This loads any snippets that aren't yet registered (for example, that were created on another application process thread)
0
- def load_snippets
0
- Snippet.all.each do |snippet|
0
- snippet.register unless snippet.registered?
0
- end
0
+Hooks::Events.register_event(:application_before) do
0
+ Snippet.all.each do |snippet|
0
+ snippet.register unless snippet.registered?
0
+ snippet.deregister && snippet.register unless snippet.up_to_date?
0
   end
0
 end
0
\ No newline at end of file
...
1
2
3
 
4
5
6
7
 
8
9
 
10
11
12
13
14
 
15
16
17
18
19
 
20
21
22
23
 
24
 
25
26
27
...
32
33
34
 
 
 
 
 
 
35
36
...
1
2
3
4
5
6
7
 
8
9
 
10
11
12
13
14
15
16
17
18
19
20
 
21
22
23
24
 
25
26
27
28
29
30
...
35
36
37
38
39
40
41
42
43
44
45
0
@@ -1,27 +1,30 @@
0
 class Snippet < DataMapper::Base
0
   property :content, :text, :nullable => false
0
   property :location, :string, :nullable => false, :length => 255
0
+ property :created_at, :datetime
0
   
0
   after_save :register
0
   before_destroy :deregister
0
-
0
+
0
   class << self
0
- @@registered = []
0
+ @@registered = {}
0
   end
0
   
0
   ##
0
   # This registers the snippet within the view hooks
0
   def register
0
+ # Register the snippet view
0
     Hooks::View.register_view self.id do
0
       { :name => self.location, :content => self.content }
0
     end
0
     # Add the snippet to the array of registered snippets
0
- @@registered << self.id
0
+ @@registered[self.id] = {:location => self.location, :created_at => self.created_at}
0
   end
0
   
0
   ##
0
- # This de-registers the snippet from the view hooks
0
+ # This deregisters the snippet from the view hooks
0
   def deregister
0
+ # Deregister the snippet view
0
     Hooks::View.deregister_view self.id
0
     # Remove the snippet from the array of registered snippets
0
     @@registered.delete(self.id)
0
@@ -32,4 +35,10 @@ class Snippet < DataMapper::Base
0
   def registered?
0
     @@registered.include?(self.id)
0
   end
0
+
0
+ ##
0
+ # This returns true if the snippet has been registered and is up to date, false otherwise
0
+ def up_to_date?
0
+ self.registered? && @@registered[self.id][:location] == self.location && @@registered[self.id][:created_at] == self.created_at
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.