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
Search Repo:
Fixes for capture/concat
wycats (author)
Mon Feb 18 19:19:26 -0800 2008
commit  3d023b06e4da0bfc9edbb28ee92fd2bec762b31a
tree    6249c26c22c40bbe8dc6953e55d7382a290622ec
parent  a952c9895541975ee64689782f9a6023e9416f28
...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
174
175
176
 
 
 
 
 
 
 
 
...
9
10
11
 
 
 
 
 
 
 
 
 
12
13
14
...
165
166
167
168
169
170
171
172
173
174
175
0
@@ -9,15 +9,6 @@ $LOAD_PATH.unshift File.dirname(__FILE__) unless
0
   $LOAD_PATH.include?(File.dirname(__FILE__)) ||
0
   $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
0
 
0
-require 'merb-core/autoload'
0
-require 'merb-core/server'
0
-require 'merb-core/core_ext'
0
-require 'merb-core/gem_ext/erubis'
0
-require 'merb-core/logger'
0
-require 'merb-core/version'
0
-require 'merb-core/controller/mime'
0
-require 'merb-core/vendor/facets'
0
-
0
 begin
0
   require "json/ext"
0
 rescue LoadError
0
@@ -174,3 +165,11 @@ module Merb
0
   end
0
 
0
 end
0
+
0
+require 'merb-core/autoload'
0
+require 'merb-core/server'
0
+require 'merb-core/gem_ext/erubis'
0
+require 'merb-core/logger'
0
+require 'merb-core/version'
0
+require 'merb-core/controller/mime'
0
+require 'merb-core/vendor/facets'
...
9
10
11
12
13
14
15
...
21
22
23
 
 
24
25
26
...
9
10
11
 
12
13
14
...
20
21
22
23
24
25
26
27
0
@@ -9,7 +9,6 @@ module Merb
0
   autoload :Cookies, "merb-core/dispatch/cookies"
0
   autoload :Dispatcher, "merb-core/dispatch/dispatcher"
0
   autoload :ErubisCaptureMixin, "merb-core/controller/mixins/erubis_capture"
0
- autoload :Hook, "merb-core/hook"
0
   autoload :Plugins, "merb-core/plugins"
0
   autoload :Rack, "merb-core/rack"
0
   autoload :RenderMixin, "merb-core/controller/mixins/render"
0
@@ -21,6 +20,8 @@ end
0
 
0
 # Require this rather than autoloading it so we can be sure the default template
0
 # gets registered
0
+require 'merb-core/core_ext'
0
+require 'merb-core/hook'
0
 require "merb-core/controller/template"
0
 require "merb-core/hook"
0
 
...
71
72
73
74
 
75
76
77
...
116
117
118
119
120
121
122
...
125
126
127
128
129
 
 
 
 
 
130
131
132
...
153
154
155
 
156
157
158
...
376
377
378
 
 
 
 
379
380
381
...
71
72
73
 
74
75
76
77
...
116
117
118
 
119
120
121
...
124
125
126
 
 
127
128
129
130
131
132
133
134
...
155
156
157
158
159
160
161
...
379
380
381
382
383
384
385
386
387
388
0
@@ -71,7 +71,7 @@ class Merb::AbstractController
0
   include Merb::InlineTemplates
0
   is_hookable
0
   
0
- class_inheritable_accessor :_before_filters, :_after_filters, :_template_root, :_layout
0
+ class_inheritable_accessor :_before_filters, :_after_filters, :_layout, :_template_root
0
 
0
   # Controller name is part of the public API
0
   def self.controller_name() @controller_name ||= self.name.to_const_path end
0
@@ -116,7 +116,6 @@ class Merb::AbstractController
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
- self._template_root = Merb.dir_for(:view)
0
 
0
   def self.subclasses_list() _abstract_subclasses end
0
   
0
@@ -125,8 +124,11 @@ class Merb::AbstractController
0
     # klass<Merb::AbstractController>::
0
     # The controller that is being inherited from Merb::AbstractController
0
     def inherited(klass)
