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,18 +1,18 @@
1
- # $Id: pages_db.rb 137 2008-02-08 05:05:55Z tim_pease $
1
+ # $Id: db.rb 169 2008-02-24 03:59:37Z tim_pease $
2
2
 
3
- module Webby
3
+ module Webby::Resources
4
4
 
5
5
  # A rudimentary "database" for holding resource objects and finding them.
6
6
  # The database is held in a Ruby hash keyed by the directories in the
7
7
  # content folder.
8
8
  #
9
- class PagesDB
9
+ class DB
10
10
 
11
11
  # call-seq:
12
- # PagesDB.new
12
+ # DB.new
13
13
  #
14
- # Create a new pages database object. This is used to store resources and
15
- # to find them by their attributes.
14
+ # Create a new resources database object. This is used to store resources
15
+ # and to find them by their attributes.
16
16
  #
17
17
  def initialize
18
18
  @db = Hash.new {|h,k| h[k] = []}
@@ -63,40 +63,43 @@ class PagesDB
63
63
  # find( opts = {} ) => resource or nil
64
64
  # find( opts = {} ) {|resource| block} => resource or nil
65
65
  #
66
- # Find a specific resource in the database. A resource can be found using
67
- # any combination of attributes by passing them in as options to the
68
- # +find+ method. This will used simple equality comparison to find the
69
- # resource.
66
+ # Find a specific resource or collection of resources in the pages database.
67
+ # Resources can be found using any combination of attributes by passing them
68
+ # in as options to the +find+ method. This will used simple equality
69
+ # comparison to find the resource or resources.
70
70
  #
71
- # For more complex finders, a block should be supplied. The usage
72
- # follows that of of the Enumerable#find method. The method will return
73
- # the first resource for which the block returns true.
74
- #
75
- # If the :all option is given as true, then all resources that match the
76
- # finder criteria will be returned in an array. If none are found, an
77
- # empty array will be returned.
78
- #
79
- # Options include:
80
- #
81
- # :in_directory => 'directory'
71
+ # If the :include option is given as :all then all resources that match
72
+ # the finder criteria will be returned in an array. If none are found, an
73
+ # empty array will be returned. If the :include option is given as an
74
+ # integer then the first n resources found will be returned. Otherwise, or
75
+ # if the :include option is not given, the first resource found will be
76
+ # returned
77
+ #
78
+ # For more complex finders, a block should be supplied. The usage follows
79
+ # that of of the Enumerable#find or Enumerable#find_all methods, depending
80
+ # on the limit. The method will return the first resource or all
81
+ # resources, respectively, for which the block returns true.
82
+ #
83
+ # Options:
84
+ # :limit => :all, integer or nil
85
+ # :in_directory => directory
82
86
  # :recursive => true or false
83
- #
84
- # :limit => :all or integer
85
- # :sorty_by => 'attribute'
87
+ # :sort_by => attribute
88
+ # :reverse => true or false
86
89
  #
87
90
  # Examples:
88
91
  #
89
92
  # # find the "index" resource in the "foo/bar" directory
90
- # pages_db.find( :filename => 'index', :in_directory => 'foo/bar' )
93
+ # @pages.find( :filename => 'index', :in_directory => 'foo/bar' )
91
94
  #
92
- # # find any "index" resource under the "foo/bar" directory
93
- # pages_db.find( :filename => 'index', :in_directory => 'foo/bar', :recursive => true )
95
+ # # find all resources under the "foo/bar" directory recursively
96
+ # @pages.find( :limit => :all, :in_directory => 'foo/bar', :recursive => true )
94
97
  #
95
- # # find all resources named "widgets" whose color is "blue"
96
- # pages_db.find( :all, :name => 'widgets', :color => 'blue' )
98
+ # # find the resource named "widgets" whose color is "blue"
99
+ # @pages.find( :name => 'widgets', :color => 'blue' )
97
100
  #
98
101
  # # find all resources created in the past week
99
- # pages_db.find( :all ) do |resource|
102
+ # @pages.find( :limit => :all ) do |resource|
100
103
  # resource.created_at > Time.now - (7 * 24 * 3600)
101
104
  # end
102
105
  #
@@ -105,12 +108,13 @@ class PagesDB
105
108
 
106
109
  limit = opts.delete(:limit)
107
110
  sort_by = opts.delete(:sort_by)
111
+ reverse = opts.delete(:reverse)
108
112
 
109
113
  # figure out which directories to search through and whether to recurse
110
114
  # into directories or not
