webby 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/History.txt +19 -0
  2. data/Manifest.txt +19 -6
  3. data/README.txt +21 -5
  4. data/Rakefile +2 -3
  5. data/data/Rakefile +1 -1
  6. data/data/lib/breadcrumbs.rb +28 -0
  7. data/data/tasks/create.rake +0 -1
  8. data/data/tasks/deploy.rake +0 -1
  9. data/data/tasks/growl.rake +0 -1
  10. data/data/tasks/heel.rake +2 -3
  11. data/data/tasks/setup.rb +0 -1
  12. data/data/templates/_partial.erb +10 -0
  13. data/data/templates/atom_feed.erb +34 -0
  14. data/examples/webby/content/manual/index.txt +11 -13
  15. data/examples/webby/content/tutorial/index.txt +1 -1
  16. data/examples/webby/tasks/heel.rake +2 -2
  17. data/examples/webby/tasks/setup.rb +6 -1
  18. data/lib/webby.rb +50 -23
  19. data/lib/webby/auto_builder.rb +4 -2
  20. data/lib/webby/builder.rb +6 -5
  21. data/lib/webby/filters.rb +6 -7
  22. data/lib/webby/filters/outline.rb +4 -2
  23. data/lib/webby/filters/tidy.rb +4 -2
  24. data/lib/webby/helpers.rb +32 -0
  25. data/lib/webby/helpers/coderay_helper.rb +78 -0
  26. data/lib/webby/helpers/graphviz_helper.rb +158 -0
  27. data/lib/webby/helpers/tag_helper.rb +9 -4
  28. data/lib/webby/helpers/tex_img_helper.rb +181 -0
  29. data/lib/webby/helpers/url_helper.rb +12 -11
  30. data/lib/webby/renderer.rb +97 -18
  31. data/lib/webby/resources.rb +82 -0
  32. data/lib/webby/{pages_db.rb → resources/db.rb} +63 -33
  33. data/lib/webby/{file.rb → resources/file.rb} +27 -24
  34. data/lib/webby/resources/layout.rb +65 -0
  35. data/lib/webby/resources/page.rb +109 -0
  36. data/lib/webby/resources/partial.rb +81 -0
  37. data/lib/webby/resources/resource.rb +145 -0
  38. data/lib/webby/resources/static.rb +54 -0
  39. data/lib/webby/stelan/mktemp.rb +137 -0
  40. data/lib/webby/stelan/spawner.rb +5 -1
  41. data/lib/webby/utils.rb +3 -1
  42. data/lib/webby/webby_task.rb +43 -24
  43. data/spec/spec_helper.rb +12 -1
  44. data/spec/webby/{file_spec.rb → resources/file_spec.rb} +21 -22
  45. data/tasks/ann.rake +76 -0
  46. data/tasks/annotations.rake +6 -14
  47. data/tasks/bones.rake +40 -0
  48. data/tasks/doc.rake +1 -2
  49. data/tasks/gem.rake +29 -2
  50. data/tasks/manifest.rake +15 -21
  51. data/tasks/post_load.rake +22 -8
  52. data/tasks/setup.rb +53 -15
  53. data/tasks/spec.rake +13 -0
  54. metadata +22 -9
  55. data/lib/webby/filters/coderay.rb +0 -98
  56. data/lib/webby/filters/graphviz.rb +0 -189
  57. data/lib/webby/resource.rb +0 -293
