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
@@ -0,0 +1,81 @@
1
+ # $Id: partial.rb 167 2008-02-24 00:59:54Z tim_pease $
2
+
3
+ require Webby.libpath(*%w[webby resources resource])
4
+
5
+ module Webby::Resources
6
+
7
+ # A Partial is a file in the content folder whose filename starts with an
8
+ # underscore "_" character. Partials contain text that can be included into
9
+ # other pages. Partials are not standalone pages, and they will never
10
+ # correspond directly to an output file.
11
+ #
12
+ # Partials can contain YAML meta-data at the top of the file. This
13
+ # information is only used to determin the filters to apply to the
14
+ # partial. If there is no meta-data, then the partial text is used "as is"
15
+ # without any processing by the Webby rendering engine.
16
+ #
17
+ class Partial < Resource
18
+
19
+ # call-seq:
20
+ # Partial.new( path )
21
+ #
22
+ # Creates a new Partial object given the full path to the partial file.
23
+ # Partial filenames start with an underscore (this is an enforced
24
+ # convention).
25
+ #
26
+ def initialize( fn )
27
+ super
28
+
29
+ @mdata = ::Webby::Resources::File.meta_data(@path)
30
+ @mdata ||= {}
31
+ @mdata.sanitize!
32
+ end
33
+
34
+ # call-seq:
35
+ # dirty? => true or false
36
+ #
37
+ # Returns +true+ if this resource is newer than its corresponding output
38
+ # product. The resource needs to be rendered (if a page or layout) or
39
+ # copied (if a static file) to the output directory.
40
+ #
41
+ def dirty?
42
+ return @mdata['dirty'] if @mdata.has_key? 'dirty'
43
+
44
+ # if the destination file does not exist, then we are dirty
45
+ return true unless test(?e, destination)
46
+
47
+ # if this file's mtime is larger than the destination file's
48
+ # mtime, then we are dirty
49
+ dirty = @mtime > ::File.mtime(destination)
50
+ return dirty if dirty
51
+
52
+ # if we got here, then we are not dirty
53
+ false
54
+ end
55
+
56
+ # call-seq:
57
+ # destination => string
58
+ #
59
+ # The output file destination for the partial. This is the ".cairn" file in
60
+ # the output folder. It is used to determine if the partial is newer than
61
+ # the build products.
62
+ #
63
+ def destination
64
+ ::Webby.cairn
65
+ end
66
+
67
+ alias :extension :ext
68
+
69
+ # call-seq:
70
+ # url => nil
71
+ #
72
+ # Partials do not have a URL. This method will alwasy return +nil+.
73
+ #
74
+ def url
75
+ nil
76
+ end
77
+
78
+ end # class Partial
79
+ end # module Webby::Resources
80
+
81
+ # EOF
@@ -0,0 +1,145 @@
1
+ # $Id: resource.rb 167 2008-02-24 00:59:54Z tim_pease $
2
+
3
+ unless defined? Webby::Resources::Resource
4
+
5
+ module Webby::Resources
6
+
7
+ # A Webby::Resource is any file that can be found in the content directory
8
+ # or in the layout directory. This class contains information about the
9
+ # resources available to Webby.
10
+ #
11
+ class Resource
12
+
13
+ instance_methods.each do |m|
14
+ undef_method(m) unless m =~ %r/\A__|\?$/ ||
15
+ m == 'class'
16
+ end
17
+
18
+ # The full path to the resource file
19
+ attr_reader :path
20
+
21
+ # The directory of the resource excluding the content directory
22
+ attr_reader :dir
23
+
24
+ # The resource filename excluding path and extension
25
+ attr_reader :filename
26
+
27
+ # Extesion of the resource file
28
+ attr_reader :ext
29
+
30
+ # Resource file modification time
31
+ attr_reader :mtime
32
+
33
+ # call-seq:
34
+ # Resource.new( filename ) => resource
35
+ #
36
+ # Creates a new resource object given the _filename_.
37
+ #
38
+ def initialize( fn )
39
+ @path = fn
40
+ @dir = ::Webby::Resources::File.dirname(@path)
41
+ @filename = ::Webby::Resources::File.basename(@path)
42
+ @ext = ::Webby::Resources::File.extname(@path)
43
+ @mtime = ::File.mtime @path
44
+
45
+ @mdata = @@mdata ||= {}
46
+ end
47
+
48
+ # call-seq:
49
+ # equal?( other ) => true or false
50
+ #
51
+ # Returns +true+ if the path of this resource is equivalent to the path of
52
+ # the _other_ resource. Returns +false+ if this is not the case.
53
+ #
54
+ def equal?( other )
55
+ return false unless other.kind_of? ::Webby::Resources::Resource
56
+ @path == other.path
57
+ end
58
+ alias :== :equal?
59
+ alias :eql? :equal?
60
+
61
+ # call-seq:
62
+ # resource <=> other => -1, 0, +1, or nil
63
+ #
64
+ # Resource comparison operates on the full path of the resource objects
65
+ # and uses the standard String comparison operator. Returns +nil+ if
66
+ # _other_ is not a Resource instance.
67
+ #
68
+ def <=>( other )
69
+ return unless other.kind_of? ::Webby::Resources::Resource
70
+ @path <=> other.path
71
+ end
72
+
73
+ # call-seq:
74
+ # method_missing( symbol [, *args, &block] ) => result
75
+ #
76
+ # Invoked by Ruby when a message is sent to the resource that it cannot
77
+ # handle. The default behavior is to convert _symbol_ to a string and
78
+ # search for that string in the resource's meta-data. If found, the
79
+ # meta-data item is returned; otherwise, +nil+ is returned.
80
+ #
81
+ def method_missing( name, *a, &b )
82
+ @mdata[name.to_s]
83
+ end
84
+
85
+ # call-seq:
86
+ # dirty? => true or false
87
+ #
88
+ # Returns +true+ if this resource is newer than its corresponding output
89
+ # product. The resource needs to be rendered (if a page or layout) or
90
+ # copied (if a static file) to the output directory.
91
+ #
92
+ def dirty?
93
+ return @mdata['dirty'] if @mdata.has_key? 'dirty'
94
+
95
+ # if the destination file does not exist, then we are dirty
96
+ return true unless test(?e, destination)
97
+
98
+ # if this file's mtime is larger than the destination file's
99
+ # mtime, then we are dirty
100
+ dirty = @mtime > ::File.mtime(destination)
101
+ return dirty if dirty
102
+
103
+ # check to see if the layout is dirty, and if it is then we
104
+ # are dirty, too
105
+ if @mdata.has_key? 'layout'
106
+ lyt = ::Webby::Resources.layouts.find :filename => @mdata['layout']
107
+ unless lyt.nil?
108
+ return true if lyt.dirty?
109
+ end
110
+ end
111
+
112
+ # if we got here, then we are not dirty
113
+ false
114
+ end
115
+
116
+ # call-seq
117
+ # url => string or nil
118
+ #
119
+ # Returns a string suitable for use as a URL linking to this page. Nil
120
+ # is returned for layouts.
121
+ #
122
+ def url
123
+ return @url if defined? @url and @url
124
+
125
+ @url = destination.sub(::Webby.site.output_dir, '')
126
+ @url = File.dirname(@url) if filename == 'index'
127
+ @url
128
+ end
129
+
130
+ # :stopdoc:
131
+ def destination
132
+ raise NotImplementedError
133
+ end
134
+
135
+ def extension
136
+ raise NotImplementedError
137
+ end
138
+ # :startdoc:
139
+
140
+ end # class Resource
141
+ end # module Webby::Resources
142
+
143
+ end # unless defined?
144
+
145
+ # EOF
@@ -0,0 +1,54 @@
1
+ # $Id: static.rb 167 2008-02-24 00:59:54Z tim_pease $
2
+
3
+ require Webby.libpath(*%w[webby resources resource])
4
+
5
+ module Webby::Resources
6
+
7
+ # A Static resource is any file in the content folder that does not
8
+ # contain YAML meta-data at the top of the file and does not start with
9
+ # and underscore "_" character (those are partials). Static resources will
10
+ # be copied as-is from the content directory to the output directory.
11
+ #
12
+ class Static < Resource
13
+
14
+ # call-seq:
15
+ # render => string
16
+ #
17
+ # Returns the contents of the file.
18
+ #
19
+ def render
20
+ ::File.read(path)
21
+ end
22
+
23
+ # call-seq:
24
+ # dirty? => true or false
25
+ #
26
+ # Returns +true+ if this static file is newer than its corresponding output
27
+ # product. The static file needs to be copied to the output directory.
28
+ #
29
+ def dirty?
30
+ return true unless test(?e, destination)
31
+ @mtime > ::File.mtime(destination)
32
+ end
33
+
34
+ # call-seq:
35
+ # destination => string
36
+ #
37
+ # Returns the path in the output directory where the static file should
38
+ # be copied. This path is used to determine if the static file is dirty
39
+ # and in need of copying to the output file.
40
+ #
41
+ def destination
42
+ return @dest if defined? @dest and @dest
43
+
44
+ @dest = ::File.join(::Webby.site.output_dir, dir, filename)
45
+ @dest << '.' << @ext if @ext and !@ext.empty?
46
+ @dest
47
+ end
48
+
49
+ alias :extension :ext
50
+
51
+ end # class Layout
52
+ end # module Webby::Resources
53
+
54
+ # EOF
@@ -0,0 +1,137 @@
1
+ # $Id: mktemp.rb 176 2008-02-29 00:00:53Z tim_pease $
2
+
3
+ # :stopdoc:
4
+ # Skeleton module for the 'mktemp' routine.
5
+ #
6
+ # Ideally, one would do this in their code to import the "mktemp" call
7
+ # directly into their current namespace:
8
+ #
9
+ # require 'mktemp'
10
+ # include MkTemp
11
+ # # do something with mktemp()
12
+ #
13
+ #
14
+ # It is recommended that you look at the documentation for the mktemp()
15
+ # call directly for specific usage.
16
+ #
17
+ #--
18
+ #
19
+ # The compilation of software known as mktemp.rb is distributed under the
20
+ # following terms:
21
+ # Copyright (C) 2005-2006 Erik Hollensbe. All rights reserved.
22
+ #
23
+ # Redistribution and use in source form, with or without
24
+ # modification, are permitted provided that the following conditions
25
+ # are met:
26
+ # 1. Redistributions of source code must retain the above copyright
27
+ # notice, this list of conditions and the following disclaimer.
28
+ #
29
+ # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
30
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32
+ # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
33
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35
+ # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36
+ # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37
+ # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38
+ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39
+ # SUCH DAMAGE.
40
+ #
41
+ #++
42
+
43
+ module Webby
44
+ module MkTemp
45
+ VALID_TMPNAM_CHARS = (?a..?z).to_a + (?A..?Z).to_a
46
+
47
+ #
48
+ # This routine just generates a temporary file similar to the
49
+ # routines from 'mktemp'. A trailing series of 'X' characters will
50
+ # be transformed into a randomly-generated set of alphanumeric
51
+ # characters.
52
+ #
53
+ # This routine performs no file testing, at all. It is not suitable
54
+ # for anything beyond that.
55
+ #
56
+
57
+ def tmpnam(filename)
58
+ m = filename.match(/(X*)$/)
59
+
60
+ retnam = filename.dup
61
+
62
+ if m[1]
63
+ mask = ""
64
+ m[1].length.times { mask += VALID_TMPNAM_CHARS[rand(52)].chr }
65
+ retnam.sub!(/(X*)$/, mask)
66
+ end
67
+
68
+ return retnam
69
+ end
70
+
71
+ module_function :tmpnam
72
+
73
+ #
74
+ # This routine works similarly to mkstemp(3) in that it gets a new
75
+ # file, and returns a file handle for that file. The mask parameter
76
+ # determines whether or not to process the filename as a mask by
77
+ # calling the tmpnam() routine in this module. This routine will
78
+ # continue until it finds a valid filename, which may not do what
79
+ # you expect.
80
+ #
81
+ # While all attempts have been made to keep this as secure as
82
+ # possible, due to a few problems with Ruby's file handling code, we
83
+ # are required to allow a few concessions. If a 0-length file is
84
+ # created before we attempt to create ours, we have no choice but to
85
+ # accept it. Do not rely on this code for any expected level of
86
+ # security, even though we have taken all the measures we can to
87
+ # handle that situation.
88
+ #
89
+
90
+ def mktemp(filename, mask=true)
91
+ fh = nil
92
+
93
+ begin
94
+ loop do
95
+ fn = mask ? tmpnam(filename) : filename
96
+
97
+ if File.exist? fn
98
+ fail "Unable to create a temporary filename" unless mask
99
+ next
100
+ end
101
+
102
+ fh = File.new(fn, "a", 0600)
103
+ fh.seek(0, IO::SEEK_END)
104
+ break if fh.pos == 0
105
+
106
+ fail "Unable to create a temporary filename" unless mask
107
+ fh.close
108
+ end
109
+ rescue Exception => e
110
+ # in the case that we hit a locked file...
111
+ fh.close if fh
112
+ raise e unless mask
113
+ end
114
+
115
+ return fh
116
+ end
117
+
118
+ module_function :mktemp
119
+
120
+ #
121
+ # Create a directory. If mask is true (default), it will use the
122
+ # random name generation rules from the tmpnam() call in this
123
+ # module.
124
+ #
125
+
126
+ def mktempdir(filename, mask=true)
127
+ fn = mask ? tmpnam(filename) : filename
128
+ Dir.mkdir(fn)
129
+ return fn
130
+ end
131
+
132
+ module_function :mktempdir
133
+ end # module MkTemp
134
+ end # module Webby
135
+
136
+ # :startdoc:
137
+ # EOF
@@ -1,9 +1,11 @@
1
- # $Id: spawner.rb 49 2007-11-29 00:57:15Z tim_pease $
1
+ # $Id: spawner.rb 157 2008-02-20 17:41:00Z tim_pease $
2
2
 
3
3
  require 'rbconfig'
4
4
  require 'thread'
5
5
  require 'tempfile'
6
6
 
7
+ # :stopdoc:
8
+
7
9
  # == Synopsis
8
10
  #
9
11
  # A class for spawning child processes and ensuring those children continue
@@ -334,4 +336,6 @@ class Spawner
334
336
  end
335
337
  end # class Spawner
336
338
 
339
+ # :startdoc:
340
+
337
341
  # EOF
data/lib/webby/utils.rb CHANGED
@@ -1,5 +1,6 @@
1
- # $Id: utils.rb 121 2008-01-29 04:55:28Z tim_pease $
1
+ # $Id: utils.rb 157 2008-02-20 17:41:00Z tim_pease $
2
2
 
3
+ # :stopdoc:
3
4
  module Enumerable
4
5
  def injecting( initial )
5
6
  inject(initial) do |memo, obj|
@@ -48,5 +49,6 @@ class Time
48
49
  self.to_yaml.slice(4..-1).strip
49
50
  end
50
51
  end
52
+ # :startdoc:
51
53
 
52
54
  # EOF