webby 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- # $Id: outline.rb 181 2008-02-29 05:09:49Z tim_pease $
1
+ # $Id: outline.rb 192 2008-03-08 16:27:29Z tim_pease $
2
2
 
3
3
  require 'hpricot'
4
4
 
@@ -27,10 +27,6 @@ module Filters
27
27
  class Outline
28
28
  include ERB::Util
29
29
 
30
- # :stopdoc:
31
- class Error < StandardError; end
32
- # :startdoc:
33
-
34
30
  # call-seq:
35
31
  # Outline.new( html )
36
32
  #
@@ -159,7 +155,7 @@ class Outline
159
155
  end
160
156
 
161
157
  if level < @base_level
162
- raise Error, "heading tags are not in order, cannot outline"
158
+ raise ::Webby::Error, "heading tags are not in order, cannot outline"
163
159
  end
164
160
 
165
161
  if level == @cur_level
@@ -1,4 +1,4 @@
1
- # $Id: tidy.rb 181 2008-02-29 05:09:49Z tim_pease $
1
+ # $Id: tidy.rb 192 2008-03-08 16:27:29Z tim_pease $
2
2
 
3
3
  require 'fileutils'
4
4
  require 'tempfile'
@@ -20,10 +20,6 @@ module Filters
20
20
  #
21
21
  class Tidy
22
22
 
23
- # :stopdoc:
24
- class Error < StandardError; end
25
- # :startdoc:
26
-
27
23
  # call-seq:
28
24
  # Tidy.new( html )
29
25
  #
@@ -1,4 +1,4 @@
1
- # $Id: coderay_helper.rb 155 2008-02-17 00:48:30Z tim_pease $
1
+ # $Id: coderay_helper.rb 193 2008-03-09 02:32:37Z tim_pease $
2
2
 
3
3
  if try_require 'coderay'
4
4
  require 'enumerator'
@@ -43,16 +43,18 @@ module CodeRayHelper
43
43
  return
44
44
  end
45
45
 
46
- lang = opts.getopt(:lang, :ruby).to_sym
46
+ defaults = ::Webby.site.coderay
47
+ lang = opts.getopt(:lang, defaults[:lang]).to_sym
47
48
 
48
49
  cr_opts = {}
49
50
  %w(line_numbers to_sym
50
51
  line_number_start to_i
51
52
  bold_every to_i
52
53
  tab_width to_i).each_slice(2) do |key,convert|
53
- val = opts.getopt(key)
54
+ key = key.to_sym
55
+ val = opts.getopt(key, defaults[key])
54
56
  next if val.nil?
55
- cr_opts[key.to_sym] = val.send(convert)
57
+ cr_opts[key] = val.send(convert)
56
58
  end
57
59
 
58
60
  #cr.swap(CodeRay.scan(text, lang).html(opts).div)
@@ -1,4 +1,4 @@
1
- # $Id: graphviz_helper.rb 181 2008-02-29 05:09:49Z tim_pease $
1
+ # $Id: graphviz_helper.rb 193 2008-03-09 02:32:37Z tim_pease $
2
2
 
3
3
  require 'fileutils'
4
4
  require 'tempfile'
@@ -6,10 +6,6 @@ require 'tempfile'
6
6
  module Webby::Helpers
7
7
  module GraphvizHelper
8
8
 
9
- # :stopdoc:
10
- class Error < StandardError; end
11
- # :startdoc:
12
-
13
9
  # call-seq:
14
10
  # GraphvizHelper.error_check( file )
15
11
  #
@@ -20,7 +16,7 @@ module GraphvizHelper
20
16
  def self.error_check( file )
21
17
  if ::File.size(file.path) != 0
22
18
  msg = "\n" << ::File.read(file.path).strip
23
- raise Error, msg
19
+ raise ::Webby::Error, msg
24
20
  end
25
21
  end
26
22
 
@@ -77,21 +73,16 @@ module GraphvizHelper
77
73
  pos = buffer.length
78
74
  block.call(*args)
79
75
 
