/
rspec_extras.rb
147 lines (128 loc) · 3.84 KB
/
rspec_extras.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
module Webby
module Resources
class DB
def immediate_children( page, opts = {} )
root = page.dir == "" ? "" : "#{page.dir}/"
rgxp = Regexp.new "\\A#{root}[^/]+$"
keys = @db.keys.find_all {|k| rgxp =~ k}
ary = keys.map {|k| @db[k]}
ary.flatten!
return ary unless opts.has_key? :sort_by
m = opts[:sort_by]
ary.sort! {|a,b| a.__send__(m) <=> b.__send__(m)}
ary.reverse! if opts[:reverse]
ary
end
end
class Resource
def link
"<a href=\"#{url}\">#{title}</a>"
end
def order
(@_meta_data['order'] || 10000).to_i
end
def path_from_root
resources = []
resource = self
while(resource)
resources << resource
resource = Webby::Resources.pages.parent_of(resource)
end
resources.reverse
end
def siblings
Webby::Resources.pages.siblings(self).reject{|p| p.title.nil?}
end
def immediate_children
Webby::Resources.pages.immediate_children(self).reject{|p| p.title.nil?}.select{|p| p.filename == 'index'}
end
end
end
require File.dirname(__FILE__) + '/../../example_rails_app/vendor/plugins/rspec/lib/spec/version'
require File.dirname(__FILE__) + '/../../example_rails_app/vendor/plugins/rspec-rails/lib/spec/rails/version'
class Renderer
def rspec_version
Spec::VERSION::STRING
end
def rspec_rails_version
Spec::Rails::VERSION::STRING
end
def svn_tag
Spec::VERSION::TAG
end
def breadcrumb_menu(page)
'<div class="breadcrumb-menu">' + breadcrumbs(page) + menu(page) + '</div>'
end
def breadcrumbs(page)
b = binding
ERB.new(<<-EOF, nil, '-').result(b)
<div class="breadcrumbs">
<ul>
<% page.path_from_root.each do |p| %>
<% if p != page %>
<li><%= p.link %></li>
<% else %>
<li class="current"><%= p.link %></li>
<% end %>
<% end %>
</ul>
</div>
EOF
end
def menu(page)
pages = if page.filename == 'index'
(page.siblings + page.immediate_children).sort{|a,b| a.order <=> b.order}
else
[]
end
b = binding
ERB.new(<<-EOF, nil, '-').result(b)
<div class="menu">
<ul>
<% pages.each do |p| %>
<li>
<%= p.link %>
</li>
<% end %>
<% if page.url == '/community' %>
<li>
<a href="http://wiki.github.com/dchelimsky/rspec/get-in-touch" target="_blank">Get in Touch</a>
</li>
<li>
<a href="http://wiki.github.com/dchelimsky/rspec/contribute" target="_blank">Contribute</a>
</li>
<% end %>
<% if page.url == '/documentation' %>
<li>
<a href="http://github.com/dchelimsky/rspec/wikis/home" target="_blank">Install</a>
</li>
<li>
<a href="http://rspec.rubyforge.org/rspec/#{rspec_version}" target="_blank">RDoc</a>
</li>
<% end %>
<% if page.url == '/rails' -%>
<li>
<a href="http://github.com/dchelimsky/rspec-rails/wikis/home" target="_blank">Install</a>
</li>
<li>
<a href="http://rspec.rubyforge.org/rspec-rails/#{rspec_version}" target="_blank">RDoc</a>
</li>
<% end -%>
</ul>
</div>
EOF
end
end
end
# This patches a bug in webby-0.8.2 in which the coderay method fails to add a
# newline resulting in webby formatting problems.
module Webby::Helpers::CodeRayHelper
alias :orig_coderay :coderay
def coderay( *args, &block )
orig_coderay *args, &block
buffer = eval('_erbout', block.binding)
pos = buffer.length
buffer[pos..-1] = "\n"
return
end
end