@@ -1,293 +0,0 @@
1
- # $Id: resource.rb 102 2008-01-19 23:13:55Z tim_pease $
2
-
3
- module Webby
4
-
5
- # A Webby::Resource is any file that can be found in the content directory
6
- # or in the layout directory. This class contains information about the
7
- # resources available to Webby. This information includes the resource
8
- # type (static, page, layout), if the resource is dirty (it needs to be
9
- # rendered), the output location of the rendered resource, etc.
10
- #
11
- # A resource is a "layout" if the resource is found in the layout
12
- # directory. Static and page resources are found in the content directory.
13
- #
14
- # A resource is considered static only if it *does not* contain a YAML
15
- # meta-data header at the top of the file. These resources will be copied
16
- # as-is from the content directory to the output directory.
17
- #
18
- # If a resouce does have meta-data, then it will be processed (i.e.
19
- # rendered/filtered) by Webby, and the rendered results will be written to
20
- # the output directory.
21
- #
22
- class Resource
23
-
24
- instance_methods.each do |m|
25
- undef_method(m) unless m =~ %r/\A__/ ||
26
- m == 'class'
27
- end
28
-
29
- class << self
30
- # Returns the pages hash object.
31
- def pages
32
- @pages ||= PagesDB.new
33
- end
34
-
35
- # Returns the layouts hash object.
36
- def layouts
37
- @layouts ||= PagesDB.new
38
- end
39
-
40
- # Clear the contents of the +layouts+ and the +pages+ hash objects.
41
- def clear
42
- self.pages.clear
43
- self.layouts.clear
44
- end
45
- end # class << self
46
-
47
- # The full path to the resource file
48
- attr_reader :path
49
-
50
- # The directory of the resource excluding the content directory
51
- attr_reader :dir
52
-
53
- # The resource filename excluding path and extension
54
- attr_reader :filename
55
-
56
- # Extesion of the resource file
57
- attr_reader :ext
58
-
59
- # Resource file modification time
60
- attr_reader :mtime
61
-
62
- # Resource page number (if needed)
63
- attr_reader :number
64
-
65
- # call-seq:
66
- # Resource.new( filename ) => resource
67
- #
68
- # Creates a new resource object given the _filename_.
69
- #
70
- def initialize( fn )
71
- @path = fn.sub(%r/\A(?:\.\/|\/)/o, '').freeze
72
- @dir = Webby::File.dirname(@path)
73
- @filename = Webby::File.basename(@path)
74
- @ext = Webby::File.extname(@path)
75
- @mtime = ::File.mtime @path
76
-
77
- @number = nil
78
- @rendering = false
79
-
80
- # deal with the meta-data
81
- @mdata = ::Webby::File.meta_data(@path)
82
- @have_mdata = !@mdata.nil?
83
-
84
- @mdata ||= {}
85
- @mdata = ::Webby.site.page_defaults.merge(@mdata) if is_page?
86
- @mdata.sanitize!
87
-
88
- self.class.pages << self if is_page? or is_static?
89
- self.class.layouts << self if is_layout?
90
- end
91
-
92
- # call-seq:
93
- # equal?( other ) => true or false
94
- #
95
- # Returns +true+ if the path of this resource is equivalent to the path of
96
- # the _other_ resource. Returns +false+ if this is not the case.
97
- #
98
- def equal?( other )
99
- return false unless self.class == other.class
100
- @path == other.path
101
- end
102
- alias :== :equal?
103
- alias :eql? :equal?
104
-
105
- # call-seq:
106
- # resource <=> other => -1, 0, +1, or nil
107
- #
108
- # Resource comparison operates on the full path of the resource objects
109
- # and uses the standard String comparison operator. Returns +nil+ if
110
- # _other_ is not a Resource instance.
111
- #
112
- def <=>( other )
113
- return unless self.class == other.class
114
- @path <=> other.path
115
- end
116
-
117
- # call-seq:
118
- # extension => string
119
- #
120
- # Returns the extension that will be appended to the output destination
121
- # filename. The extension is determined by looking at the following:
122
- #
123
- # * this resource's meta-data for an 'extension' property
124
- # * the meta-data of this resource's layout for an 'extension' property
125
- # * the extension of this resource file
126
- #
127
- def extension
128
- return @mdata['extension'] if @mdata.has_key? 'extension'
129
-
130
- if @mdata.has_key? 'layout'
131
- lyt = self.class.layouts.find :filename => @mdata['layout']
132
- ext = lyt ? lyt.extension : nil
133
- return ext if ext
134
- end
135
-
136
- return (is_layout? ? nil : @ext)
137
- end
138
-
139
- # call-seq:
140
- # destination => string
141
- #
142
- # Returns the path in the output directory where the results of rendering
143
- # this resource should be stored. This path is used to determine if the
144
- # resource is dirty and in need of rendering.
145
- #
146
- # The destination for any resource can be overridden by explicitly setting
147
- # the 'destination' property in the resource's meta-data.
148
- #
149
- def destination
150
- return @dest if defined? @dest and @dest
151
- return @dest = ::Webby.cairn if is_layout?
152
-
153
- @dest = if @mdata.has_key? 'destination' then @mdata['destination']
154
- else ::File.join(dir, filename) end
155
-
156
- @dest = ::File.join(::Webby.site.output_dir, @dest)
157
- @dest << @number.to_s if @number
158
-
159
- ext = extension
160
- unless ext.nil? or ext.empty?
161
- @dest << '.'
162
- @dest << ext
163
- end
164
- @dest
165
- end
166
-
167
- # call-seq
168
- # url => string or nil
169
- #
170
- # Returns a string suitable for use as a URL linking to this page. Nil
171
- # is returned for layouts.
172
- #
173
- def url
174
- return nil if is_layout?
175
- return @url if defined? @url and @url
176
-
177
- @url = destination.sub(::Webby.site.output_dir, '')
178
- @url = File.dirname(@url) if filename == 'index'
179
- @url
180
- end
181
-
182
- # call-seq:
183
- # resource.number = Integer
184
- #
185
- # Sets the page number for the current resource to the given integer. This
186
- # number is used to modify the output destination for resources that
187
- # require pagination.
188
- #
189
- def number=( num )
190
- @number = num
191
- @dest = nil
192
- end
193
-
194
- # call-seq:
195
- # render => string
196
- #
197
- # Creates a new Webby::Renderer instance and uses that instance to render
198
- # the resource contents using the configured filter(s). The filter(s) to
199
- # use is defined in the resource's meta-data as the 'filter' key.
200
- #
201
- # Note, this only renders this resource. The returned string does not
202
- # include any layout rendering.
203
- #
204
- def render( renderer = nil )
205
- raise Error, "page '#@path' is in a rendering loop" if @rendering
206
-
207
- @rendering = true
208
- renderer ||= Renderer.new(self)
209
- content = renderer.render_page
210
- @rendering = false
211
-
212
- return content
213
-
214
- rescue
215
- @rendering = false
216
- raise
217
- end
218
-
219
- # call-seq:
220
- # is_layout? => true or false
221
- #
222
- # Returns +true+ if this resource is a layout.
223
- #
224
- def is_layout?
225
- @is_layout ||=
226
- !(%r/\A(?:\.\/|\/)?#{::Webby.site.layout_dir}\//o =~ @path).nil?
227
- end
228
-
229
- # call-seq:
230
- # is_static? => true or false
231
- #
232
- # Returns +true+ if this resource is a static file.
233
- #
234
- def is_static?
235
- !@have_mdata
236
- end
237
-
238
- # call-seq:
239
- # is_page? => true or false
240
- #
241
- # Returns +true+ if this resource is a page suitable for rendering.
242
- #
243
- def is_page?
244
- @have_mdata and !is_layout?
245
- end
246
-
247
- # call-seq:
248
- # dirty? => true or false
249
- #
250
- # Returns +true+ if this resource is newer than its corresponding output
251
- # product. The resource needs to be rendered (if a page or layout) or
252
- # copied (if a static file) to the output directory.
253
- #
254
- def dirty?
255
- return @mdata['dirty'] if @mdata.has_key? 'dirty'
256
-
257
- # if the destination file does not exist, then we are dirty
258
- return true unless test ?e, destination
259
-
260
- # if this file's mtime is larger than the destination file's
261
- # mtime, then we are dirty
262
- dirty = @mtime > ::File.mtime(destination)
263
- return dirty if is_static? or dirty
264
-
265
- # check to see if the layout is dirty, and it it is then we
266
- # are dirty, too
267
- if @mdata.has_key? 'layout'
268
- lyt = self.class.layouts.find :filename => @mdata['layout']
269
- unless lyt.nil?
270
- return true if lyt.dirty?
271
- end
272
- end
273
-
274
- # if we got here, then we are not dirty
275
- false
276
- end
277
-
278
- # call-seq:
279
- # method_missing( symbol [, *args, &block] ) => result
280
- #
281
- # Invoked by Ruby when a message is sent to the resource that it cannot
282
- # handle. The default behavior is to convert _symbol_ to a string and
283
- # search for that string in the resource's meta-data. If found, the
284
- # meta-data item is returned; otherwise, +nil+ is returned.
285
- #
286
- def method_missing( name, *a, &b )
287
- @mdata[name.to_s]
288
- end
289
-
290
- end # class Resource
291
- end # module Webby
292
-
293
- # EOF