0
- _abstract_subclasses << klass.to_s
0
- klass.send(:include, Object.full_const_get("Merb::#{klass}Helper")) rescue nil
0
+ _abstract_subclasses << klass.to_s
0
+ self._template_root = Merb.dir_for(:view) unless self._template_root
0
+ klass.class_eval <<-HERE
0
+ include Object.full_const_get("Merb::#{klass}Helper") rescue nil
0
+ HERE
0
       super
0
     end
0
     
0
@@ -153,6 +155,7 @@ class Merb::AbstractController
0
   def initialize(*args)
0
     @_benchmarks = {}
0
     @_caught_content = {}
0
+ @_template_stack = []
0
   end
0
   
0
   # This will dispatch the request, calling before and after dispatch hooks
0
@@ -376,6 +379,10 @@ class Merb::AbstractController
0
     opts[:exclude] = Array(opts[:exclude]).map {|x| x.to_s} if opts[:exclude]
0
     return opts
0
   end
0
+
0
+ def capture(*args, &block)
0
+ send("capture_#{@_engine}", *args, &block)
0
+ end
0
 
0
   def method_missing(sym, *args, &blk)
0
     return @_merb_partial_locals[sym] if @_merb_partial_locals && @_merb_partial_locals.key?(sym)
...
62
63
64
65
 
66
67
 
 
68
69
70
...
145
146
147
148
 
149
150
151
...
196
197
198
199
 
200
201
202
...
257
258
259
260
 
261
262
263
264
265
266
 
 
267
268
269
 
 
 
 
270
271
272
...
62
63
64
 
65
66
67
68
69
70
71
72
...
147
148
149
 
150
151
152
153
...
198
199
200
 
201
202
203
204
...
259
260
261
 
262
263
264
265
266
 
 
267
268
269
270
271
272
273
274
275
276
277
278
0
@@ -62,9 +62,11 @@ module Merb::RenderMixin
0
       template_location = _template_root / (opts[:template] || _template_location(thing, content_type))
0
       
0
       # Get the method name from the previously inlined list
0
- template_method = Merb::Template.template_for(template_location)
0
+ template_method = _template_for(template_location)
0
 
0
       # Raise an error if there's no template
0
+ require 'ruby-debug'
0
+ debugger if $DEBUG
0
       raise TemplateNotFound, "No template found at #{template_location}" unless
0
         template_method && self.respond_to?(template_method)
0
 
0
@@ -145,7 +147,7 @@ module Merb::RenderMixin
0
       # Look for the layout under the default layout directly. If it's not found, reraise
0
       # the TemplateNotFound error
0
       template = _template_location(opts[:layout], layout.index(".") ? content_type : nil, "layout")
0
- layout = Merb::Template.template_for(_template_root / template) ||
0
+ layout = _template_for(_template_root / template) ||
0
         (raise TemplateNotFound, "No layout found at #{_template_root / template}.*")
0
               
0
       # If the layout was found, call it
0
@@ -196,7 +198,7 @@ module Merb::RenderMixin
0
     template_location = _template_root / _template_location(template, content_type, kontroller)
0
     
0
     # Get the method name from the previously inlined list
0
- template_method = Merb::Template.template_for(template_location)
0
+ template_method = _template_for(template_location)
0
 
0
     if opts.key?(:with)
0
       with = opts.delete(:with)
0
@@ -257,16 +259,20 @@ module Merb::RenderMixin
0
     # If a layout was provided, throw an error if it's not found
0
     if layout
0
       template = _template_location(layout, layout.index(".") ? nil : content_type, "layout")
0
- Merb::Template.template_for(_template_root / template) ||
0
+ _template_for(_template_root / template) ||
0
         (raise TemplateNotFound, "No layout found at #{_template_root / template}.*")
0
     
0
     # If a layout was not provided, try the default locations
0
     else
0
- Merb::Template.template_for(_template_root / _template_location(controller_name, content_type, "layout")) ||
0
- Merb::Template.template_for(_template_root / _template_location("application", content_type, "layout")) || nil
0
+ _template_for(_template_root / _template_location(controller_name, content_type, "layout")) ||
0
+ _template_for(_template_root / _template_location("application", content_type, "layout")) || nil
0
     end
0
   end
0
   
