GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
A bunch of changes, mostly BootLoader related
wycats (author)
Sat Jan 12 22:18:44 -0800 2008
commit  31845db37f965a72b4848bccfd0d7ed0fa87e2fc
tree    7d4113dc539d84f07fcc8bd225a76702e70d9033
parent  266932186cdf84c39aac2000e31a709ad8074461
...
17
18
19
 
 
20
21
22
...
17
18
19
20
21
22
23
24
0
@@ -17,6 +17,8 @@ module Merb
0
     attr_accessor :environment, :load_paths
0
     self.load_paths = Hash.new
0
     
0
+ require 'merb_core/autoload'
0
+
0
     # This is the core mechanism for setting up your application layout
0
     # merb-core won't set a default application layout, but merb-more will
0
     # use the app/:type layout that is in use in Merb 0.5
...
11
12
13
14
15
16
 
 
 
 
 
...
11
12
13
 
 
14
15
16
17
18
19
0
@@ -11,5 +11,8 @@ module Merb
0
   autoload :Responder, "merb_core/controller/mixins/responder"
0
   autoload :Router, "merb_core/dispatch/router"
0
   autoload :SessionMixin, "merb_core/dispatch/session"
0
- autoload :Template, "merb_core/controller/template"
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+# Require this rather than autoloading it so we can be sure the default templater
0
+# gets registered
0
+require "merb_core/controller/template"
...
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
 
31
32
33
34
 
35
36
37
...
58
59
60
 
 
61
62
63
...
66
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
73
...
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
31
32
33
 
34
35
36
37
...
58
59
60
61
62
63
64
65
...
68
69
70
 
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
0
@@ -6,32 +6,32 @@ module Merb
0
   
0
   class BootLoader
0
     
0
- cattr_accessor :_subclasses
0
- class_inheritable_accessor :_after, :_before
0
+ cattr_accessor :subclasses
0
+ class_inheritable_accessor :after, :before
0
     
0
     class << self
0
       
0
       def inherited(klass)
0
- unless klass._before || klass._after
0
- _subclasses << klass.to_s
0
- elsif klass._before
0
- _subclasses.insert(_subclasses.index(klass._before), klass)
0
+ unless klass.before || klass.after
0
+ subclasses << klass.to_s
0
+ elsif klass.before
0
+ subclasses.insert(subclasses.index(klass.before), klass)
0
         else
0
- _subclasses.insert(_subclasses.index(klass._before) + 1, klass)
0
+ subclasses.insert(subclasses.index(klass.before) + 1, klass)
0
         end
0
         super
0
       end
0
       
0
       def run
0
- _subclasses.each {|klass| klass.new.run! }
0
+ subclasses.each {|klass| klass.new.run! }
0
       end
0
       
0
       def after(klass)
0
- _after = klass
0
+ after = klass
0
       end
0
       
0
       def before(klass)
0
- _before = klass
0
+ before = klass
0
       end
0
       
0
     end
0
@@ -58,6 +58,8 @@ class Merb::BootLoader::BuildFramework < Merb::BootLoader
0
 end
0
 
0
 class Merb::BootLoader::LoadPaths < Merb::BootLoader
0
+ LOADED_CLASSES = {}
0
+
0
   def run
0
     # Add models, controllers, and lib to the load path
0
     $LOAD_PATH.unshift Merb.load_paths[:model].first if Merb.load_paths[:model]
0
@@ -66,7 +68,95 @@ class Merb::BootLoader::LoadPaths < Merb::BootLoader
0
     
0
     # Require all the files in the registered load paths
0
     Merb.load_paths.each do |name, path|
