webby 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,4 +1,4 @@
1
- # $Id: auto_builder.rb 60 2007-12-04 05:05:50Z tim_pease $
1
+ # $Id: auto_builder.rb 167 2008-02-24 00:59:54Z tim_pease $
2
2
 
3
3
  require 'directory_watcher'
4
4
 
@@ -11,6 +11,8 @@ module Webby
11
11
  #
12
12
  class AutoBuilder
13
13
 
14
+ # TODO: hit Ctrl-C once to rebuild everything, and hit it twice to stop the autobuild loop
15
+
14
16
  # call-seq:
15
17
  # AutoBuilder.run
16
18
  #
@@ -54,7 +56,7 @@ class AutoBuilder
54
56
  @log.debug "changed #{evt.path}"
55
57
  next unless test ?f, evt.path
56
58
  next if evt.path =~ ::Webby.exclude
57
- Resource.new evt.path
59
+ Resources.new evt.path
58
60
  end
59
61
 
60
62
  @builder.run :load_files => false
data/lib/webby/builder.rb CHANGED
@@ -1,4 +1,4 @@
1
- # $Id: builder.rb 92 2008-01-03 19:41:51Z tim_pease $
1
+ # $Id: builder.rb 167 2008-02-24 00:59:54Z tim_pease $
2
2
 
3
3
  require 'find'
4
4
  require 'fileutils'
@@ -90,7 +90,7 @@ class Builder
90
90
  load_files if opts[:load_files]
91
91
  loop_check
92
92
 
93
- Resource.pages.each do |page|
93
+ Resources.pages.each do |page|
94
94
  next unless page.dirty? or opts[:rebuild]
95
95
 
96
96
  @log.info "creating #{page.destination}"
@@ -99,8 +99,9 @@ class Builder
99
99
  FileUtils.mkdir_p ::File.dirname(page.destination)
100
100
 
101
101
  # copy the resource to the output directory if it is static
102
- if page.is_static?
102
+ if page.instance_of? Resources::Static
103
103
  FileUtils.cp page.path, page.destination
104
+ FileUtils.chmod 0644, page.destination
104
105
 
105
106
  # otherwise, layout the resource and write the results to
106
107
  # the output directory
@@ -123,7 +124,7 @@ class Builder
123
124
  ::Find.find(layout_dir, content_dir) do |path|
124
125
  next unless test ?f, path
125
126
  next if path =~ ::Webby.exclude
126
- Resource.new path
127
+ Resources.new path
127
128
  end
128
129
  end
129
130
 
@@ -132,7 +133,7 @@ class Builder
132
133
  # error if one is detected.
133
134
  #
134
135
  def loop_check
135
- layouts = Resource.layouts
136
+ layouts = Resources.layouts
136
137
 
137
138
  layouts.each do |lyt|
138
139
  stack = []
data/lib/webby/filters.rb CHANGED
@@ -1,4 +1,4 @@
1
- # $Id: filters.rb 68 2007-12-09 07:45:37Z tim_pease $
1
+ # $Id: filters.rb 179 2008-02-29 04:47:19Z tim_pease $
2
2
 
3
3
  module Webby
4
4
  module Filters
@@ -47,11 +47,14 @@ module Filters
47
47
  end
48
48
 
49
49
  def start_for(input)
50
+ @renderer.instance_variable_set(:@_cursor, self)
50
51
  filters.inject(input) do |result, filter|
51
52
  handler = Filters[filter]
52
53
  args = [result, self][0, handler.arity]
53
54
  handle(filter, handler, *args)
54
55
  end
56
+ ensure
57
+ @renderer.instance_variable_set(:@_cursor, nil)
55
58
  end
56
59
 
57
60
  # The list of filters yet to be processed
@@ -73,12 +76,6 @@ module Filters
73
76
  result = handler.call(*args)
74
77
  @processed += 1
75
78
  result
76
- rescue NameError => e
77
- @log.fatal "Name error in filter `#{filter}' (missing dependency?): #{e.message}"
78
- exit 1
79
- rescue => e
80
- @log.fatal "Error in filter `#{filter}': #{e.message}"
81
- exit 1
82
79
  end
83
80
 
84
81
  end # class Cursor
@@ -87,4 +84,6 @@ module Filters
87
84
  end # module Filters