111
115
  search = if (dir = opts.delete(:in_directory))
112
116
  strategy = if opts.delete(:recursive)
113
- lambda { |key| key =~ /^#{Regexp.escape(dir)}(?:\/|$)/ }
117
+ lambda { |key| key =~ %r/^#{Regexp.escape(dir)}(?:\/|$)/ }
114
118
  else
115
119
  lambda { |key| key == dir }
116
120
  end
@@ -141,7 +145,9 @@ class PagesDB
141
145
  if sort_by
142
146
  m = sort_by.to_sym
143
147
  ary.delete_if {|p| p.__send__(m).nil?}
144
- ary.sort! {|a,b| a.__send__(m) <=> b.__send__(m)}
148
+ reverse ?
149
+ ary.sort! {|a,b| b.__send__(m) <=> a.__send__(m)} :
150
+ ary.sort! {|a,b| a.__send__(m) <=> b.__send__(m)}
145
151
  end
146
152
 
147
153
  # limit the search results
@@ -205,7 +211,31 @@ class PagesDB
205
211
  ary
206
212
  end
207
213
 
208
- end # class PagesDB
214
+ # call-seq:
215
+ # parent_of( resource ) => resource or nil
216
+ #
217
+ # Returns the parent page of the given resource or nil if the resource is
218
+ # at the root of the directory structure. The parent is the "index" page
219
+ # of the current directory or the next directory up the chain.
220
+ #
221
+ def parent_of( page )
222
+ dir = page.dir
223
+
224
+ loop do
225
+ if @db.has_key? dir
226
+ parent = @db[dir].find {|p| p.filename == 'index'}
227
+ return parent unless parent.nil? or parent == page
228
+ end
229
+
230
+ break if dir.empty?
231
+ dir = ::File.dirname(dir)
232
+ dir = '' if dir == '.'
233
+ end
234
+
235
+ return
236
+ end
237
+
238
+ end # class DB
209
239
  end # module Webby
210
240
 
211
241
  # EOF
@@ -1,13 +1,13 @@
1
- # $Id: file.rb 134 2008-02-05 16:12:48Z tim_pease $
1
+ # $Id: file.rb 167 2008-02-24 00:59:54Z tim_pease $
2
2
 
3
3
  require 'yaml'
4
4
 
5
- module Webby
5
+ module Webby::Resources
6
6
 
7
- # The Webby::File class is identical to the core Ruby file class except for
8
- # YAML meta-data stored at the top of the file. This meta-data is made
9
- # available through the <code>meta_data</code> and <code>meta_data=</code>
10
- # functions.
7
+ # The Webby::Resources::File class is identical to the core Ruby file class
8
+ # except for YAML meta-data stored at the top of the file. This meta-data
9
+ # is made available through the <code>meta_data</code> and
10
+ # <code>meta_data=</code> functions.
11
11
  #
12
12
  # The meta-data data must be found between two YAML block separators "---",
13
13
  # each on their own line.
@@ -30,7 +30,7 @@ class File < ::File
30
30
 
31
31
  class << self
32
32
  # call-seq:
33
- # Webby::File.read( name [, length [, offset]]) => string
33
+ # File.read( name [, length [, offset]]) => string
34
34
  #
35
35
  # Opens the file, optionally seeks to the given _offset_, then returns
36
36
  # _length_ bytes (defaulting to the rest of the file). +read+ ensures
@@ -38,13 +38,13 @@ class File < ::File
38
38
  #
39
39
  def read( name, *args )
40
40
  fd = new name, 'r'
41
- fd.read *args
41
+ fd.read(*args)
42
42
  ensure
43
43
  fd.close unless fd.nil?
44
44
  end
45
45
 
46
46
  # call-seq:
47
- # Webby::File.readlines( name, sep_string = $/ ) => array
47
+ # File.readlines( name, sep_string = $/ ) => array
48
48
  #
49
49
  # Reads the entire file specified by _name_ as individual lines, and
50
50
  # returns those lines in an array. Lines are separated by _sep_string_.
@@ -58,7 +58,7 @@ class File < ::File
58
58
  end
59
59
 
60
60
  # call-seq:
61
- # Webby::File.meta_data( name ) => object or nil
61
+ # File.meta_data( name ) => object or nil
62
62
  #
63
63
  # Reads the meta-data from the file specified by _name_. +meta_data+
64
64
  # ensures the files is closed before returning.
@@ -71,7 +71,7 @@ class File < ::File
71
71
  end
72
72
 
73
73
  # call-seq:
74
- # Webby::File.dirname( filename ) => dir_name
74
+ # File.dirname( filename ) => dir_name
75
75
  #
76
76
  # Returns all components of the _filename_ except the last one. The
77
77
  # filename must be formed using forward slashes ("/") regardless of the
@@ -82,7 +82,7 @@ class File < ::File
82
82
  end
83
83
 
84
84
  # call-seq:
85
- # Webby::File.basename( filename ) => base_name
85
+ # File.basename( filename ) => base_name
86
86
  #
87
87
  # Returns the last component of the _filename_, which must be formed
88
88
  # using forward slashes ("/"regardless of the separator used on the
@@ -93,7 +93,7 @@ class File < ::File
93
93
  end
94
94
 
95
95
  # call-seq:
96
- # Webby::File.extname( filename ) => ext_name
96
+ # File.extname( filename ) => ext_name
97
97
  #
98
98
  # Returns the extension (the portion of file name in path after the
99
99
  # period). This method excludes the period from the extension name.
@@ -104,16 +104,16 @@ class File < ::File
104
104
  end
105
105
 
106
106
  # call-seq:
107
- # Webby::File.new( filename, mode = "r" ) => file
108
- # Webby::File.new( filename [, mode [, perm]] ) => file
107
+ # File.new( filename, mode = "r" ) => file
108
+ # File.new( filename [, mode [, perm]] ) => file
109
109
  #
110
110
  # Opens the file named by _filename_ according to _mode_ (default is 'r')
111
- # and returns a new +Webby::File+ object. See the description of class
112
- # +IO+ for a description of _mode_. The file _mode_ may optionally be
113
- # specified as a +Fixnum+ by or-ing together the flags (+O_RDONLY+ etc,
114
- # again described under +IO+). Optional permission bits may be given in
115
- # _perm_. These _mode_ and permission bits are platform dependent; on Unix
116
- # systems, see +open(2)+ for details.
111
+ # and returns a new +Webby::Resources::File+ object. See the description
112
+ # of class +IO+ for a description of _mode_. The file _mode_ may
113
+ # optionally be specified as a +Fixnum+ by or-ing together the flags
114
+ # (+O_RDONLY+ etc, again described under +IO+). Optional permission bits
115
+ # may be given in _perm_. These _mode_ and permission bits are platform
116
+ # dependent; on Unix systems, see +open(2)+ for details.
117
117
  #
118
118
  # f = File.new("testfile", "r")
119
119
  # f = File.new("newfile", "w+")
@@ -172,6 +172,9 @@ class File < ::File
172
172
  seek 0, IO::SEEK_END
173
173
  end
174
174
 
175
+ alias :_gets :gets
176
+ private :_gets
177
+
175
178
  %w(getc gets read read_nonblock readbytes readchar readline readlines readpartial scanf).each do |m|
176
179
  self.class_eval <<-CODE
177
180
  def #{m}(*a)
@@ -201,10 +204,10 @@ class File < ::File
201
204
  cur = tell
202
205
 
203
206
  seek 0
204
- line = gets
207
+ line = _gets
205
208
  return unless META_SEP =~ line
206
209
 
207
- while line = gets
210
+ while line = _gets
208
211
  break if META_SEP =~ line
209
212
  end
210
213
  return if line.nil?
@@ -215,6 +218,6 @@ class File < ::File
215
218
  end
216
219
 
217
220
  end # class File
218
- end # module Webby
221
+ end # module Webby::Resources
219
222
 
220
223
  # EOF
@@ -0,0 +1,65 @@
1
+ # $Id: layout.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 Layout is any file that is found in the layout folder of the webiste
8
+ # directory. Layouts container the common elements of all the pages in a
9
+ # website, and pages from the content folder are rendered into the layout.
10
+ #
11
+ class Layout < Resource
12
+
13
+ # call-seq:
14
+ # Layout.new( path )
15
+ #
16
+ # Creates a new Layout object given the full path to the layout file.
17
+ #
18
+ def initialize( fn )
19
+ super
20
+
21
+ @mdata = ::Webby::Resources::File.meta_data(@path)
22
+ @mdata ||= {}
23
+ @mdata.sanitize!
24
+ end
25
+
26
+ # call-seq:
27
+ # destination => string
28
+ #
29
+ # The output file destination for the layout. This is the ".cairn" file in
30
+ # the output folder. It is used to determine if the layout is newer than
31
+ # the build products.
32
+ #
33
+ def destination
34
+ ::Webby.cairn
35
+ end
36
+
37
+ # call-seq:
38
+ # extension => string or nil
39
+ #
40
+ # Returns the extension to be applied to output files rendered by the
41
+ # layotut. This will either be a string or +nil+ if the layout does not
42
+ # specify an extension to use.
43
+ #
44
+ def extension
45
+ return @mdata['extension'] if @mdata.has_key? 'extension'
46
+
47
+ if @mdata.has_key? 'layout'
48
+ lyt = ::Webby::Resources.layouts.find :filename => @mdata['layout']
49
+ ext = lyt ? lyt.extension : nil
50
+ end
51
+ end
52
+
53
+ # call-seq:
54
+ # url => nil
55
+ #
56
+ # Layouts do not have a URL. This method will alwasy return +nil+.
57
+ #
58
+ def url
59
+ nil
60
+ end
61
+
62
+ end # class Layout
63
+ end # module Webby::Resources
64
+
65
+ # EOF
@@ -0,0 +1,109 @@
1
+ # $Id: page.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 Page is a file in the content folder that contains YAML meta-data at
8
+ # the top of the file. Pages are processed by the Webby rendering engine
9
+ # and then inserted into the desired layout. The string resulting from
10
+ # processing and layout is then written to the output directory.
11
+ #
12
+ class Page < Resource
13
+
14
+ # Resource page number (if needed)
15
+ attr_reader :number
16
+
17
+ # call-seq:
18
+ # Resource.new( path )
19
+ #
20
+ # Creates a new page object from the full path to the page file.
21
+ #
22
+ def initialize( fn )
23
+ super
24
+ @number = nil
25
+
26
+ @mdata = ::Webby::Resources::File.meta_data(@path)
27
+ @mdata ||= {}
28
+ @mdata = ::Webby.site.page_defaults.merge(@mdata)
29
+ @mdata.sanitize!
30
+ end
31
+
32
+ # call-seq:
33
+ # render => string
34
+ #
35
+ # Creates a new Webby::Renderer instance and uses that instance to render
36
+ # the page contents using the configured filter(s). The filter(s) to
37
+ # use is defined in the page's meta-data as the 'filter' key.
38
+ #
39
+ # Note, this only renders this page. The returned string does not include
40
+ # any layout rendering.
41
+ #
42
+ def render( renderer = nil )
43
+ renderer ||= ::Webby::Renderer.new(self)
44
+ renderer.render_page
45
+ end
46
+
47
+ # call-seq:
48
+ # page.number = Integer
49
+ #
50
+ # Sets the page number for the current resource to the given integer. This
51
+ # number is used to modify the output destination for resources that
52
+ # require pagination.
53
+ #
54
+ def number=( num )
55
+ @number = num
56
+ @dest = nil
57
+ end
58
+
59
+ # call-seq:
60
+ # destination => string
61
+ #
62
+ # Returns the path in the output directory where the rendered page should
63
+ # be stored. This path is used to determine if the page is dirty and in
64
+ # need of rendering.
65
+ #
66
+ # The destination for a page can be overridden by explicitly setting
67
+ # the 'destination' property in the page's meta-data.
68
+ #
69
+ def destination
70
+ return @dest if defined? @dest and @dest
71
+
72
+ @dest = if @mdata.has_key? 'destination' then @mdata['destination']
73
+ else ::File.join(dir, filename) end
74
+
75
+ @dest = ::File.join(::Webby.site.output_dir, @dest)
76
+ @dest << @number.to_s if @number
77
+
78
+ ext = extension
79
+ unless ext.nil? or ext.empty?
80
+ @dest << '.' << ext
81
+ end
82
+ @dest
83
+ end
84
+
85
+ # call-seq:
86
+ # extension => string
87
+ #
88
+ # Returns the extension that will be appended to the output destination
89
+ # filename. The extension is determined by looking at the following:
90
+ #
91
+ # * this page's meta-data for an 'extension' property
92
+ # * the meta-data of this page's layout for an 'extension' property
93
+ # * the extension of this page file
94
+ #
95
+ def extension
96
+ return @mdata['extension'] if @mdata.has_key? 'extension'
97
+
98
+ if @mdata.has_key? 'layout'
99
+ lyt = ::Webby::Resources.layouts.find :filename => @mdata['layout']
100
+ ext = lyt ? lyt.extension : nil
101
+ return ext if ext
102
+ end
103
+ @ext
104
+ end
105
+
106
+ end # class Page
107
+ end # module Webby::Resources
108
+
109
+ # EOF