0
- Dir[path.first / path.last].each {|f| require f}
0
+ Dir[path.first / path.last].each do |file|
0
+ klasses = ObjectSpace.classes.dup
0
+ require f
0
+ LOADED_CLASSES[file] = ObjectSpace.classes - klasses
0
+ end
0
+ end
0
+ end
0
+
0
+ def reload(file)
0
+ if klasses = LOADED_CLASSES[file]
0
+ klasses.each do |klass|
0
+ remove_constant(klass)
0
+ end
0
+ end
0
+ end
0
+
0
+ def remove_constant(const)
0
+ # This is to support superclasses (like AbstractController) that track
0
+ # their subclasses in a class variable. Classes that wish to use this
0
+ # functionality are required to alias it to _subclasses_list. Plugins
0
+ # for ORMs and other libraries should keep this in mind.
0
+ if klass.superclass.respond_to?(:_subclasses_list)
0
+ klass.superclass.send(:_subclasses_list).delete(klass)
0
+ klass.superclass.send(:_subclasses_list).delete(klass.to_s)
0
+ end
0
+
0
+ parts = const.to_s.split("::")
0
+ base = parts.size == 1 ? Object : Object.full_const_get(parts[0..-2].join("::"))
0
+ object = parts[-1].intern
0
+ Merb.logger.debugger("Removing constant #{object} from #{base}")
0
+ base.send(:remove_const, object) if object
0
+ end
0
+
0
+end
0
+
0
+class Merb::BootLoader::Templates < Merb::BootLoader
0
+ def run
0
+ template_paths.each do |path|
0
+ Merb::Template.inline_template(path)
0
     end
0
   end
0
+
0
+ def template_paths
0
+ extension_glob = "{#{Merb::Template::EXTENSIONS.keys.join(',')}}"
0
+
0
+ # This gets all templates set in the controllers template roots
0
+ # We separate the two maps because most of controllers will have
0
+ # the same _template_root, so it's silly to be globbing the same
0
+ # path over and over.
0
+ template_paths = Merb::AbstractController._abstract_subclasses.map do |klass|
0
+ klass._template_root
0
+ end.uniq.map {|path| Dir["#{path}/**/*.#{extension_glob}"] }
0
+
0
+ # This gets the templates that might be created outside controllers
0
+ # template roots. eg app/views/shared/*
0
+ template_paths << Dir["#{Merb.load_paths[:view]}/**/*.#{extension_glob}"]
0
+
0
+ template_paths.flatten.compact.uniq
0
+ end
0
+end
0
+
0
+class Merb::BootLoader::Libraries < Merb::BootLoader
0
+ @@libraries = {:disable_json_gem => %[json/ext json/pure]}
0
+
0
+ # Add other libraries to load in early in the boot process
0
+ #
0
+ # ==== Parameters
0
+ # hsh<Hash[exclude, tries]>:: A hash or libraries to add
0
+ #
0
+ # ==== Hash
0
+ # exclude<Symbol>::
0
+ # Exclude this library if Merb::Config[exclude] is true
0
+ # tries<Array[String]>::
0
+ # Try to require each item in the Array in succesion. If the item is not found,
0
+ # try the next one. If none of the items are found, raise a LoadError.
0
+ def self.add_libraries(hsh)
0
+ @@libraries.merge!(hsh)
0
+ end
0
+
0
+ def run
0
+ @@libraries.each do |exclude, choices|
0
+ require_first_working(*choices) unless Merb::Config[exclude]
0
+ end
0
+ end
0
+
0
+ def require_first_working(first, *rest)
0
+ require first
0
+ rescue LoadError
0
+ raise LoadError if rest.empty?
0
+ require_first_working rest.unshift, *rest
0
+ end
0
 end
0
\ No newline at end of file
...
63
64
65
66
 
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
69
 
 
 
 
70
 
71
72
73
...
63
64
65
 
66
67
68
69
70
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
0
@@ -63,11 +63,33 @@ class Merb::AbstractController
0
   include Merb::RenderMixin
0
   include Merb::GeneralControllerMixin
0
   
0
- class_inheritable_accessor :_before_filters, :_after_filters
0
+ class_inheritable_accessor :_before_filters, :_after_filters, :_template_root
0
   self._before_filters, self._after_filters = [], []