88
85
  end # module Webby
89
86
 
87
+ Webby.require_all_libs_relative_to(__FILE__)
88
+
90
89
  # EOF
@@ -1,4 +1,4 @@
1
- # $Id: outline.rb 151 2008-02-15 21:09:47Z tim_pease $
1
+ # $Id: outline.rb 181 2008-02-29 05:09:49Z tim_pease $
2
2
 
3
3
  require 'hpricot'
4
4
 
@@ -27,7 +27,9 @@ module Filters
27
27
  class Outline
28
28
  include ERB::Util
29
29
 
30
- class Error < StandardError; end # :nodoc:
30
+ # :stopdoc:
31
+ class Error < StandardError; end
32
+ # :startdoc:
31
33
 
32
34
  # call-seq:
33
35
  # Outline.new( html )
@@ -1,4 +1,4 @@
1
- # $Id: tidy.rb 68 2007-12-09 07:45:37Z tim_pease $
1
+ # $Id: tidy.rb 181 2008-02-29 05:09:49Z tim_pease $
2
2
 
3
3
  require 'fileutils'
4
4
  require 'tempfile'
@@ -20,7 +20,9 @@ module Filters
20
20
  #
21
21
  class Tidy
22
22
 
23
- class Error < StandardError; end # :nodoc:
23
+ # :stopdoc:
24
+ class Error < StandardError; end
25
+ # :startdoc:
24
26
 
25
27
  # call-seq:
26
28
  # Tidy.new( html )
