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

public
Rubygem
Description: A lightweight and flexible website management system.
Homepage: http://webby.rubyforge.org/
Clone URL: git://github.com/TwP/webby.git
partials now support local variables
Tim Pease (author)
Sat Apr 12 20:43:57 -0700 2008
commit  0c97a9a006c2d297cdf3efe30d7637a34c67d4c0
tree    02a7b3287005cd1e139bb314aa5914e168ad037f
parent  fc60bf3afb6ed2f5e6925a9ec8e004b2840531db
...
2
3
4
5
 
6
7
8
9
 
 
10
 
11
12
13
...
2
3
4
 
5
6
7
8
 
9
10
11
12
13
14
15
0
@@ -2,12 +2,14 @@
0
 
0
 * 1 major enhancement
0
   - Added blogging support
0
-* 3 minor enhancements
0
+* 4 minor enhancements
0
   - Changed the arguments to the DB#find method
0
   - Added locals support for page templates
0
   - Updated atom feed generation template
0
-* 1 bug fix
0
+ - Partials now support local variables when rendering
0
+* 2 bug fix
0
   - Fixed reference to an non-existent Error class
0
+ - Basepath filter now handles XML files properly
0
 
0
 == 0.8.2 / 2008-03-12
0
 
...
64
65
66
 
67
68
69
...
80
81
82
83
 
84
85
86
...
108
109
110
 
111
112
113
...
140
141
142
143
 
144
145
146
...
229
230
231
 
232
233
234
...
240
241
242
 
243
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
246
247
...
64
65
66
67
68
69
70
...
81
82
83
 
84
85
86
87
...
109
110
111
112
113
114
115
...
142
143
144
 
145
146
147
148
...
231
232
233
234
235
236
237
...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
0
@@ -64,6 +64,7 @@ class Renderer
0
     @content = nil
0
     @config = ::Webby.site
0
 
0
+ @_bindings = []
0
     @log = Logging::Logger[self]
0
   end
0
 
0
@@ -80,7 +81,7 @@ class Renderer
0
   end
0
 
0
   # call-seq:
0
- # render_partial( partial ) => string
0
+ # render_partial( partial, :locals => {} ) => string
0
   #
0
   # Render the given _partial_ into the current page. The _partial_ can
0
   # either be the name of the partial to render or a Partial object.
0
@@ -108,6 +109,7 @@ class Renderer
0
       else raise ::Webby::Error, "expecting a partial or a partial name" end
0
 
0
     _track_rendering(part.path) {
0
+ _configure_locals(opts[:locals])
0
       Filters.process(self, part, ::Webby::Resources::File.read(part.path))
0
     }
0
   end
0
@@ -140,7 +142,7 @@ class Renderer
0
   # Returns the current binding for the renderer.
0
   #
0
   def get_binding
0
- binding
0
+ @_bindings.last
0
   end
0
 
0
 
0
@@ -229,6 +231,7 @@ class Renderer
0
   def _track_rendering( path )
0
     loop_error = @@stack.include? path
0
     @@stack << path
0
+ @_bindings << _binding
0
 
0
     if loop_error
0
       msg = "rendering loop detected for '#{path}'\n"
0
@@ -240,8 +243,30 @@ class Renderer
0
     yield
0
   ensure
0
     @@stack.pop if path == @@stack.last
0
+ @_bindings.pop
0
   end
0
 
0
+ # call-seq:
0
+ # _configure_locals( locals )
0
+ #
0
+ # Configure local variables in the scope of the current binding returned
0
+ # by the +get_binding+ method. The _locals_ should be given as a hash of
0
+ # name / value pairs.
0
+ #
0
+ def _configure_locals( locals )
0
+ return if locals.nil?
0
+
0
+ locals.each do |k,v|
0
+ Thread.current[:value] = v
0
+ definition = "#{k} = Thread.current[:value]"
0
+ eval(definition, get_binding)
0
+ end
0
+ end
0
+
0
+ # Returns the binding in the scope of this Renderer object.
0
+ #
0
+ def _binding() binding end
0
+
0
 end # class Renderer
0
 end # module Webby
0
 

Comments

    No one has commented yet.