0
+ def _template_for(path)
0
+ Merb::Template.template_for(path)
0
+ end
0
+
0
   # Called in templates to get at content thrown in another template.
0
   # The results of rendering a template are automatically thrown
0
   # into :layout, so catch_content or catch_content(:layout) can be
...
 
 
 
1
2
3
...
28
29
30
31
 
32
33
 
 
34
 
35
36
37
 
 
 
 
38
 
 
39
40
41
...
90
91
92
 
 
 
93
94
95
...
103
104
105
106
 
107
108
109
110
111
112
 
113
114
115
...
122
123
124
125
 
126
127
 
128
129
130
...
142
143
144
145
 
 
 
 
 
146
147
148
149
150
151
 
 
 
 
 
 
 
 
 
 
 
 
152
153
...
1
2
3
4
5
6
...
31
32
33
 
34
35
 
36
37
38
39
40
41
 
42
43
44
45
46
47
48
49
50
51
...
100
101
102
103
104
105
106
107
108
...
116
117
118
 
119
120
121
122
123
124
 
125
126
127
128
...
135
136
137
 
138
139
 
140
141
142
143
...
155
156
157
 
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
0
@@ -1,3 +1,6 @@
0
+module Merb::InlineTemplates
0
+end
0
+
0
 module Merb::Template
0
   
0
   EXTENSIONS = {} unless defined?(EXTENSIONS)
0
@@ -28,14 +31,21 @@ module Merb::Template
0
     # path<String>:: A full path to find a template method for
0
     #---
0
     # @semipublic
0
- def template_for(path)
0
+ def template_for(path, template_stack = [])
0
       path = File.expand_path(path)
0
- file = Dir["#{path}.{#{Merb::Template::EXTENSIONS.keys.join(',')}}"].first
0
+
0
+ ret =
0
       if Merb::Config[:reload_templates]
0
+ file = Dir["#{path}.{#{Merb::Template::EXTENSIONS.keys.join(',')}}"].first
0
         METHOD_LIST[path] = file ? inline_template(file) : nil
0
       else
0
- METHOD_LIST[path] ||= file ? inline_template(file) : nil
0
+ METHOD_LIST[path] ||= begin
0
+ file = Dir["#{path}.{#{Merb::Template::EXTENSIONS.keys.join(',')}}"].first
0
+ file ? inline_template(file) : nil
0
+ end
0
       end
0
+
0
+ ret
0
     end
0
     
0
     # Takes a template at a particular path and inlines it into
0
@@ -90,6 +100,9 @@ module Merb::Template
0
       raise ArgumentError, "The class you are registering does not have a compile_template method" unless
0
         engine.respond_to?(:compile_template)
0
       extensions.each{|ext| EXTENSIONS[ext] = engine }
0
+ Merb::AbstractController.class_eval <<-HERE
0
+ include #{engine}::Mixin
0
+ HERE
0
     end
0
   end
0
   
0
@@ -103,13 +116,13 @@ module Merb::Template
0
     def self.compile_template(path, name, mod)
0
       template = ::Erubis::Eruby.new(File.read(path))
0
       template.def_method(mod, name, path)
0
- name
0
+ name
0
     end
0
 
0
     module Mixin
0
       
0
       # Provides direct acccess to the buffer for this view context
0
- def _buffer( the_binding )
0
+ def _erb_buffer( the_binding )
0
         @_buffer = eval( "_buf", the_binding, __FILE__, __LINE__)
0
       end
0
 
0
@@ -122,9 +135,9 @@ module Merb::Template
0
       # <% @foo = capture do %>
0
       # <p>Some Foo content!</p>
0
       # <% end %>
0
- def capture(*args, &block)
0
+ def capture_erb(*args, &block)
0
         # get the buffer from the block's binding
0
- buffer = _buffer( block.binding ) rescue nil
0
+ buffer = _erb_buffer( block.binding ) rescue nil
0
 
0
         # If there is no buffer, just call the block and get the contents
0
         if buffer.nil?
0
@@ -142,11 +155,27 @@ module Merb::Template
0
 
0
           data
0
         end
0
- end
0
+ end
0
+
0
+ def concat_erb(string, binding)
0
+ _erb_buffer(binding) << string
0
+ end
0
             