@@ -0,0 +1,32 @@
1
+ # $Id: helpers.rb 167 2008-02-24 00:59:54Z tim_pease $
2
+
3
+ require Webby.libpath(*%w[webby renderer])
4
+
5
+ module Webby
6
+
7
+ # The Helpers module is used to register helper modules that provide extra
8
+ # functionality to the Webby renderer. The most notable example is the
9
+ # UrlHelpers module that provides methods to link to another page in a
10
+ # Webby webiste.
11
+ #
12
+ # Helpers are registered with the Webby framework by calling:
13
+ #
14
+ # Webby::Helpers.register( MyHelper )
15
+ #
16
+ module Helpers
17
+
18
+ # call-seq:
19
+ # Helpers.register( module )
20
+ #
21
+ # Register the given _module_ as a helper module for the Webby framework.
22
+ #
23
+ def self.register( helper )
24
+ ::Webby::Renderer.__send__( :include, helper )
25
+ end
26
+
27
+ end # module Helper
28
+ end # module Webby
29
+
30
+ Webby.require_all_libs_relative_to(__FILE__)
31
+
32
+ # EOF
@@ -0,0 +1,78 @@
1
+ # $Id: coderay_helper.rb 155 2008-02-17 00:48:30Z tim_pease $
2
+
3
+ if try_require 'coderay'
4
+ require 'enumerator'
5
+
6
+ module Webby::Helpers
7
+ module CodeRayHelper
8
+
9
+ # The +coderay+ method applies syntax highlighting to source code embedded
10
+ # in a webpage. The CodeRay highlighting engine is used for the HTML
11
+ # markup of the source code. The page sections to be highlighted are given
12
+ # as blocks of text to the +coderay+ method.
13
+ #
14
+ # Options can be passed to the CodeRay engine via attributes in the
15
+ # +coderay+ method.
16
+ #
17
+ # <% coderay( :lang => "ruby", :line_numbers => "inline" ) do -%>
18
+ # # Initializer for the class.
19
+ # def initialize( string )
20
+ # @str = stirng
21
+ # end
22
+ # <% end -%>
23
+ #
24
+ # The supported CodeRay options are the following:
25
+ #
26
+ # :lang : the language to highlight (ruby, c, html, ...)
27
+ # :line_numbers : include line numbers in 'table', 'inline',
28
+ # or 'list'
29
+ # :line_number_start : where to start with line number counting
30
+ # :bold_every : make every n-th number appear bold
31
+ # :tab_width : convert tab characters to n spaces
32
+ #
33
+ def coderay( *args, &block )
34
+ opts = args.last.instance_of?(Hash) ? args.pop : {}
35
+
36
+ buffer = eval('_erbout', block.binding)
37
+ pos = buffer.length
38
+ block.call(*args)
39
+
40
+ text = buffer[pos..-1].strip
41
+ if text.empty?
42
+ buffer[pos..-1] = ''
43
+ return
44
+ end
45
+
46
+ lang = opts.getopt(:lang, :ruby).to_sym
47
+
48
+ cr_opts = {}
49
+ %w(line_numbers to_sym
50
+ line_number_start to_i
51
+ bold_every to_i
52
+ tab_width to_i).each_slice(2) do |key,convert|
53
+ val = opts.getopt(key)
54
+ next if val.nil?
55
+ cr_opts[key.to_sym] = val.send(convert)
56
+ end
57
+
58
+ #cr.swap(CodeRay.scan(text, lang).html(opts).div)
59
+ out = '<div class="CodeRay"><pre>'
60
+ out << ::CodeRay.scan(text, lang).html(cr_opts)
61
+ out << '</pre></div>'
62
+
63
+ if @_cursor.remaining_filters.include? 'textile'
64
+ out.insert 0, "<notextile>\n"
65
+ out << "\n</notextile>"
66
+ end
67
+
68
+ buffer[pos..-1] = out
69
+ return
70
+ end
71
+ end # module CodeRayHelper
72
+
73
+ register(CodeRayHelper)
74
+
75
+ end # module Webby::Helpers
76
+ end # try_require
77
+
78
+ # EOF
@@ -0,0 +1,158 @@
1
+ # $Id: graphviz_helper.rb 181 2008-02-29 05:09:49Z tim_pease $
2
+
3
+ require 'fileutils'
4
+ require 'tempfile'
5
+
6
+ module Webby::Helpers
7
+ module GraphvizHelper
8
+
9
+ # :stopdoc:
10
+ class Error < StandardError; end
11
+ # :startdoc:
12
+
13
+ # call-seq:
14
+ # GraphvizHelper.error_check( file )
15
+ #
16
+ # Check the temporary error file to see if it contains any error messages
17
+ # from the graphviz program. If it is not empty, then read the contents
18
+ # and log an error message and raise an exception.
19
+ #
20
+ def self.error_check( file )
21
+ if ::File.size(file.path) != 0
22
+ msg = "\n" << ::File.read(file.path).strip
23
+ raise Error, msg
24
+ end
25
+ end
26
+
27
+ # The +graphviz+ method processes DOT scripts in a webpage and replaces them
28
+ # with generated image files. The page sections to be processed are given
29
+ # as blocks of text to the +graphviz+ method.
30
+ #
31
+ # Options can be passed to the Graphviz program using attributes in the
32
+ # +graphviz+ method.
33
+ #
34
+ # <% graphviz( :path => "images", :type => "gif", cmd => "dot" ) do %>
35
+ # digraph graph_1 {
36
+ # graph [URL="default.html"]
37
+ # a [URL="a.html"]
38
+ # b [URL="b.html"]
39
+ # c [URL="c.html"]
40
+ # a -> b -> c
41
+ # a -> c
42
+ # }
43
+ # <% end %>
44
+ #
45
+ # If the DOT script contains *URL* or *href* attributes on any of the nodes
46
+ # or edges, then an image map will be generated and the image will be
47
+ # "clikcable" in the webpage. If *URL* or *href* attributes do not appear in
48
+ # the DOT script, then a regular image will be inserted into the webpage.
49
+ #
50
+ # The image is inserted into the page using an HTML <img /> tag. A
51
+ # corresponding <map>...</map> element will be inserted if needed.
52
+ #
53
+ # The supported Graphviz options are the following:
54
+ #
55
+ # :path : where generated images will be stored
56
+ # [default is "/"]
57
+ # :type : the type of image to generate (png, jpeg, gif)
58
+ # [default is png]
59
+ # :cmd : the Graphviz command to use when generating images
60
+ # (dot, neato, twopi, circo, fdp) [default is dot]
61
+ #
62
+ # the following options are passed as-is to the generated <img /> tag
63
+ # :style : CSS styles to apply to the <img />
64
+ # :class : CSS class to apply to the <img />
65
+ # :id : HTML identifier
66
+ # :alt : alternate text for the <img />
67
+ #
68
+ def graphviz( *args, &block )
69
+ opts = args.last.instance_of?(Hash) ? args.pop : {}
70
+
71
+ # create a temporary file for holding any error messages
72
+ # from the graphviz program
73
+ err = Tempfile.new('graphviz_err')
74
+ err.close
75
+
76
+ buffer = eval('_erbout', block.binding)
77
+ pos = buffer.length
78
+ block.call(*args)
79
+
80
+ path = opts.getopt(:path)
81
+ cmd = opts.getopt(:cmd, 'dot')
82
+ type = opts.getopt(:type, 'png')
83
+ text = buffer[pos..-1].strip
84
+ if text.empty?
85
+ buffer[pos..-1] = ''
86
+ return
87
+ end
88
+
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
+ # pull the name of the graph|digraph out of the DOT script
96
+ name = text.match(%r/\A\s*(?:strict\s+)?(?:di)?graph\s+([A-Za-z_][A-Za-z0-9_]*)\s+\{/o)[1]
97
+
98
+ # see if the user includes any URL or href attributes
99
+ # if so, then we need to create an imagemap
100
+ usemap = text.match(%r/(?:URL|href)\s*=/o) != nil
101
+
102
+ # generate the image filename based on the path, graph name, and type
103
+ # of image to generate
104
+ image_fn = path.nil? ? name.dup : ::File.join(path, name)
105
+ image_fn = ::File.join('', image_fn) << '.' << type
106
+
107
+ # create the HTML img tag
108
+ out = "<img src=\"#{image_fn}\""
109
+
110
+ %w[class style id alt].each do |atr|
111
+ val = opts.getopt(atr)
112
+ next if val.nil?
113
+ out << " %s=\"%s\"" % [atr, val]
114
+ end
115
+
116
+ out << " usemap=\"\##{name}\"" if usemap
117
+ out << " />\n"
118
+
119
+ # generate the image map if needed
120
+ if usemap
121
+ IO.popen("#{cmd} -Tcmapx 2> #{err.path}", 'r+') do |io|
122
+ io.write text
123
+ io.close_write
124
+ out << io.read
125
+ end
126
+ GraphvizHelper.error_check(err)
127
+ end
128
+
129
+ # generate the image using graphviz -- but first ensure that the
130
+ # path exists
131
+ out_dir = ::Webby.site.output_dir
132
+ out_file = ::File.join(out_dir, image_fn)
133
+ FileUtils.mkpath(::File.join(out_dir, path)) unless path.nil?
134
+ cmd = "#{cmd} -T#{type} -o #{out_file} 2> #{err.path}"
135
+
136
+ IO.popen(cmd, 'w') {|io| io.write text}
137
+ GraphvizHelper.error_check(err)
138
+
139
+ # see if we need to put some guards around the output
140
+ # (specifically for textile)
141
+ if @_cursor.remaining_filters.include? 'textile'
142
+ out.insert 0, "<notextile>\n"
143
+ out << "\n</notextile>"
144
+ end
145
+
146
+ buffer[pos..-1] = out
147
+ return
148
+ end
149
+ end # module GraphvizHelper
150
+
151
+ %x[dot -V 2>&1]
152
+ if 0 == $?.exitstatus
153
+ register(GraphvizHelper)
154
+ end
155
+
156
+ end # module Webby::Helpers
157
+
158
+ # EOF
@@ -1,6 +1,9 @@
1
+ # $Id: tag_helper.rb 157 2008-02-20 17:41:00Z tim_pease $
2
+
1
3
  require 'erb'
2
4
  require 'set'
3
5
 
6
+ # :stopdoc:
4
7
  class ERB
5
8
  module Util
6
9
  HTML_ESCAPE = { '&' => '&amp;', '"' => '&quot;', '>' => '&gt;', '<' => '&lt;' }
@@ -10,9 +13,9 @@ class ERB
10
13
  end
11
14
  end
12
15
  end
16
+ # :startdoc:
13
17
 
14
- module Webby
15
- module Helpers #:nodoc:
18
+ module Webby::Helpers
16
19
 
17
20
  # Provides methods to generate HTML tags programmatically.
18
21
  # By default, they output XHTML compliant tags.
@@ -56,7 +59,9 @@ module TagHelper
56
59
  end
57
60
 
58
61
  end # module TagHelper
59
- end # module Helpers
60
- end # module Webby
62
+
63
+ register(TagHelper)
64
+
65
+ end # module Webby::Helpers
61
66
 
62
67
  # EOF