webby 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -1
- data/Manifest.txt +36 -27
- data/README.txt +21 -1
- data/Rakefile +12 -8
- data/bin/webby +2 -10
- data/data/Rakefile +1 -0
- data/data/tasks/create.rake +1 -0
- data/data/tasks/deploy.rake +1 -0
- data/data/tasks/growl.rake +13 -12
- data/data/tasks/heel.rake +29 -32
- data/data/tasks/setup.rb +4 -9
- data/{website → examples/webby}/Rakefile +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/buttons.css +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/compressed.css +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/grid.css +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/img/grid.png +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/img/icons/cross.png +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/img/icons/textfield_key.png +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/img/icons/tick.png +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/reset.css +0 -0
- data/{website → examples/webby}/content/css/blueprint/lib/typography.css +0 -0
- data/{website → examples/webby}/content/css/blueprint/print.css +0 -0
- data/{website → examples/webby}/content/css/blueprint/screen.css +0 -0
- data/{website → examples/webby}/content/css/coderay.css +0 -0
- data/{website → examples/webby}/content/css/site.css +0 -0
- data/{website → examples/webby}/content/download.txt +0 -0
- data/{website → examples/webby}/content/index.txt +0 -0
- data/examples/webby/content/manual.txt +24 -0
- data/{website → examples/webby}/content/robots.txt +0 -0
- data/{website → examples/webby}/content/tips_and_tricks.txt +0 -0
- data/{website → examples/webby}/content/tutorial.txt +6 -6
- data/{website → examples/webby}/layouts/default.rhtml +0 -0
- data/{website → examples/webby}/tasks/create.rake +0 -0
- data/{website → examples/webby}/tasks/deploy.rake +0 -0
- data/{website → examples/webby}/tasks/growl.rake +12 -12
- data/{website → examples/webby}/tasks/heel.rake +28 -32
- data/{website → examples/webby}/tasks/setup.rb +3 -9
- data/{website → examples/webby}/templates/page.erb +0 -0
- data/lib/webby/file.rb +33 -1
- data/lib/webby/filters/coderay.rb +8 -2
- data/lib/webby/filters/erb.rb +11 -0
- data/lib/webby/filters/graphviz.rb +22 -8
- data/lib/webby/filters/haml.rb +16 -0
- data/lib/webby/filters/markdown.rb +10 -0
- data/lib/webby/filters/sass.rb +11 -0
- data/lib/webby/filters/textile.rb +10 -0
- data/lib/webby/filters/tidy.rb +8 -1
- data/lib/webby/filters.rb +90 -0
- data/lib/webby/helpers/tag_helper.rb +61 -0
- data/lib/webby/helpers/url_helper.rb +162 -0
- data/lib/webby/pages_db.rb +8 -9
- data/lib/webby/renderer.rb +20 -113
- data/lib/webby/resource.rb +13 -6
- data/lib/webby/utils.rb +13 -1
- data/lib/webby/webby_task.rb +7 -1
- data/lib/webby.rb +21 -17
- data/spec/spec_helper.rb +3 -9
- data/tasks/annotations.rake +30 -0
- data/tasks/doc.rake +7 -1
- data/tasks/gem.rake +6 -2
- data/tasks/manifest.rake +6 -4
- data/tasks/rubyforge.rake +1 -1
- data/tasks/setup.rb +29 -7
- data/tasks/spec.rake +8 -5
- data/tasks/website.rake +2 -2
- metadata +123 -116
- data/website/content/manual.txt +0 -60
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: graphviz.rb
|
1
|
+
# $Id: graphviz.rb 71 2007-12-13 05:45:53Z tim_pease $
|
2
2
|
|
3
3
|
require 'hpricot'
|
4
4
|
require 'fileutils'
|
@@ -25,9 +25,9 @@ module Filters
|
|
25
25
|
# }
|
26
26
|
# </graphviz>
|
27
27
|
#
|
28
|
-
# If the DOT script contains *URL* or *href*
|
28
|
+
# If the DOT script contains *URL* or *href* cursorments on any of the nodes
|
29
29
|
# or edges, then an image map will be generated and the image will be
|
30
|
-
# "clikcable" in the webpage. If *URL* or *href*
|
30
|
+
# "clikcable" in the webpage. If *URL* or *href* cursorments do not appear in
|
31
31
|
# the DOT script, then a regular image will be inserted into the webpage.
|
32
32
|
#
|
33
33
|
# The image is inserted into the page using an HTML <img /> tag. A
|
@@ -60,7 +60,6 @@ class Graphviz
|
|
60
60
|
# output string returned by the Graphviz filter.
|
61
61
|
#
|
62
62
|
def initialize( str, filters = nil )
|
63
|
-
@log = ::Logging::Logger[self]
|
64
63
|
@str = str
|
65
64
|
@filters = filters
|
66
65
|
|
@@ -82,11 +81,19 @@ class Graphviz
|
|
82
81
|
doc = Hpricot(@str)
|
83
82
|
doc.search('//graphviz') do |gviz|
|
84
83
|
|
85
|
-
text = gviz.inner_html.strip # the DOT script to process
|
86
84
|
path = gviz['path']
|
87
85
|
cmd = gviz['cmd'] || 'dot'
|
88
86
|
type = gviz['type'] || 'png'
|
87
|
+
text = gviz.inner_html.strip # the DOT script to process
|
88
|
+
|
89
|
+
# if we don't have a DOT script, then replace it with
|
90
|
+
# the empty text and move on to the next graphviz tags
|
91
|
+
if text.empty?
|
92
|
+
gviz.swap text
|
93
|
+
next
|
94
|
+
end
|
89
95
|
|
96
|
+
# ensure the requested graphviz command actually exists
|
90
97
|
%x[#{cmd} -V 2>&1]
|
91
98
|
unless 0 == $?.exitstatus
|
92
99
|
raise NameError, "'#{cmd}' not found on the path"
|
@@ -102,7 +109,7 @@ class Graphviz
|
|
102
109
|
# generate the image filename based on the path, graph name, and type
|
103
110
|
# of image to generate
|
104
111
|
image_fn = path.nil? ? name.dup : File.join(path, name)
|
105
|
-
image_fn << '.' << type
|
112
|
+
image_fn = File.join('', image_fn) << '.' << type
|
106
113
|
|
107
114
|
# create the HTML img tag
|
108
115
|
out = "<img src=\"#{image_fn}\""
|
@@ -163,12 +170,19 @@ class Graphviz
|
|
163
170
|
#
|
164
171
|
def error_check
|
165
172
|
if File.size(@err.path) != 0
|
166
|
-
|
167
|
-
raise Error
|
173
|
+
msg = "\n" << File.read(@err.path).strip
|
174
|
+
raise Error, msg
|
168
175
|
end
|
169
176
|
end
|
170
177
|
|
171
178
|
end # class Graphviz
|
179
|
+
|
180
|
+
# Render text into iamges via the Graphviz programs.
|
181
|
+
#
|
182
|
+
register :graphviz do |input, cursor|
|
183
|
+
Filters::Graphviz.new(input, cursor.remaining_filters).to_html
|
184
|
+
end
|
185
|
+
|
172
186
|
end # module Filters
|
173
187
|
end # module Webby
|
174
188
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# $Id: haml.rb 68 2007-12-09 07:45:37Z tim_pease $
|
2
|
+
|
3
|
+
try_require 'haml'
|
4
|
+
|
5
|
+
# Render text via the Haml library
|
6
|
+
Webby::Filters.register :haml do |input, cursor|
|
7
|
+
opts = cursor.page.haml_options || {}
|
8
|
+
opts[:locals] ||= {}
|
9
|
+
opts[:locals].merge!(
|
10
|
+
:page => cursor.renderer.page,
|
11
|
+
:pages => cursor.renderer.pages
|
12
|
+
)
|
13
|
+
Haml::Engine.new(input, opts).to_html
|
14
|
+
end
|
15
|
+
|
16
|
+
# EOF
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# $Id: sass.rb 68 2007-12-09 07:45:37Z tim_pease $
|
2
|
+
|
3
|
+
try_require 'sass'
|
4
|
+
|
5
|
+
# Render text via the Sass library (part of Haml)
|
6
|
+
Webby::Filters.register :sass do |input, cursor|
|
7
|
+
opts = cursor.page.sass_options || {}
|
8
|
+
Sass::Engine.new(input, opts).render
|
9
|
+
end
|
10
|
+
|
11
|
+
# EOF
|
data/lib/webby/filters/tidy.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: tidy.rb
|
1
|
+
# $Id: tidy.rb 68 2007-12-09 07:45:37Z tim_pease $
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'tempfile'
|
@@ -65,6 +65,13 @@ class Tidy
|
|
65
65
|
end
|
66
66
|
|
67
67
|
end # class Tidy
|
68
|
+
|
69
|
+
# Render html into html/xhtml via the Tidy program
|
70
|
+
#
|
71
|
+
register :tidy do |input|
|
72
|
+
Filters::Tidy.new(input).process
|
73
|
+
end
|
74
|
+
|
68
75
|
end # module Filters
|
69
76
|
end # module Webby
|
70
77
|
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# $Id: filters.rb 68 2007-12-09 07:45:37Z tim_pease $
|
2
|
+
|
3
|
+
module Webby
|
4
|
+
module Filters
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# Register a handler for a filter
|
9
|
+
def register( filter, &block )
|
10
|
+
handlers[filter.to_s] = block
|
11
|
+
end
|
12
|
+
|
13
|
+
# Process input through filters
|
14
|
+
def process( renderer, page, input )
|
15
|
+
# Start a new cursor for this page
|
16
|
+
Cursor.new(renderer, page).start_for(input)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Access a filter handler
|
20
|
+
def []( name )
|
21
|
+
handlers[name]
|
22
|
+
end
|
23
|
+
|
24
|
+
#######
|
25
|
+
private
|
26
|
+
#######
|
27
|
+
|
28
|
+
# The registered filter handlers
|
29
|
+
def handlers
|
30
|
+
@handlers ||= {}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Instances of this class handle processing a set of filters
|
34
|
+
# for a given renderer and page.
|
35
|
+
# Note: The instance is passed as the second argument to filters
|
36
|
+
# that require two parameters and can be used to access
|
37
|
+
# information on the renderer, page, or filters being
|
38
|
+
# processed.
|
39
|
+
class Cursor
|
40
|
+
|
41
|
+
attr_reader :renderer, :page, :filters
|
42
|
+
def initialize(renderer, page)
|
43
|
+
@renderer, @page = renderer, page
|
44
|
+
@filters = Array(page.filter)
|
45
|
+
@log = Logging::Logger[Webby::Renderer]
|
46
|
+
@processed = 0
|
47
|
+
end
|
48
|
+
|
49
|
+
def start_for(input)
|
50
|
+
filters.inject(input) do |result, filter|
|
51
|
+
handler = Filters[filter]
|
52
|
+
args = [result, self][0, handler.arity]
|
53
|
+
handle(filter, handler, *args)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# The list of filters yet to be processed
|
58
|
+
def remaining_filters
|
59
|
+
filters[@processed..-1]
|
60
|
+
end
|
61
|
+
|
62
|
+
# The name of the current filter
|
63
|
+
def current_filter
|
64
|
+
filters[@processed]
|
65
|
+
end
|
66
|
+
|
67
|
+
#######
|
68
|
+
private
|
69
|
+
#######
|
70
|
+
|
71
|
+
# Process arguments through a single filter
|
72
|
+
def handle(filter, handler, *args)
|
73
|
+
result = handler.call(*args)
|
74
|
+
@processed += 1
|
75
|
+
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
|
+
end
|
83
|
+
|
84
|
+
end # class Cursor
|
85
|
+
end # class << self
|
86
|
+
|
87
|
+
end # module Filters
|
88
|
+
end # module Webby
|
89
|
+
|
90
|
+
# EOF
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
class ERB
|
5
|
+
module Util
|
6
|
+
HTML_ESCAPE = { '&' => '&', '"' => '"', '>' => '>', '<' => '<' }
|
7
|
+
|
8
|
+
def html_escape(s)
|
9
|
+
s.to_s.gsub(/[&\"><]/) { |special| HTML_ESCAPE[special] }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Webby
|
15
|
+
module Helpers #:nodoc:
|
16
|
+
|
17
|
+
# Provides methods to generate HTML tags programmatically.
|
18
|
+
# By default, they output XHTML compliant tags.
|
19
|
+
#
|
20
|
+
module TagHelper
|
21
|
+
include ERB::Util
|
22
|
+
|
23
|
+
BOOLEAN_ATTRIBUTES = Set.new(%w(disabled readonly multiple))
|
24
|
+
|
25
|
+
# Returns an escaped version of +html+ without affecting existing escaped
|
26
|
+
# entities.
|
27
|
+
#
|
28
|
+
# ==== Examples
|
29
|
+
# escape_once("1 > 2 & 3")
|
30
|
+
# # => "1 < 2 & 3"
|
31
|
+
#
|
32
|
+
# escape_once("<< Accept & Checkout")
|
33
|
+
# # => "<< Accept & Checkout"
|
34
|
+
#
|
35
|
+
def escape_once( html )
|
36
|
+
html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| ERB::Util::HTML_ESCAPE[special] }
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def tag_options( options, escape = true )
|
41
|
+
unless options.empty?
|
42
|
+
attrs = []
|
43
|
+
if escape
|
44
|
+
options.each do |key, value|
|
45
|
+
next if value.nil?
|
46
|
+
key = key.to_s
|
47
|
+
value = BOOLEAN_ATTRIBUTES.include?(key) ? key : escape_once(value)
|
48
|
+
attrs << %Q(#{key}="#{value}")
|
49
|
+
end
|
50
|
+
else
|
51
|
+
attrs = options.map {|key, value| %Q(#{key}="#{value}")}
|
52
|
+
end
|
53
|
+
%Q( #{attrs.sort * ' '}) unless attrs.empty?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end # module TagHelper
|
58
|
+
end # module Helpers
|
59
|
+
end # module Webby
|
60
|
+
|
61
|
+
# EOF
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# $Id: url_helper.rb 75 2007-12-20 23:10:19Z tim_pease $
|
2
|
+
|
3
|
+
module Webby
|
4
|
+
module Helpers #:nodoc:
|
5
|
+
|
6
|
+
#
|
7
|
+
#
|
8
|
+
module UrlHelper
|
9
|
+
|
10
|
+
# call-seq:
|
11
|
+
# url_for( string, opts = {} )
|
12
|
+
# url_for( page, opts ={} )
|
13
|
+
#
|
14
|
+
# Options
|
15
|
+
#
|
16
|
+
# :escape => determins whether the returned URL will be HTML escaped
|
17
|
+
# or not (+true+ by default)
|
18
|
+
# :anchor => specifies the anchor name to be appended to the path
|
19
|
+
#
|
20
|
+
def url_for( *args )
|
21
|
+
opts = Hash === args.last ? args.pop : {}
|
22
|
+
obj = args.first
|
23
|
+
|
24
|
+
anchor = opts.delete(:anchor)
|
25
|
+
escape = opts.has_key?(:escape) ? opts.delte(:escape) : true
|
26
|
+
|
27
|
+
url = Webby::Resource === obj ? obj.url : obj.to_s
|
28
|
+
url = escape_once(url) if escape
|
29
|
+
url << "#" << anchor if anchor
|
30
|
+
|
31
|
+
return url
|
32
|
+
end
|
33
|
+
|
34
|
+
def url_for_page( opts = {} )
|
35
|
+
opts = opts.symbolize_keys
|
36
|
+
url_opts = opts.delete(:url)
|
37
|
+
|
38
|
+
p = @pages.find(opts)
|
39
|
+
raise Webby::Renderer::Error,
|
40
|
+
"could not find requested page: #{opts.inspect}" if p.nil?
|
41
|
+
|
42
|
+
self.url_for(p, url_opts)
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
#
|
47
|
+
def link_to( name, *args )
|
48
|
+
opts = Hash === args.last ? args.pop : {}
|
49
|
+
url = args.first
|
50
|
+
attrs = opts.delete(:attrs)
|
51
|
+
|
52
|
+
url = case url
|
53
|
+
when String
|
54
|
+
url
|
55
|
+
when Webby::Resource
|
56
|
+
self.url_for(url, opts)
|
57
|
+
when :back
|
58
|
+
'javascript:history.back()'
|
59
|
+
else
|
60
|
+
self.url_for(name, opts)
|
61
|
+
end
|
62
|
+
|
63
|
+
if attrs
|
64
|
+
html_opts = attrs.stringify_keys
|
65
|
+
href = html_opts.has_key? 'href'
|
66
|
+
attrs = tag_options(html_opts)
|
67
|
+
else
|
68
|
+
href = false
|
69
|
+
attrs = nil
|
70
|
+
end
|
71
|
+
|
72
|
+
href_attr = href ? nil : %Q(href="#{url}")
|
73
|
+
"<a #{href_attr}#{attrs}>#{name || url}</a>"
|
74
|
+
end
|
75
|
+
|
76
|
+
# call-seq:
|
77
|
+
# link_to_page( name )
|
78
|
+
# link_to_page( :key => value )
|
79
|
+
# link_to_page( name, :key => value )
|
80
|
+
# link_to_page( page )
|
81
|
+
#
|
82
|
+
# Creates a link tag of the given _name_ using a URL created by finding
|
83
|
+
# the associated page from the key/value pairs. If the key/value pairs are
|
84
|
+
# omitted, the _name_ is used in conjunction with the default site +find_by+
|
85
|
+
# attribute. If the _name_ is omitted, then either the page +title+
|
86
|
+
# attribute or the page +filename+ attribute is used as the name (in that
|
87
|
+
# order of preference).
|
88
|
+
#
|
89
|
+
# Pages are found using key/value pairs. The key is any of the page
|
90
|
+
# attributes, and the value is what that attribute should be. Any number
|
91
|
+
# of key/value pairs can be included, but all values must equal the
|
92
|
+
# corresponding page attributes for a match to be found -- i.e. the
|
93
|
+
# comparisons are joined by AND operations to determine a match.
|
94
|
+
#
|
95
|
+
# In the absence of any key/value pairs -- just a name was given -- then
|
96
|
+
# the default site +find_by+ attribute is used, and the name is compared
|
97
|
+
# against this attribute from the page. The default +find_by+ attribue is
|
98
|
+
# set in the Rakefile or in the <tt>Webby.site.find_by</tt> parameter.
|
99
|
+
#
|
100
|
+
# Several options can be passed to the method to determin how URLs are
|
101
|
+
# created and to specify any HTML attributes on the returned link tag. The
|
102
|
+
# URL options are given as a hash to the <tt>:url</tt> key. The HTML
|
103
|
+
# attributes are given as a hash to the <tt>:attrs</tt> key.
|
104
|
+
#
|
105
|
+
# See the +url_for+ method for a desciption of the <tt>:url</tt> options.
|
106
|
+
# See the +link_to+ method for a description of the <tt>:attrs</tt>
|
107
|
+
# options.
|
108
|
+
#
|
109
|
+
# ==== Examples
|
110
|
+
#
|
111
|
+
def link_to_page( *args )
|
112
|
+
self.link_to(*_find_page(args))
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
#
|
117
|
+
def link_to_page_unless_current( *args )
|
118
|
+
name, page, link_opts = _find_page(args)
|
119
|
+
return name if @page == page
|
120
|
+
|
121
|
+
self.link_to(name, page, link_opts)
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
# call-seq:
|
128
|
+
# _find_page( name, opts = {} )
|
129
|
+
# _find_page( :key => value, [:key => value, ...], opts = {} )
|
130
|
+
# _find_page( name, :key => value, [:key => value, ...], opts = {} )
|
131
|
+
# _find_page( page, opts = {} )
|
132
|
+
#
|
133
|
+
# Returns an array of the [name, page, options].
|
134
|
+
#
|
135
|
+
def _find_page( args )
|
136
|
+
raise ArgumentError, 'wrong number of arguments (0 for 1)' if args.empty?
|
137
|
+
|
138
|
+
opts = Hash === args.last ? args.pop : {}
|
139
|
+
name = args.first
|
140
|
+
link_opts = opts.delete(:url) || {}
|
141
|
+
link_opts[:attrs] = opts.delete(:attrs)
|
142
|
+
|
143
|
+
if Webby::Resource === name
|
144
|
+
p, name = name, nil
|
145
|
+
elsif opts.empty? && name
|
146
|
+
p = @pages.find(Webby.site.find_by.to_sym => name)
|
147
|
+
else
|
148
|
+
p = @pages.find(opts)
|
149
|
+
end
|
150
|
+
|
151
|
+
raise Webby::Renderer::Error,
|
152
|
+
"could not find requested page: #{opts.inspect}" if p.nil?
|
153
|
+
|
154
|
+
name = h(p.title || p.filename) if name.nil?
|
155
|
+
return [name, p, link_opts]
|
156
|
+
end
|
157
|
+
|
158
|
+
end # module UrlHelper
|
159
|
+
end # module Helpers
|
160
|
+
end # module Webby
|
161
|
+
|
162
|
+
# EOF
|
data/lib/webby/pages_db.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: pages_db.rb
|
1
|
+
# $Id: pages_db.rb 67 2007-12-09 00:49:26Z tim_pease $
|
2
2
|
|
3
3
|
module Webby
|
4
4
|
|
@@ -78,7 +78,7 @@ class PagesDB
|
|
78
78
|
#
|
79
79
|
# Options include:
|
80
80
|
#
|
81
|
-
# :all
|
81
|
+
# :all
|
82
82
|
# :in_directory => 'directory'
|
83
83
|
#
|
84
84
|
# Examples:
|
@@ -87,19 +87,18 @@ class PagesDB
|
|
87
87
|
# pages_db.find( :filename => 'index', :in_directory => 'foo/bar' )
|
88
88
|
#
|
89
89
|
# # find all resources named "widgets" whose color is "blue"
|
90
|
-
# pages_db.find( :name => 'widgets', :color => 'blue'
|
90
|
+
# pages_db.find( :all, :name => 'widgets', :color => 'blue' )
|
91
91
|
#
|
92
92
|
# # find all resources created in the past week
|
93
|
-
# pages_db.find( :all
|
93
|
+
# pages_db.find( :all ) do |resource|
|
94
94
|
# resource.created_at > Time.now - (7 * 24 * 3600)
|
95
95
|
# end
|
96
96
|
#
|
97
|
-
def find(
|
98
|
-
|
99
|
-
|
97
|
+
def find( *args, &block )
|
98
|
+
opts = Hash === args.last ? args.pop : {}
|
99
|
+
find_all = args.include? :all
|
100
100
|
|
101
|
-
dir =
|
102
|
-
else nil end
|
101
|
+
dir = opts.has_key?(:in_directory) ? opts.delete(:in_directory) : nil
|
103
102
|
if dir && !@db.has_key?(dir)
|
104
103
|
raise RuntimeError, "unknown directory '#{dir}'"
|
105
104
|
end
|
data/lib/webby/renderer.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: renderer.rb
|
1
|
+
# $Id: renderer.rb 68 2007-12-09 07:45:37Z tim_pease $
|
2
2
|
|
3
3
|
require 'erb'
|
4
4
|
try_require 'bluecloth'
|
@@ -22,6 +22,10 @@ module Webby
|
|
22
22
|
#
|
23
23
|
class Renderer
|
24
24
|
include ERB::Util
|
25
|
+
include Webby::Helpers::TagHelper
|
26
|
+
include Webby::Helpers::UrlHelper
|
27
|
+
|
28
|
+
class Error < StandardError; end # :nodoc:
|
25
29
|
|
26
30
|
# call-seq:
|
27
31
|
# Renderer.write( page )
|
@@ -37,7 +41,7 @@ class Renderer
|
|
37
41
|
::File.open(page.destination, 'w') do |fd|
|
38
42
|
fd.write renderer.layout_page
|
39
43
|
end
|
40
|
-
break unless renderer.next_page
|
44
|
+
break unless renderer.__send__(:next_page)
|
41
45
|
}
|
42
46
|
end
|
43
47
|
|
@@ -79,11 +83,7 @@ class Renderer
|
|
79
83
|
break if lyt.nil?
|
80
84
|
|
81
85
|
@content, str = str, ::Webby::File.read(lyt.path)
|
82
|
-
|
83
|
-
Array(lyt.filter).each do |filter|
|
84
|
-
str = self.send(filter + '_filter', str)
|
85
|
-
end
|
86
|
-
|
86
|
+
str = Filters.process(self, lyt, str)
|
87
87
|
@content, obj = nil, lyt
|
88
88
|
end
|
89
89
|
|
@@ -97,13 +97,7 @@ class Renderer
|
|
97
97
|
# determined from the page's meta-data.
|
98
98
|
#
|
99
99
|
def render_page
|
100
|
-
|
101
|
-
|
102
|
-
Array(@page.filter).each do |filter|
|
103
|
-
str = self.send(filter + '_filter', str)
|
104
|
-
end
|
105
|
-
|
106
|
-
str
|
100
|
+
Filters.process(self, @page, ::Webby::File.read(@page.path))
|
107
101
|
end
|
108
102
|
|
109
103
|
# call-seq:
|
@@ -128,6 +122,18 @@ class Renderer
|
|
128
122
|
@pager.each &block
|
129
123
|
end
|
130
124
|
|
125
|
+
# call-seq:
|
126
|
+
# get_binding => binding
|
127
|
+
#
|
128
|
+
# Returns the current binding for the renderer.
|
129
|
+
#
|
130
|
+
def get_binding
|
131
|
+
binding
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
private
|
136
|
+
|
131
137
|
# call-seq:
|
132
138
|
# next_page => true or false
|
133
139
|
#
|
@@ -149,105 +155,6 @@ class Renderer
|
|
149
155
|
true
|
150
156
|
end
|
151
157
|
|
152
|
-
# Render text via ERB using the built in ERB library.
|
153
|
-
#
|
154
|
-
def erb_filter( str )
|
155
|
-
b = binding
|
156
|
-
ERB.new(str, nil, '-').result(b)
|
157
|
-
end
|
158
|
-
|
159
|
-
# Render text via markdown using the BlueCloth library.
|
160
|
-
#
|
161
|
-
def markdown_filter( str )
|
162
|
-
BlueCloth.new(str).to_html
|
163
|
-
rescue NameError => err
|
164
|
-
@log.error 'markdown filter failed (BlueCloth not installed?)'
|
165
|
-
@log.debug err
|
166
|
-
exit
|
167
|
-
end
|
168
|
-
|
169
|
-
# Render text via textile using the RedCloth library.
|
170
|
-
#
|
171
|
-
def textile_filter( str )
|
172
|
-
RedCloth.new(str).to_html
|
173
|
-
rescue NameError => err
|
174
|
-
@log.error 'textile filter failed (RedCloth not installed?)'
|
175
|
-
@log.debug err
|
176
|
-
exit
|
177
|
-
end
|
178
|
-
|
179
|
-
# Render text via the CodeRay syntax highlighter library.
|
180
|
-
#
|
181
|
-
def coderay_filter( str )
|
182
|
-
filters = nil
|
183
|
-
|
184
|
-
if Array === @page.filter
|
185
|
-
idx = @page.filter.index('coderay') + 1
|
186
|
-
filters = @page.filter.slice(idx..-1)
|
187
|
-
end
|
188
|
-
|
189
|
-
Filters::CodeRay.new(str, filters).to_html
|
190
|
-
rescue NameError => err
|
191
|
-
@log.error 'coderay filter failed (CodeRay not installed?)'
|
192
|
-
@log.debug err
|
193
|
-
exit
|
194
|
-
end
|
195
|
-
|
196
|
-
# Render text into iamges via the Graphviz programs.
|
197
|
-
#
|
198
|
-
def graphviz_filter( str )
|
199
|
-
filters = nil
|
200
|
-
|
201
|
-
if Array === @page.filter
|
202
|
-
idx = @page.filter.index('graphviz') + 1
|
203
|
-
filters = @page.filter.slice(idx..-1)
|
204
|
-
end
|
205
|
-
|
206
|
-
Filters::Graphviz.new(str, filters).to_html
|
207
|
-
rescue NameError => err
|
208
|
-
@log.error 'graphviz filter failed (Graphviz not installed?)'
|
209
|
-
@log.debug err
|
210
|
-
exit
|
211
|
-
rescue Filters::Graphviz::Error
|
212
|
-
exit
|
213
|
-
end
|
214
|
-
|
215
|
-
# Render html into html/xhtml via the Tidy program
|
216
|
-
#
|
217
|
-
def tidy_filter( str )
|
218
|
-
Filters::Tidy.new(str).process
|
219
|
-
rescue NameError => err
|
220
|
-
@log.error 'tidy filter failed (Tidy not installed?)'
|
221
|
-
@log.debug err
|
222
|
-
exit
|
223
|
-
rescue Filters::Tidy::Error
|
224
|
-
exit
|
225
|
-
end
|
226
|
-
|
227
|
-
# Render text via the Haml library
|
228
|
-
#
|
229
|
-
def haml_filter( str )
|
230
|
-
opts = @page.haml_options || {}
|
231
|
-
opts[:locals] ||= {}
|
232
|
-
opts[:locals].merge!({:page => @page, :pages => @pages})
|
233
|
-
Haml::Engine.new(str, opts).to_html
|
234
|
-
rescue NameError => err
|
235
|
-
@log.error 'haml filter failed (Haml not installed?)'
|
236
|
-
@log.debug err
|
237
|
-
exit
|
238
|
-
end
|
239
|
-
|
240
|
-
# Render text via the Sass library (part of Haml)
|
241
|
-
#
|
242
|
-
def sass_filter( str )
|
243
|
-
opts = @page.sass_options || {}
|
244
|
-
Sass::Engine.new(str, opts).render
|
245
|
-
rescue NameError => err
|
246
|
-
@log.error 'sass filter failed (Haml not installed?)'
|
247
|
-
@log.debug err
|
248
|
-
exit
|
249
|
-
end
|
250
|
-
|
251
158
|
end # class Renderer
|
252
159
|
end # module Webby
|
253
160
|
|