0
     end
0
   
0
     Merb::Template.register_extensions(self, %w[erb])
0
   end
0
   
0
+end
0
+
0
+module Erubis
0
+ module RubyEvaluator
0
+
0
+ def def_method(object, method_name, filename=nil)
0
+ m = object.is_a?(Module) ? :module_eval : :instance_eval
0
+ setup = "@_engine = 'erb'"
0
+ object.__send__(m, "def #{method_name}; #{setup}; #{@src}; end", filename || @filename || '(erubis)')
0
+ end
0
+
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
...
 
1
2
3
 
 
 
4
5
6
7
 
 
 
8
9
10
11
 
 
 
12
13
14
15
 
 
 
16
17
18
19
 
 
20
21
22
23
24
0
@@ -1,21 +1,23 @@
0
-class Merb::SimpleSet < Hash
0
+module Merb
0
+ class SimpleSet < Hash
0
 
0
- def initialize(arr = [])
0
- arr.each {|x| self[x] = true}
0
- end
0
+ def initialize(arr = [])
0
+ arr.each {|x| self[x] = true}
0
+ end
0
 
0
- def <<(value)
0
- self[value] = true
0
- end
0
+ def <<(value)
0
+ self[value] = true
0
+ end
0
 
0
- def merge(arr)
0
- super(arr.inject({}) {|s,x| s[x] = true; s })
0
- end
0
+ def merge(arr)
0
+ super(arr.inject({}) {|s,x| s[x] = true; s })
0
+ end
0
 
0
- def inspect
0
- "#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>"
0
- end
0
+ def inspect
0
+ "#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>"
0
+ end
0
   
0
- alias_method :to_a, :keys
0
-
0
+ alias_method :to_a, :keys
0
+
0
+ end
0
 end
0
\ No newline at end of file
...
8
9
10
11
12
13
14
15
16
17
18
19
20
 
 
 
 
 
 
 
 
 
 
21
22
23
...
8
9
10
 
 
 
 
 
 
 
 
 
 
11
12
13
14
15
16
17
18
19
20
21
22
23
0
@@ -8,16 +8,16 @@ hsh = {:x => true, :y => true}
0
 set = Set.new([:x, :y])
0
 fst = FasterSet.new([:x, :y])
0
 
0
-# Benchmark.bmbm do |x|
0
-# x.report("current included") { TIMES.times { hsh[:x] } }
0
-# x.report("hash included") { TIMES.times { hsh.include?(:x) } }
0
-# x.report("set included") { TIMES.times { set.include?(:x) } }
0
-# x.report("fasterset included") { TIMES.times { fst.include?(:x) } }
0
-# x.report("current !included") { TIMES.times { hsh[:z] } }
0
-# x.report("hash !included") { TIMES.times { hsh.include?(:z) } }
0
-# x.report("set !included") { TIMES.times { set.include?(:z) } }
0
-# x.report("fasterset !included") { TIMES.times { fst.include?(:z) } }
0
-# end
0
+Benchmark.bmbm do |x|
0
+ x.report("current included") { TIMES.times { hsh[:x] } }
0
+ x.report("hash included") { TIMES.times { hsh.include?(:x) } }
0
+ x.report("set included") { TIMES.times { set.include?(:x) } }
0
+ x.report("fasterset included") { TIMES.times { fst.include?(:x) } }
0
+ x.report("current !included") { TIMES.times { hsh[:z] } }
0
+ x.report("hash !included") { TIMES.times { hsh.include?(:z) } }
0
+ x.report("set !included") { TIMES.times { set.include?(:z) } }
0
+ x.report("fasterset !included") { TIMES.times { fst.include?(:z) } }
0
+end
0
 
0
 # TIMES = 1_000_000
0
 # user system total real
...
42
43
44
 
 
 
45
46
47
...
42
43
44
45
46
47
48
49
50
0
@@ -42,6 +42,9 @@ module Merb::Test::Fixtures
0
         end
0
       EOS
0
     end
0
+
0
+ module Mixin
0
+ end
0
   end
0
 
0
   module MyHelpers

Comments

    No one has commented yet.