80
- path = opts.getopt(:path)
81
- cmd = opts.getopt(:cmd, 'dot')
82
- type = opts.getopt(:type, 'png')
76
+ defaults = ::Webby.site.graphviz
77
+ path = opts.getopt(:path, defaults[:path])
78
+ cmd = opts.getopt(:cmd, defaults[:cmd])
79
+ type = opts.getopt(:type, defaults[:type])
83
80
  text = buffer[pos..-1].strip
84
81
  if text.empty?
85
82
  buffer[pos..-1] = ''
86
83
  return
87
84
  end
88
85
 
89
- # ensure the requested graphviz command actually exists
90
- %x[#{cmd} -V 2>&1]
91
- unless 0 == $?.exitstatus
92
- raise NameError, "'#{cmd}' not found on the path"
93
- end
94
-
95
86
  # pull the name of the graph|digraph out of the DOT script
96
87
  name = text.match(%r/\A\s*(?:strict\s+)?(?:di)?graph\s+([A-Za-z_][A-Za-z0-9_]*)\s+\{/o)[1]
97
88
 
@@ -1,16 +1,11 @@
1
- # $Id: tex_img_helper.rb 181 2008-02-29 05:09:49Z tim_pease $
1
+ # $Id: tex_img_helper.rb 193 2008-03-09 02:32:37Z tim_pease $
2
2
 
3
3
  require Webby.libpath(*%w[webby stelan mktemp])
4
4
  require 'fileutils'
5
- require 'tempfile'
6
5
 
7
6
  module Webby::Helpers
8
7
  module TexImgHelper
9
8
 
10
- # :stopdoc:
11
- class Error < StandardError; end
12
- # :startdoc:
13
-
14
9
  # The +tex2img+ method converts a a section of mathematical TeX script
15
10
  # into an image and embeds the resulting image into the page. The TeX
16
11
  # engine must be installed on your system along with the ImageMagick
@@ -36,8 +31,6 @@ module TexImgHelper
36
31
  # TeX color spec, or #aabbcc) [default is black]
37
32
  # :resolution : the desired resolution in dpi (HxV)
38
33
  # [default is 150x150]
39
- # :antialias : if false, disables anti-aliasing in the resulting image
40
- # [default is true]
41
34
  #
42
35
  # the following options are passed as-is to the generated <img /> tag
43
36
  # :style : CSS styles to apply to the <img />
@@ -60,21 +53,16 @@ module TexImgHelper
60
53
  return
61
54
  end
62
55
 
63
- # create a temporary file for holding any error messages
64
- # from the graphviz program
65
- err = Tempfile.new('graphviz_err')
66
- err.close
67
-
68
- path = opts.getopt(:path)
69
- type = opts.getopt(:type, 'png')
70
- bg = opts.getopt(:bg, 'white')
71
- fg = opts.getopt(:fg, 'black')
72
- res = opts.getopt(:resolution, '150x150')
73
- aa = opts.getopt(:antialias, true)
56
+ defaults = ::Webby.site.tex2img
57
+ path = opts.getopt(:path, defaults[:path])
58
+ type = opts.getopt(:type, defaults[:type])
59
+ bg = opts.getopt(:bg, defaults[:bg])
60
+ fg = opts.getopt(:fg, defaults[:fg])
61
+ res = opts.getopt(:resolution, defaults[:resolution])
74
62
 
75
- # fix the color escaping
76
- fg = TexImgHelper.tex_color(fg)
77
- bg = TexImgHelper.tex_color(bg)
63
+ # fix color escaping
64
+ fg = fg =~ %r/^[a-zA-Z]+$/ ? fg : "\"#{fg}\""
65
+ bg = bg =~ %r/^[a-zA-Z]+$/ ? bg : "\"#{bg}\""
78
66
 
79
67
  # generate the image filename based on the path, graph name, and type
80
68
  # of image to generate
@@ -88,15 +76,21 @@ module TexImgHelper
88
76
  FileUtils.mkpath(::File.join(out_dir, path)) unless path.nil?
89
77
 
90
78
  tex = <<-TEX
91
- \\documentclass[12pt]{article}
92
- \\usepackage[usenames,dvipsnames]{color}
93
- \\usepackage[dvips]{graphicx}
79
+ \\nonstopmode
80
+ \\documentclass{article}
81
+ \\usepackage[T1]{fontenc}
82
+ \\usepackage{amsmath,amsfonts,amssymb,wasysym,latexsym,marvosym,txfonts}
83
+ \\usepackage[pdftex]{color}
94
84
  \\pagestyle{empty}
95
- \\pagecolor#{bg}
96
85
  \\begin{document}
97
- {\\color#{fg}
86
+ \\fontsize{12}{24}
87
+ \\selectfont
88
+ \\color{white}
89
+ \\pagecolor{black}
90
+ \\[
98
91
  #{text}
99
- }\\end{document}
92
+ \\]
93
+ \\end{document}
100
94
  TEX
101
95
  tex.gsub!(%r/\n\s+/, "\n").strip!
102
96
 
@@ -109,9 +103,14 @@ module TexImgHelper
109
103
  File.open('out.tex', 'w') {|fd| fd.puts tex}
110
104
  dev_null = test(?e, "/dev/null") ? "/dev/null" : "NUL:"
111
105
 
112
- %x[latex -interaction=batchmode out.tex &> #{dev_null}]
113
- %x[dvips -o out.eps -E out.dvi &> #{dev_null}]
114
- %x[convert +adjoin #{aa ? '-antialias' : '+antialias'} -density #{res} out.eps #{out_file} &> #{dev_null}]
106
+ %x[pdflatex -interaction=batchmode out.tex &> #{dev_null}]
107
+
108
+ convert = "\\( -density #{res} out.pdf -trim +repage \\) "
109
+ convert << "\\( +clone -fuzz 100% -fill #{fg} -opaque black \\) "
110
+ convert << "+swap -compose copy-opacity -composite "
111
+ convert << "\\( +clone -fuzz 100% -fill #{bg} -opaque white +matte \\) "
112
+ convert << "+swap -compose over -composite #{out_file}"
113
+ %x[convert #{convert} &> #{dev_null}]
115
114
  ensure
116
115
  Dir.chdir(pwd)
117
116
  FileUtils.rm_rf(tmpdir) if test(?e, tmpdir)
@@ -133,42 +132,10 @@ module TexImgHelper
133
132
 
134
133
  buffer[pos..-1] = out
135
134
  return
136
- ensure
137
- end
138
-
139
- # call-seq:
140
- # TexImgHelper.tex_color( string ) => string
141
- #
142
- # Taken the given color _string_ and convert it to a TeX color spec. The
143
- # input string can be either a RGB Hex value, a TeX color spec, or a color
144
- # name.
145
- #
146
- # tex_color( '#666666' ) #=> [rgb]{0.4,0.4,0.4}
147
- # tex_color( 'Tan' ) #=> {Tan}
148
- # tex_color( '[rgb]{1,0,0}' ) #=> [rgb]{1,0,0}
149
- #
150
- # This is an example of an invalid Hex RGB color -- they must contain six
151
- # hexidecimal characters to be valid.
152
- #
153
- # tex_color( '#333' ) #=> {#333}
154
- #
155
- def self.tex_color( color )
156
- case color
157
- when %r/^#([A-Fa-f0-9]{6})/o
158
- hex = $1
159
- rgb = []
160
- hex.scan(%r/../) {|n| rgb << Float(n.to_i(16))/255.0}
161
- "[rgb]{#{rgb.join(',')}}"
162
- when %r/^[\{\[]/o
163
- "{#{color}}"
164
- else
165
- color
166
- end
167
135
  end
168
-
169
136
  end # module TexImgHelper
170
137
 
171
- %x[latex --version 2>&1]
138
+ %x[pdflatex --version 2>&1]
172
139
  if 0 == $?.exitstatus
173
140
  %x[convert --version 2>&1]
174
141
  if 0 == $?.exitstatus
@@ -0,0 +1,74 @@
1
+ # $Id: ultraviolet_helper.rb 190 2008-03-05 05:35:00Z tim_pease $
2
+
3
+ # This code was provided by Guillaume Carbonneau -- http://radr.ca/
4
+ # Many thanks for his support of Webby!
5
+
6
+ if try_require 'uv'
7
+
8
+ module Webby::Helpers
9
+ module UltraVioletHelper
10
+
11
+ # The +uv+ method applies syntax highlighting to source code embedded
12
+ # in a webpage. The UltraViolet highlighting engine is used for the HTML
13
+ # markup of the source code. The page sections to be highlighted are given
14
+ # as blocks of text to the +uv+ method.
15
+ #
16
+ # Options can be passed to the UltraViolet engine via attributes in the
17
+ # +uv+ method.
18
+ #
19
+ # <% uv( :lang => "ruby", :line_numbers => true ) do -%>
20
+ # # Initializer for the class.
21
+ # def initialize( string )
22
+ # @str = stirng
23
+ # end
24
+ # <% end -%>
25
+ #
26
+ # The supported UltraViolet options are the following:
27
+ #
28
+ # :lang : the language to highlight (ruby, c, html, ...)
29
+ # [defaults to 'ruby']
30
+ # :line_numbers : true or false [defaults to false]
31
+ # :theme : see list of available themes in ultraviolet
32
+ # [defaults to 'mac_classic']
33
+ #
34
+ # The defaults can be overridden for an entire site by changing the SITE.uv
35
+ # options hash in the Rakefile.
36
+ #
37
+ def uv( *args, &block )
38
+ opts = args.last.instance_of?(Hash) ? args.pop : {}
39
+
40
+ buffer = eval('_erbout', block.binding)
41
+ pos = buffer.length
42
+ block.call(*args)
43
+
44
+ text = buffer[pos..-1].strip
45
+ if text.empty?
46
+ buffer[pos..-1] = ''
47
+ return
48
+ end
49
+
50
+ defaults = ::Webby.site.uv
51
+ lang = opts.getopt(:lang, defaults[:lang])
52
+ line_numbers = opts.getopt(:line_numbers, defaults[:line_numbers])
53
+ theme = opts.getopt(:theme, defaults[:theme])
54
+
55
+ out = '<div class="UltraViolet">'
56
+ out << Uv.parse(text, "xhtml", lang, line_numbers, theme)
57
+ out << '</div>'
58
+
59
+ if @_cursor.remaining_filters.include? 'textile'
60
+ out.insert 0, "<notextile>\n"
61
+ out << "\n</notextile>"
62
+ end
63
+
64
+ buffer[pos..-1] = out
65
+ return
66
+ end
67
+ end # module UltraVioletHelper
68
+
69
+ register(UltraVioletHelper)
70
+
71
+ end # module Webby::Helpers
72
+ end # try_require
73
+
74
+ # EOF
@@ -1,4 +1,4 @@
1
- # $Id: url_helper.rb 175 2008-02-28 15:49:11Z tim_pease $
1
+ # $Id: url_helper.rb 192 2008-03-08 16:27:29Z tim_pease $
2
2
 
3
3
  module Webby::Helpers
4
4
 
@@ -92,12 +92,14 @@ module UrlHelper
92
92
  #
93
93
  def link_to( name, *args )
94
94
  opts = Hash === args.last ? args.pop : {}
95
- url = args.first
95
+ obj = args.first
96
96
  attrs = opts.delete(:attrs)
97
97
 
98
- url = case url
98
+ url = case obj
99
99
  when String, Webby::Resources::Resource
100
- self.url_for(url, opts)
100
+ self.url_for(obj, opts)
101
+ when ::Webby::Paginator::Page
102
+ self.url_for(obj.url, opts)
101
103
  when :back
102
104
  'javascript:history.back()'
103
105
  else
@@ -213,7 +215,8 @@ module UrlHelper
213
215
  if Webby::Resources::Resource === name
214
216
  p, name = name, nil
215
217
  elsif opts.empty? && name
216
- p = @pages.find(Webby.site.find_by.to_sym => name)
218
+ opts[Webby.site.find_by.to_sym] = name
219
+ p = @pages.find(opts)
217
220
  else
218
221
  p = @pages.find(opts)
219
222
  end
@@ -0,0 +1,154 @@
1
+ # $Id: link_validator.rb 189 2008-03-02 22:22:24Z tim_pease $
2
+
3
+ require 'hpricot'
4
+ require 'open-uri'
5
+
6
+ module Webby
7
+
8
+ # The Webby LinkValidator class is used to validate the hyperlinks of all
9
+ # the HTML files in the output directory. By default, only links to other
10
+ # pages in the output directory are checked. However, setting the
11
+ # :external flag to +true+ will cause hyperlinks to external web sites to
12
+ # be validated as well.
13
+ #
14
+ class LinkValidator
15
+
16
+ # A lazy man's method that will instantiate a new link validator and run
17
+ # the validations.
18
+ #
19
+ def self.validate( opts = {} )
20
+ new(opts).validate
21
+ end
22
+
23
+ attr_accessor :validate_externals
24
+
25
+ # call-seq:
26
+ # LinkValidator.new( opts = {} )
27
+ #
28
+ # Creates a new LinkValidator object. The only supported option is the
29
+ # :external flag. When set to +true+, the link validator will also check
30
+ # out links to external websites. This is done by opening a connection to
31
+ # the remote site and pulling down the page specified in the hyperlink.
32
+ # Use with caution.
33
+ #
34
+ def initialize( opts = {} )
35
+ @log = Logging::Logger[self]
36
+
37
+ glob = ::File.join(::Webby.site.output_dir, '**', '*.html')
38
+ @files = Dir.glob(glob).sort
39
+ @attr_rgxp = %r/\[@(\w+)\]$/o
40
+
41
+ @validate_externals = opts.getopt(:external, false)
42
+ @valid_uris = ::Webby.site.valid_uris.flatten
43
+ @invalid_uris = []
44
+ end
45
+
46
+ # Iterate over all the HTML files in the output directory and validate the
47
+ # hyperlinks.
48
+ #
49
+ def validate
50
+ @files.each {|fn| check_file fn}
51
+ end
52
+
53
+ # Check the given file (identified by its filename {fn for short here}) by
54
+ # iterating through all the configured xpaths and validating that those
55
+ # hyperlinks ae valid.
56
+ #
57
+ def check_file( fn )
58
+ @log.info "validating #{fn}"
59
+
60
+ dir = ::File.dirname(fn)
61
+ @doc = Hpricot(::File.read(fn))
62
+
63
+ ::Webby.site.xpaths.each do |xpath|
64
+ @attr_name = nil
65
+
66
+ @doc.search(xpath).each do |element|
67
+ @attr_name ||= @attr_rgxp.match(xpath)[1]
68
+ uri = URI.parse(element.get_attribute(@attr_name))
69
+ validate_uri(uri, dir)
70
+ end
71
+ end
72
+ @doc = @attr_name = nil
73
+ end
74
+
75
+ # Validate the the page the _uri_ refers to actually exists. The directory
76
+ # of the current page being processed is needed in order to resolve
77
+ # relative paths.
78
+ #
79
+ # If the _uri_ is a relative path, then the output directory is searched
80
+ # for the appropriate page. If the _uri_ is an absolute path, then the
81
+ # remote server is contacted and the page requested from the server. This
82
+ # will only take place if the LinkValidator was created with the :external
83
+ # flag set to true.
84
+ #
85
+ def validate_uri( uri, dir )
86
+ # for relative URIs, we can see if the file exists in the output folder
87
+ if uri.relative?
88
+ return validate_anchor(uri, @doc) if uri.path.empty?
89
+
90
+ path = if uri.path =~ %r/^\//
91
+ ::File.join(::Webby.site.output_dir, uri.path)
92
+ else
93
+ ::File.join(dir, uri.path)
94
+ end
95
+ path = ::File.join(path, 'index.html') if ::File.extname(path).empty?
96
+
97
+ uri_str = path.dup
98
+ (uri_str << '#' << uri.fragment) if uri.fragment
99
+ return if @valid_uris.include? uri_str
100
+
101
+ if test ?f, path
102
+ valid = if uri.fragment
103
+ validate_anchor(uri, Hpricot(::File.read(path)))
104
+ else true end
105
+ @valid_uris << uri_str if valid
106
+ else
107
+ @log.error "invalid URI '#{uri.to_s}'"
108
+ end
109
+
110
+ # if the URI responds to the open mehod, then try to access the URI
111
+ elsif uri.respond_to? :open
112
+ return unless @validate_externals
113
+ return if @valid_uris.include? uri.to_s
114
+
115
+ if @invalid_uris.include? uri.to_s
116
+ @log.error "could not open URI '#{uri.to_s}'"
117
+ return
118
+ end
119
+
120
+ begin
121
+ uri.open {|_| nil}
122
+ @valid_uris << uri.to_s
123
+ rescue Exception
124
+ @log.error "could not open URI '#{uri.to_s}'"
125
+ @invalid_uris << uri.to_s
126
+ end
127
+
128
+ # otherwise, post a warning that the URI could not be validated
129
+ else
130
+ return if @valid_uris.include? uri.to_s
131
+ @log.warn "could not validate URI '#{uri.to_s}'"
132
+ end
133
+ end
134
+
135
+ # Validate that the anchor fragment of the URI exists in the given
136
+ # document. The document is an Hpricot document object.
137
+ #
138
+ # Returns +true+ if the anchor exists in the document and +false+ if it
139
+ # does not.
140
+ #
141
+ def validate_anchor( uri, doc )
142
+ return false if uri.fragment.nil?
143
+
144
+ anchor = '#' + uri.fragment
145
+ if doc.at(anchor).nil?
146
+ @log.error "invalid URI '#{uri.to_s}'"
147
+ false
148
+ else true end
149
+ end
150
+
151
+ end # class LinkValidator
152
+ end # module Webby
153
+
154
+ # EOF
@@ -1,4 +1,4 @@
1
- # $Id: renderer.rb 173 2008-02-27 02:58:43Z tim_pease $
1
+ # $Id: renderer.rb 192 2008-03-08 16:27:29Z tim_pease $
2
2
 
3
3
  # Equivalent to a header guard in C/C++
4
4
  # Used to prevent the spec helper from being loaded more than once
@@ -24,7 +24,6 @@ class Renderer
24
24
  include ERB::Util
25
25
 
26
26
  # :stopdoc:
27
- class Error < StandardError; end
28
27
  @@stack = []
29
28
  # :startdoc:
30
29
 
@@ -40,7 +39,7 @@ class Renderer
40
39
 
41
40
  loop {
42
41
  ::File.open(page.destination, 'w') do |fd|
43
- fd.write renderer.layout_page
42
+ fd.write(renderer.__send__(:_layout_page))
44
43
  end
45
44
  break unless renderer.__send__(:_next_page)
46
45
  }
@@ -68,40 +67,6 @@ class Renderer
68
67
  @log = Logging::Logger[self]
69
68
  end
70
69
 
71
- # call-seq:
72
- # layout_page => string
73
- #
74
- # Apply the desired filters to the page and then render the filtered page
75
- # into the desired layout. The filters to apply to the page are determined
76
- # from the page's meta-data. The layout to use is also determined from the
77
- # page's meta-data.
78
- #
79
- def layout_page
80
- layouts = Resources.layouts
81
- obj = @page
82
- str = @page.render(self)
83
-
84
- @@stack << @page.path
85
- loop do
86
- lyt = layouts.find :filename => obj.layout
87
- break if lyt.nil?
88
-
89
- @content, str = str, ::Webby::Resources::File.read(lyt.path)
90
- str = _track_rendering(lyt.path) {
91
- Filters.process(self, lyt, str)
92
- }
93
- @content, obj = nil, lyt
94
- end
95
-
96
- @@stack.pop if @page.path == @@stack.last
97
- raise Error, "rendering stack corrupted" unless @@stack.empty?
98
-
99
- str
100
- rescue => err
101
- @log.error "while rendering page '#{@page.path}'"
102
- @log.error err
103
- end
104
-
105
70
  # call-seq:
106
71
  # render_page => string
107
72
  #
@@ -136,11 +101,11 @@ class Renderer
136
101
  p = Resources.partials.find(
137
102
  :filename => fn, :in_directory => @page.dir ) rescue nil
138
103
  p ||= Resources.partials.find(:filename => fn)
139
- raise Error, "could not find partial '#{part}'" if p.nil?
104
+ raise ::Webby::Error, "could not find partial '#{part}'" if p.nil?
140
105
  p
141
106
  when ::Webby::Resources::Partial
142
107
  part
143
- else raise Error, "expecting a partial or a partial name" end
108
+ else raise ::Webby::Error, "expecting a partial or a partial name" end
144
109
 
145
110
  _track_rendering(part.path) {
146
111
  Filters.process(self, part, ::Webby::Resources::File.read(part.path))
@@ -181,6 +146,52 @@ class Renderer
181
146
 
182
147
  private
183
148
 
149
+ # call-seq:
150
+ # _layout_page => string
151
+ #
152
+ # Apply the desired filters to the page and then render the filtered page
153
+ # into the desired layout. The filters to apply to the page are determined
154
+ # from the page's meta-data. The layout to use is also determined from the
155
+ # page's meta-data.
156
+ #
157
+ def _layout_page
158
+ @content = @page.render(self)
159
+
160
+ _track_rendering(@page.path) {
161
+ _render_layout_for(@page)
162
+ }
163
+ raise ::Webby::Error, "rendering stack corrupted" unless @@stack.empty?
164
+
165
+ @content
166
+ rescue ::Webby::Error => err
167
+ @log.error "while rendering page '#{@page.path}'"
168
+ @log.error err.message
169
+ rescue => err
170
+ @log.error "while rendering page '#{@page.path}'"
171
+ @log.fatal err
172
+ exit 1
173
+ ensure
174
+ @content = nil
175
+ @@stack.clear
176
+ end
177
+
178
+ # call-seq:
179
+ # _render_layout_for( resource )
180
+ #
181
+ # Render the layout for the given resource. If the resource does not have
182
+ # a layout, then this method returns immediately.
183
+ #
184
+ def _render_layout_for( res )
185
+ lyt = Resources.layouts.find :filename => res.layout
186
+ return if lyt.nil?
187
+
188
+ _track_rendering(lyt.path) {
189
+ @content = Filters.process(
190
+ self, lyt, ::Webby::Resources::File.read(lyt.path))
191
+ _render_layout_for(lyt)
192
+ }
193
+ end
194
+
184
195
  # call-seq:
185
196
  # _next_page => true or false
186
197
  #
@@ -222,7 +233,7 @@ class Renderer
222
233
  msg = "rendering loop detected for '#{path}'\n"
223
234
  msg << " current rendering stack\n\t"
224
235
  msg << @@stack.join("\n\t")
225
- raise Error, msg
236
+ raise ::Webby::Error, msg
226
237
  end
227
238
 
228
239
  yield
@@ -1,4 +1,4 @@
1
- # $Id: page.rb 167 2008-02-24 00:59:54Z tim_pease $
1
+ # $Id: page.rb 191 2008-03-05 19:07:50Z tim_pease $
2
2
 
3
3
  require Webby.libpath(*%w[webby resources resource])
4
4
 
@@ -53,7 +53,7 @@ class Page < Resource
53
53
  #
54
54
  def number=( num )
55
55
  @number = num
56
- @dest = nil
56
+ @url = @dest = nil
57
57
  end
58
58
 
59
59
  # call-seq: