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
Using a pages database class instaed of an array for the pages
and the layouts.
Tim Pease (author)
Tue Aug 21 21:25:49 -0700 2007
commit  93c2bc08e6b75c58cb9967ab471d34def1e4f07e
tree    e260a765db43b1278f0158950c16843144f54c30
parent  7f3cf829178655d3c27b661bdf4e2a4245ed665b
...
29
30
31
 
32
33
34
...
29
30
31
32
33
34
35
0
@@ -29,6 +29,7 @@ lib/webby/auto_builder.rb
0
 lib/webby/builder.rb
0
 lib/webby/file.rb
0
 lib/webby/main.rb
0
+lib/webby/pages_db.rb
0
 lib/webby/renderer.rb
0
 lib/webby/resource.rb
0
 lib/webby/utils.rb
...
50
51
52
 
 
53
54
55
...
50
51
52
53
54
55
56
57
0
@@ -50,6 +50,8 @@ class AutoBuilder
0
     print '- started at '
0
     puts Time.now.strftime('%H:%M:%S')
0
     Builder.run
0
+ rescue => err
0
+ puts err.message
0
   end
0
 
0
   # call-seq:
...
70
71
72
73
 
74
75
76
...
70
71
72
 
73
74
75
76
0
@@ -70,7 +70,7 @@ class Builder
0
   # more recently than the output file.
0
   #
0
   def run( opts = {} )
0
- Resource.reset
0
+ Resource.clear
0
 
0
     unless test(?d, output_dir)
0
       puts "creating #{output_dir}"
...
7
8
9
10
11
12
 
13
14
15
16
17
18
19
20
21
22
 
23
24
25
26
27
 
 
 
28
29
30
...
32
33
34
35
36
 
 
37
38
39
 
40
41
42
...
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
54
55
...
137
138
139
140
 
141
142
143
...
152
153
154
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
183
...
7
8
9
 
10
 
11
12
13
14
 
 
 
 
 
 
 
15
16
17
 
 
 
18
19
20
21
22
23
...
25
26
27
 
 
28
29
30
 
31
32
33
34
35
...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
...
149
150
151
 
152
153
154
155
...
164
165
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
168
169
0
@@ -7,24 +7,17 @@ module Webby
0
 class Resource
0
 
0
   class << self
0
-
0
     def pages
0
- @pages ||= []
0
+ @pages ||= PagesDB.new
0
     end
0
 
0
     def layouts
0
- return @layouts if defined? @layouts and @layouts
0
-
0
- @layouts = []
0
- class << @layouts
0
- def find_by_name( name ) find {|x| x.filename == name} end
0
- end
0
- @layouts
0
+ @layouts ||= PagesDB.new
0
     end
0
 
0
- def reset
0
- @pages = nil
0
- @layouts = nil
0
+ def clear
0
+ self.pages.clear
0
+ self.layouts.clear
0
     end
0
   end # class << self
0
 
0
@@ -32,11 +25,11 @@ class Resource
0
   # Resource.new( filename, defaults = {} ) => page
0
   #
0
   def initialize( fn, defaults = {} )
0
- @path = fn.dup.freeze
0
- @dir = ::File.dirname(@path).sub(%r/\A(?:\.\/|\/)?[^\/]+\/?/o, '')
0
+ @path = fn.sub(%r/\A(?:\.\/|\/)/o, '').freeze
0
+ @dir = ::File.dirname(@path).sub(%r/\A[^\/]+\/?/o, '')
0
     @filename = ::File.basename(@path).sub(%r/\.\w+\z/o, '')
0
- @mtime = ::File.mtime @path
0
     @ext = ::File.extname(@path).sub(%r/\A\.?/o, '')
0
+ @mtime = ::File.mtime @path
0
 
0
     @rendering = false
0
 
0
@@ -50,6 +43,25 @@ class Resource
0
     self.class.layouts << self if is_layout?
0
   end
0
 
0
+ # call-seq:
0
+ # equal?( other ) => true or false
0
+ #
0
+ def equal?( other )
0
+ return false unless self.class == other.class
0
+ @path == other.path
0
+ end
0
+ alias :== :equal?
0
+ alias :eql? :equal?
0
+
0
+ # call-seq:
0
+ # resource <=> other => -1, 0, +1, or nil
0
+ #
0
+ def <=>( other )
0
+ return unless self.class == other.class
0
+ @path <=> other.path
0
+ end
0
+
0
+
0
   attr_reader :path, :dir, :filename, :mtime, :ext
0
 
0
   # call-seq:
0
@@ -137,7 +149,7 @@ class Resource
0
 
0
     # if this file's mtime is larger than the destination file's
0
     # mtime, then we are dirty
0
- @mdata['dirty'] = @mtime >= File.mtime(destination)
0
+ @mdata['dirty'] = @mtime > File.mtime(destination)
0
     return @mdata['dirty'] if is_static? or @mdata['dirty']
0
 
0
     # check to see if the layout is dirty, and it it is then we
0
@@ -152,32 +164,6 @@ class Resource
0
     @mdata['dirty'] = false
0
   end
0
 
0
- def siblings( opts = {} )
0
- return nil unless is_page?
0
-
0
- ary = self.class.pages.find_all {|p| @dir == p.dir}
0
- ary.delete self
0
- return ary unless opts.has_key? :sort_by
0
-
0
- m = opts[:sort_by]
0
- ary.sort! {|a,b| a.send(m) <=> b.send(m)}
0
- ary.reverse! if opts[:reverse]
0
- ary
0
- end
0
-
0
- def children( opts = {} )
0
- return nil unless is_page?
0
-
0
- rgxp = Regexp.new "\\A#@dir/[^/]+"
0
- ary = self.class.pages.find_all {|p| rgxp =~ p.dir}
0
- return ary unless opts.has_key? :sort_by
0
-
0
- m = opts[:sort_by]
0
- ary.sort! {|a,b| a.send(m) <=> b.send(m)}
0
- ary.reverse! if opts[:reverse]
0
- ary
0
- end
0
-
0
   def method_missing( name, *a, &b )
0
     @mdata[name.to_s]
0
   end

Comments

    No one has commented yet.