0
+ self._template_root = Merb.load_paths[:view]
0
+
0
+ # This is called after the controller is instantiated to figure out
0
+ # where to look for templates under the _template_root. Override this
0
+ # to define a new structure for your app.
0
+ #
0
+ # ==== Examples
0
+ # {{[
0
+ # def _template_location
0
+ # "#{params[:controller]}.#{prams[:action]}.#{content_type}"
0
+ # ]}}
0
+ #
0
+ # This would look for templates at controller.action.mime.type instead
0
+ # of controller/action.mime.type
0
+ def _template_location
0
+ "#{params[:controller]}/#{params[:action]}.#{content_type}"
0
+ end
0
   
0
   cattr_accessor :_abstract_subclasses, :_template_path_cache
0
+ #---
0
+ # We're using abstract_subclasses so that Merb::Controller can have its
0
+ # own subclasses. We're using a Set so we don't have to worry about
0
+ # uniqueness.
0
   self._abstract_subclasses = Set.new
0
+ def self.subclasses_list() _abstract_subclasses end
0
   
0
   class << self
0
     # ==== Parameters
...
3
4
5
 
 
6
7
8
...
3
4
5
6
7
8
9
10
0
@@ -3,6 +3,8 @@ class Merb::Controller < AbstractController
0
   class_inheritable_accessor :_session_id_key, :_session_expiry, :_hidden_actions
0
   cattr_accessor :_subclasses, :_session_secret_key
0
   self._subclasses = Set.new
0
+ def self.subclasses_list() _subclasses end
0
+
0
   self.session_secret_key = nil
0
   self._session_id_key = '_session_id'
0
   self._session_expiry = Time.now + Merb::Const::WEEK * 2
...
61
62
63
64
 
65
66
67
...
61
62
63
 
64
65
66
67
0
@@ -61,7 +61,7 @@ module Merb::Template
0
     # {{[
0
     # Merb::Template.register_extensions(Merb::Template::Erubis, ["erb"])
0
     # ]}}
0
- def register_extensions(engine, extensions) enforce!(engine => Symbol, extensions => Array)
0
+ def register_extensions(engine, extensions) enforce!(engine => Class, extensions => Array)
0
       extensions.each{|ext| EXTENSIONS[ext] = engine }
0
     end
0
   end
...
1
 
2
3
4
 
5
...
 
1
2
 
3
4
5
0
@@ -1,3 +1,3 @@
0
-corelib = File.dirname(__FILE__) / "core_ext"
0
+corelib = File.join(File.dirname(__FILE__), "core_ext")
0
 
0
-Dir.glob["#{corelib}/*"].each {|fn| require (corelib / fn)}
0
\ No newline at end of file
0
+Dir.glob("#{corelib}/*").each {|fn| require(File.join(fn))}
0
\ No newline at end of file
...
3
4
5
6
 
7
8
9
...
184
185
186
187
 
188
189
190
...
3
4
5
 
6
7
8
9
...
184
185
186
 
187
188
189
190
0
@@ -3,7 +3,7 @@
0
 # to, for example, an array without those additions being shared with either their parent, siblings, or
0
 # children, which is unlike the regular class-level attributes that are shared across the entire hierarchy.
0
 class Class # :nodoc:
0
-
0
+
0
   def _attr_reader(*syms)
0
     syms.flatten.each do |sym|
0
       class_eval <<-EOS
0
@@ -184,7 +184,7 @@ class Class # :nodoc:
0
   def reset_inheritable_attributes
0
     @inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
0
   end
0
-
0
+
0
   private
0
     # Prevent this constant from being created multiple times
0
     EMPTY_INHERITABLE_ATTRIBUTES = {}.freeze unless const_defined?(:EMPTY_INHERITABLE_ATTRIBUTES)

Comments

    No one has commented yet.