merb 0.0.4 → 0.0.5
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.
- data/README +41 -2
- data/Rakefile +4 -2
- data/TODO +3 -3
- data/bin/merb +157 -3
- data/doc/rdoc/classes/Hash.html +4 -4
- data/doc/rdoc/classes/Merb.html +2 -12
- data/doc/rdoc/classes/Merb/Controller.html +347 -156
- data/doc/rdoc/classes/Merb/RouteMatcher.html +93 -59
- data/doc/rdoc/classes/MerbHandler.html +117 -107
- data/doc/rdoc/classes/MerbHash.html +64 -58
- data/doc/rdoc/classes/Noroutefound.html +16 -10
- data/doc/rdoc/classes/Object.html +5 -5
- data/doc/rdoc/classes/String.html +28 -16
- data/doc/rdoc/classes/Symbol.html +15 -8
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +56 -4
- data/doc/rdoc/files/TODO.html +4 -4
- data/doc/rdoc/files/lib/merb/merb_controller_rb.html +1 -1
- data/doc/rdoc/files/lib/merb/merb_handler_rb.html +1 -1
- data/doc/rdoc/files/lib/merb/merb_router_rb.html +1 -1
- data/doc/rdoc/files/lib/merb/merb_utils_rb.html +1 -1
- data/doc/rdoc/files/lib/merb_rb.html +30 -2
- data/doc/rdoc/files/lib/{merb_config_rb.html → merb_tasks_rb.html} +4 -4
- data/doc/rdoc/fr_class_index.html +0 -2
- data/doc/rdoc/fr_file_index.html +1 -3
- data/doc/rdoc/fr_method_index.html +21 -21
- data/examples/app_skeleton/Rakefile +81 -0
- data/examples/app_skeleton/dist/conf/merb_init.rb +15 -0
- data/examples/{skeleton → app_skeleton}/dist/conf/router.rb +5 -7
- data/examples/app_skeleton/scripts/merb_stop +5 -0
- data/examples/app_skeleton/scripts/new_migration +21 -0
- data/examples/{skeleton → app_skeleton}/test/test_helper.rb +0 -0
- data/examples/sample_app/Rakefile +81 -0
- data/examples/sample_app/dist/app/controllers/posts.rb +26 -10
- data/examples/sample_app/dist/app/models/comment.rb +3 -0
- data/examples/sample_app/dist/app/models/post.rb +2 -11
- data/examples/sample_app/dist/app/views/layout/application.rhtml +59 -4
- data/examples/sample_app/dist/app/views/posts/_comments.rhtml +11 -0
- data/examples/sample_app/dist/app/views/posts/comment.merbjs +1 -0
- data/examples/sample_app/dist/app/views/posts/list.rhtml +2 -4
- data/examples/sample_app/dist/app/views/posts/new.rhtml +2 -2
- data/examples/sample_app/dist/app/views/posts/show.rhtml +35 -3
- data/examples/sample_app/dist/conf/merb_init.rb +2 -4
- data/examples/sample_app/dist/conf/router.rb +3 -4
- data/examples/sample_app/dist/public/images/bg.jpg +0 -0
- data/examples/sample_app/dist/public/images/book.gif +0 -0
- data/examples/sample_app/dist/public/images/booksmall.gif +0 -0
- data/examples/sample_app/dist/public/images/greenright.jpg +0 -0
- data/examples/sample_app/dist/public/images/louiecon.gif +0 -0
- data/examples/sample_app/dist/public/images/menu.gif +0 -0
- data/examples/sample_app/dist/public/images/menuleft.gif +0 -0
- data/examples/sample_app/dist/public/images/menuright.gif +0 -0
- data/examples/sample_app/dist/public/images/mountain.jpg +0 -0
- data/examples/sample_app/dist/public/images/n3.jpg +0 -0
- data/examples/sample_app/dist/public/images/nautica.jpg +0 -0
- data/examples/sample_app/dist/public/javascripts/application.js +0 -0
- data/examples/sample_app/dist/public/javascripts/effects.js +975 -0
- data/examples/sample_app/dist/public/javascripts/prototype.js +2264 -0
- data/examples/sample_app/dist/public/stylesheets/merb.css +277 -0
- data/examples/sample_app/dist/schema/migrations/001_add_comments_to_posts.rb +22 -0
- data/examples/sample_app/dist/schema/schema.rb +22 -0
- data/examples/sample_app/log/merb.log +164394 -0
- data/examples/sample_app/script/merb_stop +9 -0
- data/examples/sample_app/script/new_migration +21 -0
- data/lib/merb.rb +7 -4
- data/lib/merb/merb_controller.rb +83 -4
- data/lib/merb/merb_handler.rb +20 -9
- data/lib/merb/merb_router.rb +18 -1
- data/lib/merb/merb_utils.rb +11 -1
- data/lib/merb_tasks.rb +7 -0
- data/lib/tasks/db.rake +53 -0
- metadata +67 -34
- data/doc/rdoc/classes/Merb/Config.html +0 -161
- data/doc/rdoc/classes/Merb/Server.html +0 -288
- data/doc/rdoc/files/lib/merb/merb_daemon_rb.html +0 -113
- data/doc/rdoc/files/lib/merb/noroutefound_rb.html +0 -101
- data/examples/sample_app/dist/app/views/layout/posts.rhtml +0 -6
- data/examples/skeleton/dist/conf/merb_init.rb +0 -21
- data/lib/merb/merb_daemon.rb +0 -91
- data/lib/merb/noroutefound.rb +0 -11
- data/lib/merb_config.rb +0 -21
data/README
CHANGED
@@ -29,7 +29,7 @@ including multipart uploads and post as well as ?query=strings. Puts the
|
|
29
29
|
params into params and the cookies into cookies when it instantiates your
|
30
30
|
controller class.
|
31
31
|
|
32
|
-
2.
|
32
|
+
2. RouteMatcher and route compiler. Reads your route definition and compiles
|
33
33
|
a method on the fly that will match the request path against each route and do the
|
34
34
|
right thing. So the following routes:
|
35
35
|
|
@@ -93,6 +93,34 @@ end
|
|
93
93
|
<h1>Hello, <%= @name %>!</h1>
|
94
94
|
<% end %>
|
95
95
|
|
96
|
+
You can also render partials like so:
|
97
|
+
<%= partial(:comments) %>
|
98
|
+
|
99
|
+
This assumes a _comments.rhtml file in the same view dir as the current
|
100
|
+
controller/view
|
101
|
+
|
102
|
+
Merb also allows for returning javascript instead of html for ajax actions
|
103
|
+
You have to use the render_js instead of normal render
|
104
|
+
|
105
|
+
def ajax_action
|
106
|
+
@posts = Post.find :all
|
107
|
+
render_js
|
108
|
+
end
|
109
|
+
|
110
|
+
# ajax_action.merbjs
|
111
|
+
$('comments').update('<%= escape_js(partial(:posts)) %>');
|
112
|
+
|
113
|
+
# _posts.rhtml
|
114
|
+
<ul>
|
115
|
+
<% @posts.each do |p| %>
|
116
|
+
<li>
|
117
|
+
<%= p.title %><br />
|
118
|
+
<%= p.body %>
|
119
|
+
</li>
|
120
|
+
<% end %>
|
121
|
+
</ul>
|
122
|
+
|
123
|
+
|
96
124
|
|
97
125
|
4. the server. right now you add your routes in
|
98
126
|
the appdir/conf/router.rb file. So by default it runs on port 4000
|
@@ -100,6 +128,15 @@ the appdir/conf/router.rb file. So by default it runs on port 4000
|
|
100
128
|
$ cd /path/to/your/merb/app
|
101
129
|
$ merb
|
102
130
|
|
131
|
+
Or to start merb on a different port:
|
132
|
+
$ merb -p 3500
|
133
|
+
|
134
|
+
To start a cluster of merb servers you specify the first port and then how many
|
135
|
+
servers you want spawned. SO this command will start a merb instance on ports
|
136
|
+
3000, 3001, 3002
|
137
|
+
|
138
|
+
$ merb -p 3000 -c 3
|
139
|
+
|
103
140
|
5. File uploads. This is the thing that Merb was written for. Rails doesn't allow
|
104
141
|
multiple concurrent file uploads at once without blocking an entire rails backend
|
105
142
|
for each file upload. Merb allows multiple file uploads at once. Start the server
|
@@ -125,11 +162,12 @@ and DIST_ROOT. MERB_ROOT is the root of the whole tree. And DISTROOT is MERB_ROO
|
|
125
162
|
You will cd into MERB_ROOT to run the merb command line. ANd when you deploy live you
|
126
163
|
will put the dist dir into another empty MERB_ROOT on the production server.
|
127
164
|
|
128
|
-
|
165
|
+
app_skeleton
|
129
166
|
Rakefile
|
130
167
|
README
|
131
168
|
scripts
|
132
169
|
test
|
170
|
+
test_helper.rb
|
133
171
|
fixtures
|
134
172
|
spec
|
135
173
|
unit
|
@@ -143,3 +181,4 @@ skeleton_app
|
|
143
181
|
lib
|
144
182
|
public
|
145
183
|
plugins
|
184
|
+
schema
|
data/Rakefile
CHANGED
@@ -3,11 +3,12 @@ require 'rake/clean'
|
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
require 'rake/rdoctask'
|
5
5
|
require 'rake/testtask'
|
6
|
+
require 'code_statistics'
|
6
7
|
require 'fileutils'
|
7
8
|
include FileUtils
|
8
9
|
|
9
10
|
NAME = "merb"
|
10
|
-
VERS = "0.0.
|
11
|
+
VERS = "0.0.5"
|
11
12
|
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
12
13
|
RDOC_OPTS = ['--quiet', '--title', "Merb Documentation",
|
13
14
|
"--opname", "index.html",
|
@@ -68,6 +69,7 @@ task :uninstall => [:clean] do
|
|
68
69
|
sh %{sudo gem uninstall #{NAME}}
|
69
70
|
end
|
70
71
|
|
72
|
+
desc "rdoc to rubyforge"
|
71
73
|
task :doc_rforge do
|
72
74
|
sh %{rake doc}
|
73
75
|
sh %{scp -r -p doc/rdoc/* ezmobius@rubyforge.org:/var/www/gforge-projects/merb}
|
@@ -112,7 +114,7 @@ STATS_DIRECTORIES = [
|
|
112
114
|
|
113
115
|
desc "Report code statistics (KLOCs, etc) from the application"
|
114
116
|
task :stats do
|
115
|
-
require 'extra/stats'
|
117
|
+
#require 'extra/stats'
|
116
118
|
verbose = true
|
117
119
|
CodeStatistics.new(*STATS_DIRECTORIES).to_s
|
118
120
|
end
|
data/TODO
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
[TODO]
|
2
2
|
* Irb Console **DONE**
|
3
|
-
* Migrations
|
3
|
+
* Migrations **DONE**
|
4
4
|
* Helpers
|
5
|
-
* config file
|
5
|
+
* config file **DONE**
|
6
6
|
* merg args and params **DONE**
|
7
7
|
* session
|
8
8
|
** AR
|
@@ -11,7 +11,7 @@
|
|
11
11
|
* Mongoose ?
|
12
12
|
* Text backend?
|
13
13
|
* plugins support(rails plugins too?)
|
14
|
-
* Layouts
|
14
|
+
* Layouts **DONE**
|
15
15
|
* auto template_dir
|
16
16
|
* before/after filters
|
17
17
|
* merbjs
|
data/bin/merb
CHANGED
@@ -1,7 +1,161 @@
|
|
1
1
|
#!/usr/local/bin/ruby
|
2
2
|
require 'rubygems'
|
3
3
|
require 'merb'
|
4
|
-
|
5
|
-
require '
|
6
|
-
|
4
|
+
require 'optparse'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'fileutils'
|
7
|
+
module Merb
|
8
|
+
end
|
9
|
+
|
10
|
+
class Merb::Config
|
11
|
+
def self.setup
|
12
|
+
defaults = {
|
13
|
+
:host => "0.0.0.0",
|
14
|
+
:port => "4000",
|
15
|
+
:allow_reloading => true,
|
16
|
+
:merb_root => Dir.pwd
|
17
|
+
}
|
18
|
+
|
19
|
+
begin
|
20
|
+
options = defaults.merge(YAML.load(ERB.new(IO.read("#{defaults[:merb_root]}/dist/conf/merb.yml")).result))
|
21
|
+
rescue
|
22
|
+
options = defaults
|
23
|
+
end
|
24
|
+
|
25
|
+
options
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Merb::Server
|
30
|
+
|
31
|
+
def self.merb_config
|
32
|
+
options = Merb::Config.setup
|
33
|
+
|
34
|
+
opts = OptionParser.new do |opts|
|
35
|
+
opts.on("-f", "--config-file [String]") do |config|
|
36
|
+
options[:config] = config
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-d", "--daemonize [String]") do |config|
|
40
|
+
options[:daemonize] = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("-c", "--cluster-nodes [String]") do |nodes|
|
44
|
+
options[:cluster] = nodes
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("-p", "--port [Integer]") do |port|
|
48
|
+
options[:port] = port
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("-n", "--num-procs [Integer]") do |numprocs|
|
52
|
+
options[:numprocs] = numprocs
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("-h", "--host [String]") do |host|
|
56
|
+
options[:host] = host
|
57
|
+
end
|
58
|
+
|
59
|
+
opts.on("-m", "--merb-root [String]") do |merb_root|
|
60
|
+
options[:merb_root] = File.expand_path(merb_root)
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on("-i", "--irb-console [String]") do |console|
|
64
|
+
options[:console] = true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.parse!(@@merb_raw_opts)
|
69
|
+
|
70
|
+
|
71
|
+
@@merb_opts = options
|
72
|
+
puts %{Merb started with these options:}
|
73
|
+
puts @@merb_opts.to_yaml; puts
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.run
|
77
|
+
@@merb_raw_opts = ARGV
|
78
|
+
merb_config
|
79
|
+
|
80
|
+
@@merb_opts[:dist_root] = @@merb_opts[:merb_root]+'/dist'
|
81
|
+
|
82
|
+
$LOAD_PATH.unshift( File.join(@@merb_opts[:merb_root] , '/dist/app/controllers') )
|
83
|
+
$LOAD_PATH.unshift( File.join(@@merb_opts[:merb_root] , '/dist/lib') )
|
84
|
+
require @@merb_opts[:merb_root]+'/dist/conf/router.rb'
|
85
|
+
require @@merb_opts[:merb_root]+'/dist/conf/merb_init.rb'
|
86
|
+
|
87
|
+
if @@merb_opts[:console]
|
88
|
+
ARGV.clear # Avoid passing args to IRB
|
89
|
+
require 'irb'
|
90
|
+
require 'irb/completion'
|
91
|
+
def exit
|
92
|
+
exit!
|
93
|
+
end
|
94
|
+
if File.exists? ".irbrc"
|
95
|
+
ENV['IRBRC'] = ".irbrc"
|
96
|
+
end
|
97
|
+
IRB.start
|
98
|
+
exit!
|
99
|
+
end
|
100
|
+
|
101
|
+
if @@merb_opts[:cluster]
|
102
|
+
delete_pidfile
|
103
|
+
@@merb_opts[:port].to_i.upto(@@merb_opts[:port].to_i+@@merb_opts[:cluster].to_i-1) do |port|
|
104
|
+
puts "Starting merb server on port: #{port}"
|
105
|
+
start(port)
|
106
|
+
end
|
107
|
+
elsif @@merb_opts[:daemonize]
|
108
|
+
delete_pidfile
|
109
|
+
start(@@merb_opts[:port])
|
110
|
+
else
|
111
|
+
trap('INT') {exit}
|
112
|
+
mongrel_start(@@merb_opts[:port])
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.store_pid(pid)
|
118
|
+
File.open("#{@@merb_opts[:merb_root]}/log/merb.pid", 'a'){|f| f.write("#{Process.pid}\n")}
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.start(port)
|
122
|
+
fork do
|
123
|
+
Process.setsid
|
124
|
+
exit if fork
|
125
|
+
store_pid(Process.pid)
|
126
|
+
Dir.chdir @@merb_opts[:merb_root]
|
127
|
+
File.umask 0000
|
128
|
+
STDIN.reopen "/dev/null"
|
129
|
+
STDOUT.reopen "/dev/null", "a"
|
130
|
+
STDERR.reopen STDOUT
|
131
|
+
trap("TERM") { exit }
|
132
|
+
mongrel_start(port)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.delete_pidfile
|
137
|
+
FileUtils.rm("#{@@merb_opts[:merb_root]}/log/merb.pid") rescue nil
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.start_cluster(ports)
|
141
|
+
delete_pidfile
|
142
|
+
ports.each do |p|
|
143
|
+
start(port)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.mongrel_start(port)
|
148
|
+
h = Mongrel::HttpServer.new((@@merb_opts[:host]||"0.0.0.0"), (port ||4000), (@@merb_opts[:numprocs]||100))
|
149
|
+
h.register("/", MerbHandler.new(@@merb_opts[:dist_root]+'/public'))
|
150
|
+
h.register("/favicon.ico", Mongrel::Error404Handler.new(""))
|
151
|
+
h.run.join
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.config
|
155
|
+
@@merb_opts
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
|
7
161
|
Merb::Server.run
|
data/doc/rdoc/classes/Hash.html
CHANGED
@@ -124,10 +124,10 @@
|
|
124
124
|
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
125
125
|
<div class="method-source-code" id="M000008-source">
|
126
126
|
<pre>
|
127
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_utils.rb, line
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_utils.rb, line 47</span>
|
128
|
+
47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">with_indifferent_access</span>
|
129
|
+
48: <span class="ruby-constant">MerbHash</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>)
|
130
|
+
49: <span class="ruby-keyword kw">end</span>
|
131
131
|
</pre>
|
132
132
|
</div>
|
133
133
|
</div>
|
data/doc/rdoc/classes/Merb.html
CHANGED
@@ -58,18 +58,10 @@
|
|
58
58
|
<a href="../files/lib/merb_rb.html">
|
59
59
|
lib/merb.rb
|
60
60
|
</a>
|
61
|
-
<br />
|
62
|
-
<a href="../files/lib/merb_config_rb.html">
|
63
|
-
lib/merb_config.rb
|
64
|
-
</a>
|
65
61
|
<br />
|
66
62
|
<a href="../files/lib/merb/merb_controller_rb.html">
|
67
63
|
lib/merb/merb_controller.rb
|
68
64
|
</a>
|
69
|
-
<br />
|
70
|
-
<a href="../files/lib/merb/merb_daemon_rb.html">
|
71
|
-
lib/merb/merb_daemon.rb
|
72
|
-
</a>
|
73
65
|
<br />
|
74
66
|
<a href="../files/lib/merb/merb_router_rb.html">
|
75
67
|
lib/merb/merb_router.rb
|
@@ -103,10 +95,8 @@
|
|
103
95
|
<div id="class-list">
|
104
96
|
<h3 class="section-bar">Classes and Modules</h3>
|
105
97
|
|
106
|
-
Class <a href="Merb/
|
107
|
-
Class <a href="Merb/Controller.html" class="link">Merb::Controller</a><br />
|
98
|
+
Class <a href="Merb/Controller.html" class="link">Merb::Controller</a><br />
|
108
99
|
Class <a href="Merb/RouteMatcher.html" class="link">Merb::RouteMatcher</a><br />
|
109
|
-
Class <a href="Merb/Server.html" class="link">Merb::Server</a><br />
|
110
100
|
|
111
101
|
</div>
|
112
102
|
|
@@ -118,7 +108,7 @@ Class <a href="Merb/Server.html" class="link">Merb::Server</a><br />
|
|
118
108
|
<tr class="top-aligned-row context-row">
|
119
109
|
<td class="context-item-name">VERSION</td>
|
120
110
|
<td>=</td>
|
121
|
-
<td class="context-item-value">'0.0.
|
111
|
+
<td class="context-item-value">'0.0.5' unless defined?VERSION</td>
|
122
112
|
</tr>
|
123
113
|
</table>
|
124
114
|
</div>
|
@@ -84,14 +84,14 @@
|
|
84
84
|
<p>
|
85
85
|
All of your controllers will inherit from <a
|
86
86
|
href="Controller.html">Merb::Controller</a>. This superclass takes care of
|
87
|
-
parsing the incoming <a href="Controller.html#
|
88
|
-
into <a href="Controller.html#
|
89
|
-
href="Controller.html#
|
90
|
-
href="Controller.html#
|
87
|
+
parsing the incoming <a href="Controller.html#M000039">headers</a> and body
|
88
|
+
into <a href="Controller.html#M000037">params</a> and <a
|
89
|
+
href="Controller.html#M000038">cookies</a> and <a
|
90
|
+
href="Controller.html#M000039">headers</a>. If the request is a file upload
|
91
91
|
it will stream it into a tempfile and pass in the filename and tempfile
|
92
|
-
object to your controller via <a href="Controller.html#
|
92
|
+
object to your controller via <a href="Controller.html#M000037">params</a>.
|
93
93
|
It also parses the ?query=string and puts that into <a
|
94
|
-
href="Controller.html#
|
94
|
+
href="Controller.html#M000037">params</a> as well.
|
95
95
|
</p>
|
96
96
|
|
97
97
|
</div>
|
@@ -103,19 +103,24 @@ href="Controller.html#M000038">params</a> as well.
|
|
103
103
|
<h3 class="section-bar">Methods</h3>
|
104
104
|
|
105
105
|
<div class="name-list">
|
106
|
-
<a href="#
|
107
|
-
<a href="#
|
108
|
-
<a href="#
|
109
|
-
<a href="#
|
110
|
-
<a href="#
|
111
|
-
<a href="#
|
112
|
-
<a href="#
|
113
|
-
<a href="#
|
114
|
-
<a href="#
|
115
|
-
<a href="#
|
116
|
-
<a href="#
|
117
|
-
<a href="#
|
118
|
-
<a href="#
|
106
|
+
<a href="#M000038">cookies</a>
|
107
|
+
<a href="#M000046">current_method_name</a>
|
108
|
+
<a href="#M000041">escape</a>
|
109
|
+
<a href="#M000043">escape_js</a>
|
110
|
+
<a href="#M000039">headers</a>
|
111
|
+
<a href="#M000044">js</a>
|
112
|
+
<a href="#M000048">layout</a>
|
113
|
+
<a href="#M000037">params</a>
|
114
|
+
<a href="#M000051">partial</a>
|
115
|
+
<a href="#M000040">query_parse</a>
|
116
|
+
<a href="#M000035">redirect</a>
|
117
|
+
<a href="#M000052">render</a>
|
118
|
+
<a href="#M000047">render_js</a>
|
119
|
+
<a href="#M000050">render_no_layout</a>
|
120
|
+
<a href="#M000049">render_nothing</a>
|
121
|
+
<a href="#M000036">send_file</a>
|
122
|
+
<a href="#M000045">template_dir</a>
|
123
|
+
<a href="#M000042">unescape</a>
|
119
124
|
</div>
|
120
125
|
</div>
|
121
126
|
|
@@ -150,230 +155,346 @@ href="Controller.html#M000038">params</a> as well.
|
|
150
155
|
<div id="methods">
|
151
156
|
<h3 class="section-bar">Public Instance methods</h3>
|
152
157
|
|
153
|
-
<div id="method-
|
154
|
-
<a name="
|
158
|
+
<div id="method-M000038" class="method-detail">
|
159
|
+
<a name="M000038"></a>
|
155
160
|
|
156
161
|
<div class="method-heading">
|
157
|
-
<a href="#
|
162
|
+
<a href="#M000038" class="method-signature">
|
158
163
|
<span class="method-name">cookies</span><span class="method-args">()</span>
|
159
164
|
</a>
|
160
165
|
</div>
|
161
166
|
|
162
167
|
<div class="method-description">
|
168
|
+
<p>
|
169
|
+
accessor for @<a href="Controller.html#M000038">cookies</a>. Please use <a
|
170
|
+
href="Controller.html#M000038">cookies</a> and never @<a
|
171
|
+
href="Controller.html#M000038">cookies</a> directly.
|
172
|
+
</p>
|
163
173
|
<p><a class="source-toggle" href="#"
|
164
|
-
onclick="toggleCode('
|
165
|
-
<div class="method-source-code" id="
|
174
|
+
onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
|
175
|
+
<div class="method-source-code" id="M000038-source">
|
166
176
|
<pre>
|
167
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
168
|
-
|
169
|
-
|
170
|
-
|
177
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 92</span>
|
178
|
+
92: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cookies</span>
|
179
|
+
93: <span class="ruby-ivar">@cookies</span>
|
180
|
+
94: <span class="ruby-keyword kw">end</span>
|
171
181
|
</pre>
|
172
182
|
</div>
|
173
183
|
</div>
|
174
184
|
</div>
|
175
185
|
|
176
|
-
<div id="method-
|
177
|
-
<a name="
|
186
|
+
<div id="method-M000046" class="method-detail">
|
187
|
+
<a name="M000046"></a>
|
178
188
|
|
179
189
|
<div class="method-heading">
|
180
|
-
<a href="#
|
190
|
+
<a href="#M000046" class="method-signature">
|
181
191
|
<span class="method-name">current_method_name</span><span class="method-args">(depth=0)</span>
|
182
192
|
</a>
|
183
193
|
</div>
|
184
194
|
|
185
195
|
<div class="method-description">
|
196
|
+
<p>
|
197
|
+
returns the current method name. Used for auto discovery of which template
|
198
|
+
to <a href="Controller.html#M000052">render</a> based on the action name.
|
199
|
+
</p>
|
186
200
|
<p><a class="source-toggle" href="#"
|
187
|
-
onclick="toggleCode('
|
188
|
-
<div class="method-source-code" id="
|
201
|
+
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
202
|
+
<div class="method-source-code" id="M000046-source">
|
189
203
|
<pre>
|
190
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
191
|
-
|
192
|
-
|
193
|
-
|
204
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 140</span>
|
205
|
+
140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current_method_name</span>(<span class="ruby-identifier">depth</span>=<span class="ruby-value">0</span>)
|
206
|
+
141: <span class="ruby-identifier">caller</span>[<span class="ruby-identifier">depth</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/`(.*)'$/</span>; <span class="ruby-identifier">$1</span>
|
207
|
+
142: <span class="ruby-keyword kw">end</span>
|
194
208
|
</pre>
|
195
209
|
</div>
|
196
210
|
</div>
|
197
211
|
</div>
|
198
212
|
|
199
|
-
<div id="method-
|
200
|
-
<a name="
|
213
|
+
<div id="method-M000041" class="method-detail">
|
214
|
+
<a name="M000041"></a>
|
201
215
|
|
202
216
|
<div class="method-heading">
|
203
|
-
<a href="#
|
217
|
+
<a href="#M000041" class="method-signature">
|
204
218
|
<span class="method-name">escape</span><span class="method-args">(s)</span>
|
205
219
|
</a>
|
206
220
|
</div>
|
207
221
|
|
208
222
|
<div class="method-description">
|
223
|
+
<p>
|
224
|
+
does url escaping
|
225
|
+
</p>
|
209
226
|
<p><a class="source-toggle" href="#"
|
210
|
-
onclick="toggleCode('
|
211
|
-
<div class="method-source-code" id="
|
227
|
+
onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
|
228
|
+
<div class="method-source-code" id="M000041-source">
|
212
229
|
<pre>
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
230
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 117</span>
|
231
|
+
117: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">s</span>)
|
232
|
+
118: <span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">HttpRequest</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">s</span>)
|
233
|
+
119: <span class="ruby-keyword kw">end</span>
|
217
234
|
</pre>
|
218
235
|
</div>
|
219
236
|
</div>
|
220
237
|
</div>
|
221
238
|
|
222
|
-
<div id="method-
|
223
|
-
<a name="
|
239
|
+
<div id="method-M000043" class="method-detail">
|
240
|
+
<a name="M000043"></a>
|
224
241
|
|
225
242
|
<div class="method-heading">
|
226
|
-
<a href="#
|
243
|
+
<a href="#M000043" class="method-signature">
|
244
|
+
<span class="method-name">escape_js</span><span class="method-args">(javascript)</span>
|
245
|
+
</a>
|
246
|
+
</div>
|
247
|
+
|
248
|
+
<div class="method-description">
|
249
|
+
<p>
|
250
|
+
<a href="Controller.html#M000041">escape</a> text for javascript.
|
251
|
+
</p>
|
252
|
+
<p><a class="source-toggle" href="#"
|
253
|
+
onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
|
254
|
+
<div class="method-source-code" id="M000043-source">
|
255
|
+
<pre>
|
256
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 127</span>
|
257
|
+
127: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">escape_js</span>(<span class="ruby-identifier">javascript</span>)
|
258
|
+
128: (<span class="ruby-identifier">javascript</span> <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'\\'</span>,<span class="ruby-value str">'\0\0'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\r\n|\n|\r/</span>, <span class="ruby-value str">"\\n"</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/["']/</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-node">"\\#{m}"</span> }
|
259
|
+
129: <span class="ruby-keyword kw">end</span>
|
260
|
+
</pre>
|
261
|
+
</div>
|
262
|
+
</div>
|
263
|
+
</div>
|
264
|
+
|
265
|
+
<div id="method-M000039" class="method-detail">
|
266
|
+
<a name="M000039"></a>
|
267
|
+
|
268
|
+
<div class="method-heading">
|
269
|
+
<a href="#M000039" class="method-signature">
|
227
270
|
<span class="method-name">headers</span><span class="method-args">()</span>
|
228
271
|
</a>
|
229
272
|
</div>
|
230
273
|
|
231
274
|
<div class="method-description">
|
275
|
+
<p>
|
276
|
+
accessor for @<a href="Controller.html#M000039">headers</a>. Please use <a
|
277
|
+
href="Controller.html#M000039">headers</a> and never @<a
|
278
|
+
href="Controller.html#M000039">headers</a> directly.
|
279
|
+
</p>
|
232
280
|
<p><a class="source-toggle" href="#"
|
233
|
-
onclick="toggleCode('
|
234
|
-
<div class="method-source-code" id="
|
281
|
+
onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
|
282
|
+
<div class="method-source-code" id="M000039-source">
|
235
283
|
<pre>
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
284
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 98</span>
|
285
|
+
98: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">headers</span>
|
286
|
+
99: <span class="ruby-ivar">@headers</span>
|
287
|
+
100: <span class="ruby-keyword kw">end</span>
|
240
288
|
</pre>
|
241
289
|
</div>
|
242
290
|
</div>
|
243
291
|
</div>
|
244
292
|
|
245
|
-
<div id="method-
|
246
|
-
<a name="
|
293
|
+
<div id="method-M000044" class="method-detail">
|
294
|
+
<a name="M000044"></a>
|
247
295
|
|
248
296
|
<div class="method-heading">
|
249
|
-
<
|
297
|
+
<span class="method-name">js</span><span class="method-args">(javascript)</span>
|
298
|
+
</div>
|
299
|
+
|
300
|
+
<div class="method-description">
|
301
|
+
<p>
|
302
|
+
Alias for <a href="Controller.html#M000043">escape_js</a>
|
303
|
+
</p>
|
304
|
+
</div>
|
305
|
+
</div>
|
306
|
+
|
307
|
+
<div id="method-M000048" class="method-detail">
|
308
|
+
<a name="M000048"></a>
|
309
|
+
|
310
|
+
<div class="method-heading">
|
311
|
+
<a href="#M000048" class="method-signature">
|
250
312
|
<span class="method-name">layout</span><span class="method-args">(l)</span>
|
251
313
|
</a>
|
252
314
|
</div>
|
253
315
|
|
254
316
|
<div class="method-description">
|
317
|
+
<p>
|
318
|
+
set the @<a href="Controller.html#M000048">layout</a>. Use this right
|
319
|
+
before a <a href="Controller.html#M000052">render</a> to set the name of
|
320
|
+
the <a href="Controller.html#M000048">layout</a> to use minus the .rhtml
|
321
|
+
</p>
|
255
322
|
<p><a class="source-toggle" href="#"
|
256
|
-
onclick="toggleCode('
|
257
|
-
<div class="method-source-code" id="
|
323
|
+
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
324
|
+
<div class="method-source-code" id="M000048-source">
|
258
325
|
<pre>
|
259
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
260
|
-
|
261
|
-
|
262
|
-
|
326
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 156</span>
|
327
|
+
156: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">layout</span>(<span class="ruby-identifier">l</span>)
|
328
|
+
157: <span class="ruby-ivar">@layout</span> = <span class="ruby-identifier">l</span>
|
329
|
+
158: <span class="ruby-keyword kw">end</span>
|
263
330
|
</pre>
|
264
331
|
</div>
|
265
332
|
</div>
|
266
333
|
</div>
|
267
334
|
|
268
|
-
<div id="method-
|
269
|
-
<a name="
|
335
|
+
<div id="method-M000037" class="method-detail">
|
336
|
+
<a name="M000037"></a>
|
270
337
|
|
271
338
|
<div class="method-heading">
|
272
|
-
<a href="#
|
339
|
+
<a href="#M000037" class="method-signature">
|
273
340
|
<span class="method-name">params</span><span class="method-args">()</span>
|
274
341
|
</a>
|
275
342
|
</div>
|
276
343
|
|
277
344
|
<div class="method-description">
|
345
|
+
<p>
|
346
|
+
accessor for @<a href="Controller.html#M000037">params</a>. Please use <a
|
347
|
+
href="Controller.html#M000037">params</a> and never @<a
|
348
|
+
href="Controller.html#M000037">params</a> directly.
|
349
|
+
</p>
|
278
350
|
<p><a class="source-toggle" href="#"
|
279
|
-
onclick="toggleCode('
|
280
|
-
<div class="method-source-code" id="
|
351
|
+
onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
|
352
|
+
<div class="method-source-code" id="M000037-source">
|
281
353
|
<pre>
|
282
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
283
|
-
|
284
|
-
|
285
|
-
|
354
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 86</span>
|
355
|
+
86: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">params</span>
|
356
|
+
87: <span class="ruby-ivar">@params</span>
|
357
|
+
88: <span class="ruby-keyword kw">end</span>
|
286
358
|
</pre>
|
287
359
|
</div>
|
288
360
|
</div>
|
289
361
|
</div>
|
290
362
|
|
291
|
-
<div id="method-
|
292
|
-
<a name="
|
363
|
+
<div id="method-M000051" class="method-detail">
|
364
|
+
<a name="M000051"></a>
|
293
365
|
|
294
366
|
<div class="method-heading">
|
295
|
-
<a href="#
|
367
|
+
<a href="#M000051" class="method-signature">
|
368
|
+
<span class="method-name">partial</span><span class="method-args">(template)</span>
|
369
|
+
</a>
|
370
|
+
</div>
|
371
|
+
|
372
|
+
<div class="method-description">
|
373
|
+
<p><a class="source-toggle" href="#"
|
374
|
+
onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
|
375
|
+
<div class="method-source-code" id="M000051-source">
|
376
|
+
<pre>
|
377
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 171</span>
|
378
|
+
171: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">partial</span>(<span class="ruby-identifier">template</span>)
|
379
|
+
172: <span class="ruby-identifier">template</span> = <span class="ruby-constant">Erubis</span><span class="ruby-operator">::</span><span class="ruby-constant">Eruby</span>.<span class="ruby-identifier">new</span>( <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>( <span class="ruby-identifier">template_dir</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">snake_case</span>) <span class="ruby-operator">+</span> <span class="ruby-node">"/_#{template}.rhtml"</span> ) )
|
380
|
+
173: <span class="ruby-identifier">template</span>.<span class="ruby-identifier">result</span>(<span class="ruby-identifier">binding</span>)
|
381
|
+
174: <span class="ruby-keyword kw">end</span>
|
382
|
+
</pre>
|
383
|
+
</div>
|
384
|
+
</div>
|
385
|
+
</div>
|
386
|
+
|
387
|
+
<div id="method-M000040" class="method-detail">
|
388
|
+
<a name="M000040"></a>
|
389
|
+
|
390
|
+
<div class="method-heading">
|
391
|
+
<a href="#M000040" class="method-signature">
|
296
392
|
<span class="method-name">query_parse</span><span class="method-args">(qs, d = '&;')</span>
|
297
393
|
</a>
|
298
394
|
</div>
|
299
395
|
|
300
396
|
<div class="method-description">
|
397
|
+
<p>
|
398
|
+
parses a query string or the payload of a POST request into the <a
|
399
|
+
href="Controller.html#M000037">params</a> hash. So for example:
|
400
|
+
/foo?bar=nik&post[title]=heya&post[body]=whatever parses into:
|
401
|
+
{:bar => ‘nik’, :post => {:title =>
|
402
|
+
‘heya’, :body => ‘whatever}}
|
403
|
+
</p>
|
301
404
|
<p><a class="source-toggle" href="#"
|
302
|
-
onclick="toggleCode('
|
303
|
-
<div class="method-source-code" id="
|
405
|
+
onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
|
406
|
+
<div class="method-source-code" id="M000040-source">
|
304
407
|
<pre>
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
408
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 107</span>
|
409
|
+
107: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">query_parse</span>(<span class="ruby-identifier">qs</span>, <span class="ruby-identifier">d</span> = <span class="ruby-value str">'&;'</span>)
|
410
|
+
108: <span class="ruby-identifier">m</span> = <span class="ruby-identifier">proc</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">_</span>,<span class="ruby-identifier">o</span>,<span class="ruby-identifier">n</span><span class="ruby-operator">|</span><span class="ruby-identifier">o</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">n</span>,<span class="ruby-operator">&</span><span class="ruby-identifier">m</span>)<span class="ruby-keyword kw">rescue</span>([<span class="ruby-operator">*</span><span class="ruby-identifier">o</span>]<span class="ruby-operator"><<</span><span class="ruby-identifier">n</span>)}
|
411
|
+
109: (<span class="ruby-identifier">qs</span><span class="ruby-operator">||</span><span class="ruby-value str">''</span>).<span class="ruby-identifier">split</span>(<span class="ruby-node">/[#{d}] */n</span>).<span class="ruby-identifier">inject</span>(<span class="ruby-constant">MerbHash</span>[]) { <span class="ruby-operator">|</span><span class="ruby-identifier">h</span>,<span class="ruby-identifier">p</span><span class="ruby-operator">|</span>
|
412
|
+
110: <span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>=<span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">p</span>).<span class="ruby-identifier">split</span>(<span class="ruby-value str">'='</span>,<span class="ruby-value">2</span>)
|
413
|
+
111: <span class="ruby-identifier">h</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">k</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/[\]\[]+/</span>).<span class="ruby-identifier">reverse</span>.
|
414
|
+
112: <span class="ruby-identifier">inject</span>(<span class="ruby-identifier">v</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-constant">MerbHash</span>[<span class="ruby-identifier">i</span>,<span class="ruby-identifier">x</span>] },<span class="ruby-operator">&</span><span class="ruby-identifier">m</span>)
|
415
|
+
113: }
|
416
|
+
114: <span class="ruby-keyword kw">end</span>
|
314
417
|
</pre>
|
315
418
|
</div>
|
316
419
|
</div>
|
317
420
|
</div>
|
318
421
|
|
319
|
-
<div id="method-
|
320
|
-
<a name="
|
422
|
+
<div id="method-M000035" class="method-detail">
|
423
|
+
<a name="M000035"></a>
|
321
424
|
|
322
425
|
<div class="method-heading">
|
323
|
-
<a href="#
|
426
|
+
<a href="#M000035" class="method-signature">
|
324
427
|
<span class="method-name">redirect</span><span class="method-args">(url)</span>
|
325
428
|
</a>
|
326
429
|
</div>
|
327
430
|
|
328
431
|
<div class="method-description">
|
432
|
+
<p>
|
433
|
+
<a href="Controller.html#M000035">redirect</a> to another url It can be
|
434
|
+
like /foo/bar for redirecting within your same app. Or it can be a fully
|
435
|
+
qualified url to another site.
|
436
|
+
</p>
|
329
437
|
<p><a class="source-toggle" href="#"
|
330
|
-
onclick="toggleCode('
|
331
|
-
<div class="method-source-code" id="
|
438
|
+
onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
|
439
|
+
<div class="method-source-code" id="M000035-source">
|
332
440
|
<pre>
|
333
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
441
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 69</span>
|
442
|
+
69: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">redirect</span>(<span class="ruby-identifier">url</span>)
|
443
|
+
70: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">"Redirecting to: #{url}"</span>)
|
444
|
+
71: <span class="ruby-ivar">@status</span> = <span class="ruby-value">302</span>
|
445
|
+
72: <span class="ruby-ivar">@headers</span>.<span class="ruby-identifier">merge!</span>({<span class="ruby-value str">'Location'</span>=<span class="ruby-operator">></span> <span class="ruby-identifier">url</span>})
|
446
|
+
73: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">''</span>
|
447
|
+
74: <span class="ruby-keyword kw">end</span>
|
339
448
|
</pre>
|
340
449
|
</div>
|
341
450
|
</div>
|
342
451
|
</div>
|
343
452
|
|
344
|
-
<div id="method-
|
345
|
-
<a name="
|
453
|
+
<div id="method-M000052" class="method-detail">
|
454
|
+
<a name="M000052"></a>
|
346
455
|
|
347
456
|
<div class="method-heading">
|
348
|
-
<a href="#
|
457
|
+
<a href="#M000052" class="method-signature">
|
349
458
|
<span class="method-name">render</span><span class="method-args">(template=current_method_name(1), b=binding)</span>
|
350
459
|
</a>
|
351
460
|
</div>
|
352
461
|
|
353
462
|
<div class="method-description">
|
463
|
+
<p>
|
464
|
+
renders a template based on the current action name you can pass the name
|
465
|
+
of a template if you want to <a href="Controller.html#M000052">render</a> a
|
466
|
+
template with a different name then then current action name. Wraps the
|
467
|
+
rendered template in the <a href="Controller.html#M000048">layout</a>. Uses
|
468
|
+
layout/application.rhtml unless there is a <a
|
469
|
+
href="Controller.html#M000048">layout</a> named after the current
|
470
|
+
controller or @<a href="Controller.html#M000048">layout</a> has been set to
|
471
|
+
another value.
|
472
|
+
</p>
|
354
473
|
<p><a class="source-toggle" href="#"
|
355
|
-
onclick="toggleCode('
|
356
|
-
<div class="method-source-code" id="
|
474
|
+
onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
|
475
|
+
<div class="method-source-code" id="M000052-source">
|
357
476
|
<pre>
|
358
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
477
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 183</span>
|
478
|
+
183: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render</span>(<span class="ruby-identifier">template</span>=<span class="ruby-identifier">current_method_name</span>(<span class="ruby-value">1</span>), <span class="ruby-identifier">b</span>=<span class="ruby-identifier">binding</span>)
|
479
|
+
184: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">"Rendering template: #{template_dir(template)}"</span>)
|
480
|
+
185: <span class="ruby-identifier">name</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">snake_case</span>
|
481
|
+
186: <span class="ruby-identifier">template</span> = <span class="ruby-constant">Erubis</span><span class="ruby-operator">::</span><span class="ruby-constant">Eruby</span>.<span class="ruby-identifier">new</span>( <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>( <span class="ruby-identifier">template_dir</span>(<span class="ruby-identifier">name</span>) <span class="ruby-operator">+</span> <span class="ruby-node">"/#{template}.rhtml"</span> ) )
|
482
|
+
187: <span class="ruby-identifier">layout_content</span> = <span class="ruby-identifier">template</span>.<span class="ruby-identifier">result</span>(<span class="ruby-identifier">b</span>)
|
483
|
+
188: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">layout_content</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@layout</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'none'</span>)
|
484
|
+
189: <span class="ruby-keyword kw">if</span> [<span class="ruby-value str">'application'</span>, <span class="ruby-identifier">name</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-ivar">@layout</span>.<span class="ruby-identifier">to_s</span>)
|
485
|
+
190: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">template_dir</span>(<span class="ruby-node">"layout/#{name}.rhtml"</span>))
|
486
|
+
191: <span class="ruby-identifier">layout</span> = <span class="ruby-identifier">name</span>
|
487
|
+
192: <span class="ruby-keyword kw">else</span>
|
488
|
+
193: <span class="ruby-identifier">layout</span> = <span class="ruby-value str">'application'</span>
|
489
|
+
194: <span class="ruby-keyword kw">end</span>
|
490
|
+
195: <span class="ruby-keyword kw">else</span>
|
491
|
+
196: <span class="ruby-identifier">layout</span> = <span class="ruby-ivar">@layout</span>.<span class="ruby-identifier">to_s</span>
|
492
|
+
197: <span class="ruby-keyword kw">end</span>
|
493
|
+
198: <span class="ruby-constant">MERB_LOGGER</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">"With Layout: #{template_dir('layout')}/#{layout}.rhtml"</span>)
|
494
|
+
199: <span class="ruby-ivar">@layout_content</span> = <span class="ruby-identifier">layout_content</span>
|
495
|
+
200: <span class="ruby-identifier">layout_tmpl</span> = <span class="ruby-constant">Erubis</span><span class="ruby-operator">::</span><span class="ruby-constant">Eruby</span>.<span class="ruby-identifier">new</span>( <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>( <span class="ruby-identifier">template_dir</span>(<span class="ruby-value str">'layout'</span>) <span class="ruby-operator">+</span> <span class="ruby-node">"/#{layout}.rhtml"</span> ) )
|
496
|
+
201: <span class="ruby-identifier">layout_tmpl</span>.<span class="ruby-identifier">result</span>(<span class="ruby-identifier">b</span>)
|
497
|
+
202: <span class="ruby-keyword kw">end</span>
|
377
498
|
</pre>
|
378
499
|
</div>
|
379
500
|
</div>
|
@@ -384,90 +505,160 @@ href="Controller.html#M000038">params</a> as well.
|
|
384
505
|
|
385
506
|
<div class="method-heading">
|
386
507
|
<a href="#M000047" class="method-signature">
|
387
|
-
<span class="method-name">
|
508
|
+
<span class="method-name">render_js</span><span class="method-args">(template=current_method_name(1), b=binding)</span>
|
388
509
|
</a>
|
389
510
|
</div>
|
390
511
|
|
391
512
|
<div class="method-description">
|
513
|
+
<p>
|
514
|
+
does a <a href="Controller.html#M000052">render</a> with no <a
|
515
|
+
href="Controller.html#M000048">layout</a>. Also sets the content type
|
516
|
+
header to text/javascript and escapes the template for javascript eval on
|
517
|
+
the client
|
518
|
+
</p>
|
392
519
|
<p><a class="source-toggle" href="#"
|
393
520
|
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
394
521
|
<div class="method-source-code" id="M000047-source">
|
395
522
|
<pre>
|
396
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
523
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 148</span>
|
524
|
+
148: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render_js</span>(<span class="ruby-identifier">template</span>=<span class="ruby-identifier">current_method_name</span>(<span class="ruby-value">1</span>), <span class="ruby-identifier">b</span>=<span class="ruby-identifier">binding</span>)
|
525
|
+
149: <span class="ruby-identifier">headers</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-value str">"text/javascript"</span>
|
526
|
+
150: <span class="ruby-identifier">template</span> = <span class="ruby-constant">Erubis</span><span class="ruby-operator">::</span><span class="ruby-constant">Eruby</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>( <span class="ruby-identifier">template_dir</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">snake_case</span>) <span class="ruby-operator">+</span> <span class="ruby-node">"/#{template}.merbjs"</span> ))
|
527
|
+
151: <span class="ruby-identifier">template</span>.<span class="ruby-identifier">result</span>(<span class="ruby-identifier">b</span>)
|
528
|
+
152: <span class="ruby-keyword kw">end</span>
|
401
529
|
</pre>
|
402
530
|
</div>
|
403
531
|
</div>
|
404
532
|
</div>
|
405
533
|
|
406
|
-
<div id="method-
|
407
|
-
<a name="
|
534
|
+
<div id="method-M000050" class="method-detail">
|
535
|
+
<a name="M000050"></a>
|
408
536
|
|
409
537
|
<div class="method-heading">
|
410
|
-
<a href="#
|
538
|
+
<a href="#M000050" class="method-signature">
|
539
|
+
<span class="method-name">render_no_layout</span><span class="method-args">(template=current_method_name(1), b=binding)</span>
|
540
|
+
</a>
|
541
|
+
</div>
|
542
|
+
|
543
|
+
<div class="method-description">
|
544
|
+
<p>
|
545
|
+
renders the action without wrapping it in a <a
|
546
|
+
href="Controller.html#M000048">layout</a>.
|
547
|
+
</p>
|
548
|
+
<p><a class="source-toggle" href="#"
|
549
|
+
onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
|
550
|
+
<div class="method-source-code" id="M000050-source">
|
551
|
+
<pre>
|
552
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 166</span>
|
553
|
+
166: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render_no_layout</span>(<span class="ruby-identifier">template</span>=<span class="ruby-identifier">current_method_name</span>(<span class="ruby-value">1</span>), <span class="ruby-identifier">b</span>=<span class="ruby-identifier">binding</span>)
|
554
|
+
167: <span class="ruby-identifier">template</span> = <span class="ruby-constant">Erubis</span><span class="ruby-operator">::</span><span class="ruby-constant">Eruby</span>.<span class="ruby-identifier">new</span>( <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>( <span class="ruby-identifier">template_dir</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">snake_case</span>) <span class="ruby-operator">+</span> <span class="ruby-node">"/#{template}.rhtml"</span> ) )
|
555
|
+
168: <span class="ruby-identifier">template</span>.<span class="ruby-identifier">result</span>(<span class="ruby-identifier">b</span>)
|
556
|
+
169: <span class="ruby-keyword kw">end</span>
|
557
|
+
</pre>
|
558
|
+
</div>
|
559
|
+
</div>
|
560
|
+
</div>
|
561
|
+
|
562
|
+
<div id="method-M000049" class="method-detail">
|
563
|
+
<a name="M000049"></a>
|
564
|
+
|
565
|
+
<div class="method-heading">
|
566
|
+
<a href="#M000049" class="method-signature">
|
567
|
+
<span class="method-name">render_nothing</span><span class="method-args">(status)</span>
|
568
|
+
</a>
|
569
|
+
</div>
|
570
|
+
|
571
|
+
<div class="method-description">
|
572
|
+
<p><a class="source-toggle" href="#"
|
573
|
+
onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
|
574
|
+
<div class="method-source-code" id="M000049-source">
|
575
|
+
<pre>
|
576
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 160</span>
|
577
|
+
160: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">render_nothing</span>(<span class="ruby-identifier">status</span>)
|
578
|
+
161: <span class="ruby-ivar">@status</span> = <span class="ruby-identifier">status</span>
|
579
|
+
162: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">''</span>
|
580
|
+
163: <span class="ruby-keyword kw">end</span>
|
581
|
+
</pre>
|
582
|
+
</div>
|
583
|
+
</div>
|
584
|
+
</div>
|
585
|
+
|
586
|
+
<div id="method-M000036" class="method-detail">
|
587
|
+
<a name="M000036"></a>
|
588
|
+
|
589
|
+
<div class="method-heading">
|
590
|
+
<a href="#M000036" class="method-signature">
|
411
591
|
<span class="method-name">send_file</span><span class="method-args">(file)</span>
|
412
592
|
</a>
|
413
593
|
</div>
|
414
594
|
|
415
595
|
<div class="method-description">
|
596
|
+
<p>
|
597
|
+
pass in a path to a file and this will set the right <a
|
598
|
+
href="Controller.html#M000039">headers</a> and let mongrel do its thang and
|
599
|
+
serve the static file directly.
|
600
|
+
</p>
|
416
601
|
<p><a class="source-toggle" href="#"
|
417
|
-
onclick="toggleCode('
|
418
|
-
<div class="method-source-code" id="
|
602
|
+
onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
|
603
|
+
<div class="method-source-code" id="M000036-source">
|
419
604
|
<pre>
|
420
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
605
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 79</span>
|
606
|
+
79: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_file</span>(<span class="ruby-identifier">file</span>)
|
607
|
+
80: <span class="ruby-identifier">headers</span>[<span class="ruby-value str">'X-SENDFILE'</span>] = <span class="ruby-identifier">file</span>
|
608
|
+
81: <span class="ruby-keyword kw">return</span>
|
609
|
+
82: <span class="ruby-keyword kw">end</span>
|
425
610
|
</pre>
|
426
611
|
</div>
|
427
612
|
</div>
|
428
613
|
</div>
|
429
614
|
|
430
|
-
<div id="method-
|
431
|
-
<a name="
|
615
|
+
<div id="method-M000045" class="method-detail">
|
616
|
+
<a name="M000045"></a>
|
432
617
|
|
433
618
|
<div class="method-heading">
|
434
|
-
<a href="#
|
619
|
+
<a href="#M000045" class="method-signature">
|
435
620
|
<span class="method-name">template_dir</span><span class="method-args">(loc)</span>
|
436
621
|
</a>
|
437
622
|
</div>
|
438
623
|
|
439
624
|
<div class="method-description">
|
625
|
+
<p>
|
626
|
+
shortcut to a template path based on name.
|
627
|
+
</p>
|
440
628
|
<p><a class="source-toggle" href="#"
|
441
|
-
onclick="toggleCode('
|
442
|
-
<div class="method-source-code" id="
|
629
|
+
onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
|
630
|
+
<div class="method-source-code" id="M000045-source">
|
443
631
|
<pre>
|
444
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
445
|
-
|
446
|
-
|
447
|
-
|
632
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 133</span>
|
633
|
+
133: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">template_dir</span>(<span class="ruby-identifier">loc</span>)
|
634
|
+
134: <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-constant">Merb</span><span class="ruby-operator">::</span><span class="ruby-constant">Server</span>.<span class="ruby-identifier">config</span>[<span class="ruby-identifier">:merb_root</span>] <span class="ruby-operator">+</span> <span class="ruby-node">"/dist/app/views/#{loc}"</span>)
|
635
|
+
135: <span class="ruby-keyword kw">end</span>
|
448
636
|
</pre>
|
449
637
|
</div>
|
450
638
|
</div>
|
451
639
|
</div>
|
452
640
|
|
453
|
-
<div id="method-
|
454
|
-
<a name="
|
641
|
+
<div id="method-M000042" class="method-detail">
|
642
|
+
<a name="M000042"></a>
|
455
643
|
|
456
644
|
<div class="method-heading">
|
457
|
-
<a href="#
|
645
|
+
<a href="#M000042" class="method-signature">
|
458
646
|
<span class="method-name">unescape</span><span class="method-args">(s)</span>
|
459
647
|
</a>
|
460
648
|
</div>
|
461
649
|
|
462
650
|
<div class="method-description">
|
651
|
+
<p>
|
652
|
+
does url unescaping
|
653
|
+
</p>
|
463
654
|
<p><a class="source-toggle" href="#"
|
464
|
-
onclick="toggleCode('
|
465
|
-
<div class="method-source-code" id="
|
655
|
+
onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
|
656
|
+
<div class="method-source-code" id="M000042-source">
|
466
657
|
<pre>
|
467
|
-
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line
|
468
|
-
|
469
|
-
|
470
|
-
|
658
|
+
<span class="ruby-comment cmt"># File lib/merb/merb_controller.rb, line 122</span>
|
659
|
+
122: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">s</span>)
|
660
|
+
123: <span class="ruby-constant">Mongrel</span><span class="ruby-operator">::</span><span class="ruby-constant">HttpRequest</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">s</span>)
|
661
|
+
124: <span class="ruby-keyword kw">end</span>
|
471
662
|
</pre>
|
472
663
|
</div>
|
473
664
|
</div>
|