Pimki 1.7.092 → 1.8.092
Sign up to get free protection for your applications and to get access to all the features.
- data/README-PIMKI +182 -178
- data/app/controllers/wiki.rb +950 -942
- data/app/models/chunks/category.rb +33 -33
- data/app/models/chunks/category_test.rb +21 -21
- data/app/models/chunks/chunk.rb +20 -20
- data/app/models/chunks/engines.rb +48 -48
- data/app/models/chunks/include.rb +1 -1
- data/app/models/chunks/match.rb +1 -1
- data/app/models/chunks/nowiki.rb +1 -1
- data/app/models/chunks/nowiki_test.rb +5 -0
- data/app/models/chunks/todo.rb +1 -0
- data/app/models/chunks/wiki.rb +130 -130
- data/app/models/page.rb +124 -124
- data/app/models/revision.rb +92 -92
- data/app/models/web.rb +314 -316
- data/app/models/wiki_content.rb +2 -2
- data/app/models/wiki_service.rb +170 -166
- data/app/models/wiki_words.rb +28 -28
- data/app/views/error.rhtml +37 -37
- data/app/views/navigation.rhtml +1 -1
- data/app/views/static_style_sheet.rhtml +10 -5
- data/app/views/top.rhtml +1 -1
- data/app/views/wiki/adv_search.rhtml +61 -61
- data/app/views/wiki/bliki.rhtml +7 -6
- data/app/views/wiki/bliki_edit.rhtml +26 -37
- data/app/views/wiki/bliki_new.rhtml +58 -64
- data/app/views/wiki/bliki_revision.rhtml +5 -3
- data/app/views/wiki/edit.rhtml +44 -44
- data/app/views/wiki/edit_menu.rhtml +26 -19
- data/app/views/wiki/edit_web.rhtml +303 -305
- data/app/views/wiki/glossary.rhtml +35 -27
- data/app/views/wiki/list.rhtml +175 -174
- data/app/views/wiki/list.rhtml.bak +175 -0
- data/app/views/wiki/mind.rhtml +70 -70
- data/app/views/wiki/new.rhtml +34 -32
- data/app/views/wiki/published.rhtml +34 -49
- data/app/views/wiki/revision.rhtml +88 -87
- data/app/views/wiki/rollback.rhtml +36 -35
- data/app/views/wiki/todo.rhtml +2 -2
- data/app/views/wiki_words_help.rhtml +8 -8
- data/libraries/action_controller_servlet.rb +202 -202
- data/libraries/madeleine_service.rb +162 -162
- data/pimki.rb +181 -181
- metadata +11 -12
- data/README +0 -172
- data/app/models/chunks/acronym.rb +0 -19
- data/app/views/wiki/test.rhtml +0 -25
- data/libraries/secure_web_controller_server.rb +0 -106
@@ -1,35 +1,36 @@
|
|
1
|
-
<%
|
2
|
-
@title = "Rollback to #{@page.plain_name} Rev ##{@revision.number}"
|
3
|
-
@content_width =
|
4
|
-
@hide_navigation = true
|
5
|
-
@hide_menu = true
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
<
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
<input type="
|
20
|
-
|
21
|
-
|
22
|
-
</
|
23
|
-
</
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
|
34
|
-
|
35
|
-
|
1
|
+
<%
|
2
|
+
@title = "Rollback to #{@page.plain_name} Rev ##{@revision.number}"
|
3
|
+
@content_width = 810
|
4
|
+
@hide_navigation = true
|
5
|
+
@hide_menu = true
|
6
|
+
@style_additions = "#Content, #Container {width = 820px; padding-left:100px;}"
|
7
|
+
%><%= sub_template "top" %>
|
8
|
+
|
9
|
+
<%= "<p style='color:red'>Please correct the error that caused this error in rendering:<br/><small>#{@params["msg"]}</small></p>" if @params["msg"] %>
|
10
|
+
|
11
|
+
<form id="editForm" action="../save/<%= @page.name %>" method="post" onSubmit="cleanAuthorName();">
|
12
|
+
<p>
|
13
|
+
<textarea name="content" style="font-size: 12px; width: 450px; height: 75%"><%= @revision.content %></textarea>
|
14
|
+
</p>
|
15
|
+
<p>
|
16
|
+
<% if @web.check_pass_on_edit %>
|
17
|
+
<p>Please enter edit password: <input type="password" name="password" id="password"></p>
|
18
|
+
<% end %>
|
19
|
+
<input type="submit" value="Update"> as
|
20
|
+
<input type="text" name="author" id="authorName" value="<%= @author %>"
|
21
|
+
onClick="this.value == 'AnonymousCoward' ? this.value = '' : true">
|
22
|
+
| <a href="../cancel_edit/<%= @page.name %>">Cancel</a> <small>(unlocks page)</small>
|
23
|
+
</p>
|
24
|
+
</form>
|
25
|
+
|
26
|
+
<%= render_markup_help %>
|
27
|
+
|
28
|
+
<script language="JavaScript1.2">
|
29
|
+
function cleanAuthorName() {
|
30
|
+
if (document.getElementById('authorName').value == "") {
|
31
|
+
document.getElementById('authorName').value = 'AnonymousCoward';
|
32
|
+
}
|
33
|
+
}
|
34
|
+
</script>
|
35
|
+
|
36
|
+
<%= sub_template "bottom" %>
|
data/app/views/wiki/todo.rhtml
CHANGED
@@ -51,8 +51,8 @@
|
|
51
51
|
<% items.each do |item| %>
|
52
52
|
<li>
|
53
53
|
<small><%=
|
54
|
-
x = "[#{item.context.join(', ') unless item.context.empty?}#{ " - " unless item.context.empty? or item.due_date == FAR_FUTURE}#{item.due_date unless item.due_date == FAR_FUTURE }]
|
55
|
-
x unless x == "[]
|
54
|
+
x = "[#{item.context.join(', ') unless item.context.empty?}#{ " - " unless item.context.empty? or item.due_date == FAR_FUTURE}#{item.due_date unless item.due_date == FAR_FUTURE }]"
|
55
|
+
x unless x == "[]"
|
56
56
|
%></small>
|
57
57
|
<span class="<%= get_todo_display_style item.due_date %>"><%= item.text.strip %></span>
|
58
58
|
</li>
|
@@ -1,8 +1,8 @@
|
|
1
|
-
<h3>Wiki words</h3>
|
2
|
-
<p style="border-top: 1px dotted #ccc; margin-top: 0px">
|
3
|
-
Two or more uppercase words stuck together (camel case) or any phrase surrounded by double brackets is a wiki word. A camel-case wiki word can be escaped by putting \ in front of it.
|
4
|
-
</p>
|
5
|
-
<p>
|
6
|
-
Wiki words: <i>HomePage, ThreeWordsTogether, [[C++]], [[Let's play again!]]</i><br/>
|
7
|
-
Not wiki words: <i>IBM, School</i>
|
8
|
-
</p>
|
1
|
+
<h3>Wiki words</h3>
|
2
|
+
<p style="border-top: 1px dotted #ccc; margin-top: 0px">
|
3
|
+
Two or more uppercase words stuck together (camel case) or any phrase surrounded by double brackets is a wiki word. A camel-case wiki word can be escaped by putting \ in front of it.
|
4
|
+
</p>
|
5
|
+
<p>
|
6
|
+
Wiki words: <i>HomePage, ThreeWordsTogether, [[C++]], [[Let's play again!]]</i><br/>
|
7
|
+
Not wiki words: <i>IBM, School</i>
|
8
|
+
</p>
|
@@ -1,203 +1,203 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'cgi'
|
3
|
-
require 'webrick'
|
4
|
-
include WEBrick
|
5
|
-
|
6
|
-
require 'view_helper'
|
7
|
-
|
8
|
-
class FavIconHandler < HTTPServlet::AbstractServlet
|
9
|
-
LOCAL_PATH = File.join(File.dirname(__FILE__), '../favicon.png')
|
10
|
-
ICO_FILE = File.open(LOCAL_PATH, "rb") { |f| f.read }
|
11
|
-
def do_GET(req, res)
|
12
|
-
res['content-type'] = 'image/png'
|
13
|
-
res.body = ICO_FILE
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class ActionControllerServlet < HTTPServlet::AbstractServlet
|
18
|
-
@@template_root = "./views"
|
19
|
-
def self.template_root() @@template_root end
|
20
|
-
def self.template_root=(template_root) @@template_root = template_root end
|
21
|
-
|
22
|
-
include ViewHelper
|
23
|
-
|
24
|
-
def do_POST(req, res) do_GET(req, res) end
|
25
|
-
|
26
|
-
def do_GET(req, res)
|
27
|
-
@req, @res = req, res
|
28
|
-
|
29
|
-
@res['Content-Type'] = "text/html; charset=utf-8"
|
30
|
-
@res['Pragma'] = "no-cache"
|
31
|
-
@res['Cache-Control'] = "no-cache"
|
32
|
-
|
33
|
-
@params = @req.query
|
34
|
-
@assigns = {}
|
35
|
-
@performed_render = @performed_redirect = false
|
36
|
-
|
37
|
-
@logger.info "Performing #{action_name} (#{request_path.join('/')})"
|
38
|
-
@logger.info " Parameters: #{@params.inspect}"
|
39
|
-
@logger.info " Cookies: #{@req.cookies.collect { |c| "#{c.name} => #{c.value}" }.join(", ") }"
|
40
|
-
|
41
|
-
perform_action
|
42
|
-
@res
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
def template_root() self.class.template_root end
|
47
|
-
|
48
|
-
# Issues a HTTP 302 (location) redirect to the specified <tt>path</tt>. Query string
|
49
|
-
# parameters can be specified in the <tt>params</tt> hash and are automatically URL escaped.
|
50
|
-
# An <tt>anchor</tt> can also be specified (as a string).
|
51
|
-
def redirect_path(path, params = nil, anchor = nil)
|
52
|
-
path << build_query_string(params) unless params.nil?
|
53
|
-
path << "\##{anchor}" unless anchor.nil?
|
54
|
-
@res.set_redirect WEBrick::HTTPStatus::MovedPermanently, path
|
55
|
-
@performed_redirect = true
|
56
|
-
end
|
57
|
-
|
58
|
-
# Redirects the browser to another action within the current controller, so redirect_path "pages"
|
59
|
-
# within a controller called WikiController would take the user to "http://www.example.com/wiki/pages"
|
60
|
-
def redirect_action(action, params = nil, anchor = nil)
|
61
|
-
redirect_path "/#{controller_name}/#{action}", params, anchor
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
# Compiles the template response and adds it to the response. If no template_name has been
|
66
|
-
# supplied, the action parameter parsed to the controller is used. So invoking
|
67
|
-
# render on a object initialized with myController.new("show_person") will compile the template
|
68
|
-
# located at "../views/show_person.rhtml". Notice that the ".rhtml" extension is postfixed
|
69
|
-
# to the template_name regardless of one was passed or that the action parameter was used.
|
70
|
-
def render(template_name = "#{controller_name}/#{action_name}")
|
71
|
-
@performed_render = true
|
72
|
-
@logger.info "Rendering: #{template_name}"
|
73
|
-
add_instance_variables_to_assigns
|
74
|
-
@res.body = template_result "#{template_root}/#{template_name}.rhtml"
|
75
|
-
end
|
76
|
-
|
77
|
-
def render_text(text)
|
78
|
-
@performed_render = true
|
79
|
-
@logger.info "Rendering in text"
|
80
|
-
@res.body = text
|
81
|
-
end
|
82
|
-
|
83
|
-
# Wrapper around render that presumes the current controller is used as a base for the action,
|
84
|
-
# so render_action("page") in WikiController will be equal to render("wiki/page")
|
85
|
-
def render_action(action_name)
|
86
|
-
render "#{controller_name}/#{action_name}"
|
87
|
-
end
|
88
|
-
|
89
|
-
def sub_template(template_name)
|
90
|
-
template_result "#{template_root}/#{template_name}.rhtml"
|
91
|
-
end
|
92
|
-
|
93
|
-
# Returns the value of the cookie matching +name+ (or nil if none is found).
|
94
|
-
def read_cookie(key)
|
95
|
-
cookies = @req.cookies.select { |cookie| cookie.name == key }
|
96
|
-
cookies.empty? ? nil : cookies.first.value
|
97
|
-
end
|
98
|
-
|
99
|
-
def write_cookie(key, value, permanent = false)
|
100
|
-
@logger.info "Writing cookie: #{key} => #{value}"
|
101
|
-
|
102
|
-
cookie = WEBrick::Cookie.new(key, value)
|
103
|
-
cookie.path = "/"
|
104
|
-
cookie.expires = Time.local(2030) if permanent
|
105
|
-
@res.cookies << cookie
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
# Returns the last part of the uri path ("page" in "/wiki/page") by default, but
|
110
|
-
# can be overwritten to implement mod_rewrite-like behaviour, such as "page" in "/wiki/page/home"
|
111
|
-
def action_name
|
112
|
-
@req.path.to_s.split(/\//).last
|
113
|
-
end
|
114
|
-
|
115
|
-
# Returns an array with each of the parts in the request as an element. So /something/cool/dude
|
116
|
-
# returns ["something", "cool", "dude"]
|
117
|
-
def request_path
|
118
|
-
request_path_parts = @req.path.to_s.split(/\//)
|
119
|
-
request_path_parts.length > 1 ? request_path_parts[1..-1] : []
|
120
|
-
end
|
121
|
-
|
122
|
-
# Can be overwritten by a controller class to implement shared behaviour for all the actions in
|
123
|
-
# the class, such as security measures
|
124
|
-
def before_action() end
|
125
|
-
|
126
|
-
|
127
|
-
private
|
128
|
-
# Wraps around all action calls to ensure the session is properly updated and closed.
|
129
|
-
# Figures out whether an action, such as "list", is implemented as show_list or do_list.
|
130
|
-
# The show_* type has precedence and automatically calls render after execution.
|
131
|
-
def perform_action
|
132
|
-
if before_action == false then return end
|
133
|
-
|
134
|
-
if action_methods.include?(action_name)
|
135
|
-
send(action_name)
|
136
|
-
render unless @performed_render || @performed_redirect || !@res.body.empty?
|
137
|
-
elsif template_exists_for_action
|
138
|
-
render
|
139
|
-
else
|
140
|
-
raise RuntimeError, "No action responded to #{action_name}", caller
|
141
|
-
end
|
142
|
-
|
143
|
-
rescue Exception => details
|
144
|
-
raise if ['WEBrick', 'Net'].include? details.class.name.split('::')[0]
|
145
|
-
@error_details = details
|
146
|
-
render 'error'
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
def add_instance_variables_to_assigns
|
151
|
-
instance_variables.each { |var|
|
152
|
-
next if protected_instance_variables.include?(var)
|
153
|
-
@assigns[var[1..-1]] = instance_variable_get(var)
|
154
|
-
}
|
155
|
-
end
|
156
|
-
|
157
|
-
def protected_instance_variables
|
158
|
-
[ "@assigns", "@performed_redirect", "@performed_render" ]
|
159
|
-
end
|
160
|
-
|
161
|
-
def action_methods
|
162
|
-
methods - Object.instance_methods
|
163
|
-
end
|
164
|
-
|
165
|
-
# Returns true if a template exists in the controller directory for the specified <tt>action_name</tt>,
|
166
|
-
# which would mean true if called for WikiController#changes and "/views/wiki/changes.rhtml" existed.
|
167
|
-
def template_exists_for_action
|
168
|
-
File.exist? action_template_path
|
169
|
-
end
|
170
|
-
|
171
|
-
def action_template_path(action = action_name)
|
172
|
-
"#{template_root}/#{controller_name}/#{action}.rhtml"
|
173
|
-
end
|
174
|
-
|
175
|
-
def template_result(template_path)
|
176
|
-
@assigns.each { |key, value| instance_variable_set "@#{key}", value }
|
177
|
-
begin
|
178
|
-
ERB.new(IO.readlines(template_path).join).result(binding)
|
179
|
-
rescue Exception => detail
|
180
|
-
@logger.error "Error processing #{template_path}"
|
181
|
-
line = /:(\d+):/.match(detail.backtrace[0]).captures[0].to_i - 172
|
182
|
-
@logger.error "On Line: #{line}"
|
183
|
-
@logger.error detail
|
184
|
-
src = ERB.new(IO.readlines(template_path).join).src
|
185
|
-
lines = src.split("\n")[(line-1)..(line+1)]
|
186
|
-
@logger.error "\n\n" + lines.join("\n\n") + "\n\n"
|
187
|
-
raise
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
# Converts the class name from something like "OneModule::TwoModule::NeatController"
|
192
|
-
# to "neat".
|
193
|
-
def controller_name
|
194
|
-
self.class.to_s.split("::").last.sub(/Controller/, "").downcase
|
195
|
-
end
|
196
|
-
|
197
|
-
# Returns a query string with escaped keys and values from the passed hash.
|
198
|
-
def build_query_string(hash)
|
199
|
-
elements = []
|
200
|
-
hash.each { |key, value| elements << "#{CGI.escape(key)}=#{CGI.escape(value.to_s)}" }
|
201
|
-
"?" + elements.join("&")
|
202
|
-
end
|
1
|
+
require 'erb'
|
2
|
+
require 'cgi'
|
3
|
+
require 'webrick'
|
4
|
+
include WEBrick
|
5
|
+
|
6
|
+
require 'view_helper'
|
7
|
+
|
8
|
+
class FavIconHandler < HTTPServlet::AbstractServlet
|
9
|
+
LOCAL_PATH = File.join(File.dirname(__FILE__), '../favicon.png')
|
10
|
+
ICO_FILE = File.open(LOCAL_PATH, "rb") { |f| f.read }
|
11
|
+
def do_GET(req, res)
|
12
|
+
res['content-type'] = 'image/png'
|
13
|
+
res.body = ICO_FILE
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class ActionControllerServlet < HTTPServlet::AbstractServlet
|
18
|
+
@@template_root = "./views"
|
19
|
+
def self.template_root() @@template_root end
|
20
|
+
def self.template_root=(template_root) @@template_root = template_root end
|
21
|
+
|
22
|
+
include ViewHelper
|
23
|
+
|
24
|
+
def do_POST(req, res) do_GET(req, res) end
|
25
|
+
|
26
|
+
def do_GET(req, res)
|
27
|
+
@req, @res = req, res
|
28
|
+
|
29
|
+
@res['Content-Type'] = "text/html; charset=utf-8"
|
30
|
+
@res['Pragma'] = "no-cache"
|
31
|
+
@res['Cache-Control'] = "no-cache"
|
32
|
+
|
33
|
+
@params = @req.query
|
34
|
+
@assigns = {}
|
35
|
+
@performed_render = @performed_redirect = false
|
36
|
+
|
37
|
+
@logger.info "Performing #{action_name} (#{request_path.join('/')})"
|
38
|
+
@logger.info " Parameters: #{@params.inspect}"
|
39
|
+
@logger.info " Cookies: #{@req.cookies.collect { |c| "#{c.name} => #{c.value}" }.join(", ") }"
|
40
|
+
|
41
|
+
perform_action
|
42
|
+
@res
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
def template_root() self.class.template_root end
|
47
|
+
|
48
|
+
# Issues a HTTP 302 (location) redirect to the specified <tt>path</tt>. Query string
|
49
|
+
# parameters can be specified in the <tt>params</tt> hash and are automatically URL escaped.
|
50
|
+
# An <tt>anchor</tt> can also be specified (as a string).
|
51
|
+
def redirect_path(path, params = nil, anchor = nil)
|
52
|
+
path << build_query_string(params) unless params.nil?
|
53
|
+
path << "\##{anchor}" unless anchor.nil?
|
54
|
+
@res.set_redirect WEBrick::HTTPStatus::MovedPermanently, path
|
55
|
+
@performed_redirect = true
|
56
|
+
end
|
57
|
+
|
58
|
+
# Redirects the browser to another action within the current controller, so redirect_path "pages"
|
59
|
+
# within a controller called WikiController would take the user to "http://www.example.com/wiki/pages"
|
60
|
+
def redirect_action(action, params = nil, anchor = nil)
|
61
|
+
redirect_path "/#{controller_name}/#{action}", params, anchor
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
# Compiles the template response and adds it to the response. If no template_name has been
|
66
|
+
# supplied, the action parameter parsed to the controller is used. So invoking
|
67
|
+
# render on a object initialized with myController.new("show_person") will compile the template
|
68
|
+
# located at "../views/show_person.rhtml". Notice that the ".rhtml" extension is postfixed
|
69
|
+
# to the template_name regardless of one was passed or that the action parameter was used.
|
70
|
+
def render(template_name = "#{controller_name}/#{action_name}")
|
71
|
+
@performed_render = true
|
72
|
+
@logger.info "Rendering: #{template_name}"
|
73
|
+
add_instance_variables_to_assigns
|
74
|
+
@res.body = template_result "#{template_root}/#{template_name}.rhtml"
|
75
|
+
end
|
76
|
+
|
77
|
+
def render_text(text)
|
78
|
+
@performed_render = true
|
79
|
+
@logger.info "Rendering in text"
|
80
|
+
@res.body = text
|
81
|
+
end
|
82
|
+
|
83
|
+
# Wrapper around render that presumes the current controller is used as a base for the action,
|
84
|
+
# so render_action("page") in WikiController will be equal to render("wiki/page")
|
85
|
+
def render_action(action_name)
|
86
|
+
render "#{controller_name}/#{action_name}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def sub_template(template_name)
|
90
|
+
template_result "#{template_root}/#{template_name}.rhtml"
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns the value of the cookie matching +name+ (or nil if none is found).
|
94
|
+
def read_cookie(key)
|
95
|
+
cookies = @req.cookies.select { |cookie| cookie.name == key }
|
96
|
+
cookies.empty? ? nil : cookies.first.value
|
97
|
+
end
|
98
|
+
|
99
|
+
def write_cookie(key, value, permanent = false)
|
100
|
+
@logger.info "Writing cookie: #{key} => #{value}"
|
101
|
+
|
102
|
+
cookie = WEBrick::Cookie.new(key, value)
|
103
|
+
cookie.path = "/"
|
104
|
+
cookie.expires = Time.local(2030) if permanent
|
105
|
+
@res.cookies << cookie
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
# Returns the last part of the uri path ("page" in "/wiki/page") by default, but
|
110
|
+
# can be overwritten to implement mod_rewrite-like behaviour, such as "page" in "/wiki/page/home"
|
111
|
+
def action_name
|
112
|
+
@req.path.to_s.split(/\//).last
|
113
|
+
end
|
114
|
+
|
115
|
+
# Returns an array with each of the parts in the request as an element. So /something/cool/dude
|
116
|
+
# returns ["something", "cool", "dude"]
|
117
|
+
def request_path
|
118
|
+
request_path_parts = @req.path.to_s.split(/\//)
|
119
|
+
request_path_parts.length > 1 ? request_path_parts[1..-1] : []
|
120
|
+
end
|
121
|
+
|
122
|
+
# Can be overwritten by a controller class to implement shared behaviour for all the actions in
|
123
|
+
# the class, such as security measures
|
124
|
+
def before_action() end
|
125
|
+
|
126
|
+
|
127
|
+
private
|
128
|
+
# Wraps around all action calls to ensure the session is properly updated and closed.
|
129
|
+
# Figures out whether an action, such as "list", is implemented as show_list or do_list.
|
130
|
+
# The show_* type has precedence and automatically calls render after execution.
|
131
|
+
def perform_action
|
132
|
+
if before_action == false then return end
|
133
|
+
|
134
|
+
if action_methods.include?(action_name)
|
135
|
+
send(action_name)
|
136
|
+
render unless @performed_render || @performed_redirect || !@res.body.empty?
|
137
|
+
elsif template_exists_for_action
|
138
|
+
render
|
139
|
+
else
|
140
|
+
raise RuntimeError, "No action responded to #{action_name}", caller
|
141
|
+
end
|
142
|
+
|
143
|
+
rescue Exception => details
|
144
|
+
raise if ['WEBrick', 'Net'].include? details.class.name.split('::')[0]
|
145
|
+
@error_details = details
|
146
|
+
render 'error'
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
def add_instance_variables_to_assigns
|
151
|
+
instance_variables.each { |var|
|
152
|
+
next if protected_instance_variables.include?(var)
|
153
|
+
@assigns[var[1..-1]] = instance_variable_get(var)
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
def protected_instance_variables
|
158
|
+
[ "@assigns", "@performed_redirect", "@performed_render" ]
|
159
|
+
end
|
160
|
+
|
161
|
+
def action_methods
|
162
|
+
methods - Object.instance_methods
|
163
|
+
end
|
164
|
+
|
165
|
+
# Returns true if a template exists in the controller directory for the specified <tt>action_name</tt>,
|
166
|
+
# which would mean true if called for WikiController#changes and "/views/wiki/changes.rhtml" existed.
|
167
|
+
def template_exists_for_action
|
168
|
+
File.exist? action_template_path
|
169
|
+
end
|
170
|
+
|
171
|
+
def action_template_path(action = action_name)
|
172
|
+
"#{template_root}/#{controller_name}/#{action}.rhtml"
|
173
|
+
end
|
174
|
+
|
175
|
+
def template_result(template_path)
|
176
|
+
@assigns.each { |key, value| instance_variable_set "@#{key}", value }
|
177
|
+
begin
|
178
|
+
ERB.new(IO.readlines(template_path).join).result(binding)
|
179
|
+
rescue Exception => detail
|
180
|
+
@logger.error "Error processing #{template_path}"
|
181
|
+
line = /:(\d+):/.match(detail.backtrace[0]).captures[0].to_i - 172
|
182
|
+
@logger.error "On Line: #{line}"
|
183
|
+
@logger.error detail
|
184
|
+
src = ERB.new(IO.readlines(template_path).join).src
|
185
|
+
lines = src.split("\n")[(line-1)..(line+1)]
|
186
|
+
@logger.error "\n\n" + lines.join("\n\n") + "\n\n"
|
187
|
+
raise
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# Converts the class name from something like "OneModule::TwoModule::NeatController"
|
192
|
+
# to "neat".
|
193
|
+
def controller_name
|
194
|
+
self.class.to_s.split("::").last.sub(/Controller/, "").downcase
|
195
|
+
end
|
196
|
+
|
197
|
+
# Returns a query string with escaped keys and values from the passed hash.
|
198
|
+
def build_query_string(hash)
|
199
|
+
elements = []
|
200
|
+
hash.each { |key, value| elements << "#{CGI.escape(key)}=#{CGI.escape(value.to_s)}" }
|
201
|
+
"?" + elements.join("&")
|
202
|
+
end
|
203
203
|
end
|