merb 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. data/README +64 -80
  2. data/Rakefile +25 -12
  3. data/bin/merb +2 -223
  4. data/examples/README_EXAMPLES +10 -0
  5. data/examples/skeleton.tar +0 -0
  6. data/lib/merb.rb +48 -21
  7. data/lib/merb/core_ext.rb +12 -2
  8. data/lib/merb/core_ext/merb_class.rb +21 -21
  9. data/lib/merb/core_ext/merb_kernel.rb +60 -0
  10. data/lib/merb/core_ext/merb_object.rb +14 -0
  11. data/lib/merb/core_ext/merb_string.rb +3 -13
  12. data/lib/merb/generators/merb_app/merb_app.rb +33 -0
  13. data/lib/merb/merb_constants.rb +7 -0
  14. data/lib/merb/merb_controller.rb +31 -23
  15. data/lib/merb/merb_drb_server.rb +6 -60
  16. data/lib/merb/merb_exceptions.rb +162 -2
  17. data/lib/merb/merb_handler.rb +8 -19
  18. data/lib/merb/merb_mailer.rb +60 -0
  19. data/lib/merb/merb_router.rb +1 -1
  20. data/lib/merb/merb_server.rb +240 -0
  21. data/lib/merb/merb_upload_handler.rb +1 -1
  22. data/lib/merb/merb_view_context.rb +11 -6
  23. data/lib/merb/mixins/basic_authentication_mixin.rb +11 -13
  24. data/lib/merb/mixins/controller_mixin.rb +12 -6
  25. data/lib/merb/mixins/form_control_mixin.rb +94 -0
  26. data/lib/merb/mixins/render_mixin.rb +50 -24
  27. data/lib/merb/mixins/view_context_mixin.rb +122 -0
  28. data/lib/merb/session/merb_ar_session.rb +13 -14
  29. data/lib/merb/session/merb_memory_session.rb +105 -0
  30. metadata +13 -132
  31. data/examples/app_skeleton/Rakefile +0 -82
  32. data/examples/app_skeleton/dist/app/helpers/global_helper.rb +0 -6
  33. data/examples/app_skeleton/dist/conf/merb.yml +0 -11
  34. data/examples/app_skeleton/dist/conf/merb_init.rb +0 -16
  35. data/examples/app_skeleton/dist/conf/mup.conf +0 -5
  36. data/examples/app_skeleton/dist/conf/router.rb +0 -19
  37. data/examples/app_skeleton/scripts/merb_stop +0 -13
  38. data/examples/app_skeleton/scripts/new_migration +0 -21
  39. data/examples/app_skeleton/test/test_helper.rb +0 -1
  40. data/examples/sample_app/Rakefile +0 -82
  41. data/examples/sample_app/dist/app/controllers/files.rb +0 -31
  42. data/examples/sample_app/dist/app/controllers/posts.rb +0 -71
  43. data/examples/sample_app/dist/app/controllers/test.rb +0 -40
  44. data/examples/sample_app/dist/app/helpers/global_helper.rb +0 -7
  45. data/examples/sample_app/dist/app/helpers/posts_helper.rb +0 -4
  46. data/examples/sample_app/dist/app/models/comment.rb +0 -3
  47. data/examples/sample_app/dist/app/models/post.rb +0 -4
  48. data/examples/sample_app/dist/app/views/files/progress.jerb +0 -3
  49. data/examples/sample_app/dist/app/views/files/start.herb +0 -62
  50. data/examples/sample_app/dist/app/views/files/upload.herb +0 -6
  51. data/examples/sample_app/dist/app/views/layout/application.herb +0 -61
  52. data/examples/sample_app/dist/app/views/layout/foo.herb +0 -6
  53. data/examples/sample_app/dist/app/views/posts/_comments.herb +0 -11
  54. data/examples/sample_app/dist/app/views/posts/comment.jerb +0 -1
  55. data/examples/sample_app/dist/app/views/posts/list.herb +0 -5
  56. data/examples/sample_app/dist/app/views/posts/new.herb +0 -37
  57. data/examples/sample_app/dist/app/views/posts/show.herb +0 -37
  58. data/examples/sample_app/dist/app/views/posts/xml_test.xerb +0 -3
  59. data/examples/sample_app/dist/app/views/shared/_test.herb +0 -1
  60. data/examples/sample_app/dist/app/views/test/foo.herb +0 -2
  61. data/examples/sample_app/dist/app/views/test/hello.herb +0 -5
  62. data/examples/sample_app/dist/app/views/test/json.jerb +0 -1
  63. data/examples/sample_app/dist/conf/merb.yml +0 -11
  64. data/examples/sample_app/dist/conf/merb_init.rb +0 -24
  65. data/examples/sample_app/dist/conf/mup.conf +0 -5
  66. data/examples/sample_app/dist/conf/router.rb +0 -19
  67. data/examples/sample_app/dist/public/images/bg.jpg +0 -0
  68. data/examples/sample_app/dist/public/images/book.gif +0 -0
  69. data/examples/sample_app/dist/public/images/booksmall.gif +0 -0
  70. data/examples/sample_app/dist/public/images/greenright.jpg +0 -0
  71. data/examples/sample_app/dist/public/images/louiecon.gif +0 -0
  72. data/examples/sample_app/dist/public/images/menu.gif +0 -0
  73. data/examples/sample_app/dist/public/images/menuleft.gif +0 -0
  74. data/examples/sample_app/dist/public/images/menuright.gif +0 -0
  75. data/examples/sample_app/dist/public/images/mountain.jpg +0 -0
  76. data/examples/sample_app/dist/public/images/n3.jpg +0 -0
  77. data/examples/sample_app/dist/public/images/nautica.jpg +0 -0
  78. data/examples/sample_app/dist/public/javascripts/application.js +0 -0
  79. data/examples/sample_app/dist/public/javascripts/effects.js +0 -975
  80. data/examples/sample_app/dist/public/javascripts/mup.js +0 -113
  81. data/examples/sample_app/dist/public/javascripts/prototype.js +0 -2264
  82. data/examples/sample_app/dist/public/stylesheets/merb.css +0 -277
  83. data/examples/sample_app/dist/public/test.html +0 -5
  84. data/examples/sample_app/dist/schema/migrations/001_add_comments_to_posts.rb +0 -22
  85. data/examples/sample_app/dist/schema/migrations/002_add_sessions_table.rb +0 -14
  86. data/examples/sample_app/dist/schema/schema.rb +0 -28
  87. data/examples/sample_app/foo.txt +0 -0
  88. data/examples/sample_app/log/merb.4000.pid +0 -1
  89. data/examples/sample_app/script/merb_stop +0 -13
  90. data/examples/sample_app/script/new_migration +0 -21
  91. data/examples/sample_app/test/test_helper.rb +0 -1
  92. data/lib/merb/mixins/javascript_mixin.rb +0 -147
  93. data/lib/merb/session/merb_drb_session.rb +0 -65
  94. data/test/test_helper.rb +0 -1
  95. data/test/unit/route_matcher_test.rb +0 -46
data/README CHANGED
@@ -12,59 +12,18 @@ mongrel
12
12
  erubis
13
13
  json or fjson
14
14
  mime-types
15
+ archive-tar-minitar
16
+ rspec
15
17
 
16
18
  Install these gems first then you can build the merb gem from svn trunk like so:
17
- $ sudo gem install mongrel erubis json mime-types --include-dependencies
18
- $ svn co http://svn.devjavu.com/merb
19
+ $ sudo gem install mongrel erubis json mime-types archive-tar-minitar rspec --include-dependencies
20
+ $ svn co http://svn.devjavu.com/merb/trunk merb
19
21
  $ cd merb
20
- $ sudo rake install
22
+ $ rake install
21
23
 
22
- **Important**
23
- The new default filename extensions for templates are as follows
24
- html -> .herb
25
- js -> .jerb
26
- xml -> .xerb
24
+ To generate a new merb app after the gem is installed:
25
+ $ merb -g myapp
27
26
 
28
- You can change the extensions to anything you want in your config file in
29
- yourapp/dist/conf/merb.yml. See the default settings in the sample app.
30
-
31
- First you need to install the dependencies. Merb requires the follwing gems
32
-
33
- erubis
34
-
35
- json
36
-
37
- fjson # will be used if present. requires C extension.
38
-
39
- # fastthread will be used if present and is reccommended.
40
- sudo gem install fastthread --source=http://mongrel.rubyforge.org/
41
-
42
- If you have checked out merb trunk from svn you will want to build and install
43
- the gem to use merb. Run this command from the root of the merb svn checkout
44
- to do that:
45
-
46
- $ sudo rake install
47
-
48
-
49
- If you installed merb from gems then unpack the gem and grab the sample app
50
- $ gem unpack merb
51
-
52
- now with either the svn or the unpacked gem you can try out the sample app.
53
-
54
- $ cd merb*
55
- $ cd examples/sample_app
56
-
57
- $ merb
58
-
59
- You will need the mongrel_upload_progress gem installed to go to /files
60
- so use the -f flag to load a config file for mongrel_upload_progress
61
- $ merb -f dist/conf/mup.conf
62
-
63
- then the sample app will be running on port 4000 in the foreground.
64
- you can go to a few urls:
65
- http://localhost:4000/files/start
66
-
67
- http://localhost:4000/foo/123/baz/12234345
68
27
 
69
28
  **FEATURES**
70
29
 
@@ -111,7 +70,7 @@ classes with built in render method and template handling
111
70
  with instance vars available in the views automatically. Merb also supports
112
71
  layouts. It will look for a layout named after your controller class first and
113
72
  then fall back to application.herb if no layout exists named after your controller.
114
- You can use render_no_layout or do layout :none right before you render
73
+ You can use render_no_layout or do render :layout => :none
115
74
 
116
75
 
117
76
  class Test < Merb::Controller
@@ -122,28 +81,24 @@ class Test < Merb::Controller
122
81
  end
123
82
  end
124
83
 
125
- <html>
126
- <head>
127
- <title>Hello, <%= @name %></title>
128
- </head>
129
- <body>
130
- <%= @layout_content %>
131
- </body>
132
- </html>
133
-
134
-
135
- <h1><%= params.inspect %></h1>
136
- <h1><%= cookies.inspect %></h1>
137
- <% 5.times do %>
138
- <h1>Hello, <%= @name %>!</h1>
139
- <% end %>
140
-
141
84
  You can also render partials like so:
142
85
  <%= partial(:comments) %>
143
-
144
86
  This assumes a _comments.rhtml file in the same view dir as the current
145
87
  controller/view
146
88
 
89
+ Partials compile the template ands returns a string. So you can also call
90
+ them and assign them to a var if you want:
91
+
92
+ def someaction
93
+ @one = partial(:one)
94
+ @two = partial(:two)
95
+ end
96
+
97
+ partials can also render views from other controllers by specifying the path
98
+
99
+ partial('/shared/foo')
100
+
101
+
147
102
  Merb also allows for returning javascript instead of html for ajax actions
148
103
  You have to use the render_js instead of normal render
149
104
 
@@ -166,30 +121,65 @@ $('comments').update('<%=js partial(:posts) %>');
166
121
  </ul>
167
122
 
168
123
 
169
- *Controllers also now have before filters*
124
+ *Controllers have powerful before and after filters*
170
125
 
171
126
  Use the before method in your controllers. before accepts either a symbol
172
127
  or a Proc/lambda object. If you give it a symbol it will call a method with
173
128
  the same name as the symbol. If you give it a proc that takes one argument
174
- it will call the proc with the current controller as that argument.
129
+ it will call the proc with the current controller as that argument. You can
130
+ use :only and :exclude as options to your filters to exclude or include actionsfrom certain filters. :only and :exclude take :symbols or [:sym, :sam]
131
+ array of symbols.
175
132
 
176
133
  class Foo < Merb::Controller
177
134
 
178
- before :setup_user
179
- before lambda {|c| c.headers['X-Foo] = 'bar' }
135
+ before :setup_user, :only => :foo
136
+ before lambda {|c| c.headers['X-Foo] = 'bar' }, :exclude => [:foo, :baz]
180
137
 
181
138
  def setup_user
182
139
  # blah blah
183
140
  end
184
141
 
142
+ def foo
143
+ # blah
144
+ end
145
+
185
146
  def regular_action
186
147
  # blah
187
148
  end
188
149
 
189
150
  end
190
151
 
191
- Sessions are available when you start merb with the -s flag. See sample app for
192
- migration too add session table.
152
+ To stop the before filter chain you use throw :halt with a few options:
153
+
154
+ # halts the filter chain and calls filters_halted which you can override
155
+ # in your controller to specialize it.
156
+
157
+ throw :halt
158
+
159
+ # halts the filters and calls the method named after the symbol:
160
+
161
+ throw :halt, :other_action
162
+
163
+ # halts the filter chain and returns the result of the Proc being called
164
+
165
+ throw :halt, Proc.new{ |c| c.redirect "/foo" }
166
+
167
+ # halts the chain and returns whatever is in the string
168
+
169
+ throw :halt, "<h1>You don't have permissions IDIOT!</h1>"
170
+
171
+ or even render templates:
172
+
173
+ throw :halt, render 'foo'
174
+ throw :halt, partial 'foo'
175
+
176
+ After filters only accept a Proc and call that proc with the controller:
177
+
178
+ after Proc.new {|c| Tidy.new(c.body) }, :only => :index
179
+
180
+ Sessions are available when you start merb with the sql_session set to true or the memory_session set to true. See generated app for migration too add session table.
181
+
182
+ Helpers: dist/app/helpers/global_helper.rb will be available to all of your views. Helpers named afdter your controller plus _helper.rb will be included in the views for that controller only.
193
183
 
194
184
 
195
185
  *The merb server*
@@ -215,11 +205,7 @@ $merb -i
215
205
 
216
206
  *File uploads*
217
207
  This is one of the things that Merb was written for. Rails doesn't allow
218
- multiple concurrent file uploads at once without blocking an entire rails backend
219
- for each file upload. Merb allows multiple file uploads at once. Start the server
220
- and browse to http://localhost:4000/files/start and you will get a file upload
221
- form. This uses the mongrel_upload_progress gem so that must be installed first.
222
- There is a very simple upload controller example that handles this upload with a
208
+ multiple concurrent file uploads at once without blocking an entire rails backend for each file upload. Merb allows multiple file uploads at once.
223
209
  progress bar. When a file is uploaded with Merb, it gets put in a Tempfile. So
224
210
  you just want to copy it to the right place on the filesystem.
225
211
 
@@ -242,13 +228,11 @@ and DIST_ROOT. MERB_ROOT is the root of the whole tree. And DISTROOT is MERB_ROO
242
228
  You will cd into MERB_ROOT to run the merb command line. ANd when you deploy live you
243
229
  will put the dist dir into another empty MERB_ROOT on the production server.
244
230
 
245
- app_skeleton
231
+ merb_app:
246
232
  Rakefile
247
233
  README
248
234
  scripts
249
235
  test
250
- test_helper.rb
251
- fixtures
252
236
  spec
253
237
  unit
254
238
  plugins
data/Rakefile CHANGED
@@ -6,11 +6,16 @@ require 'rake/testtask'
6
6
  require 'spec/rake/spectask'
7
7
  require 'code_statistics'
8
8
  require 'fileutils'
9
- require File.dirname(__FILE__)+'/tools/rakehelp'
9
+ def __DIR__
10
+ File.dirname(__FILE__)
11
+ end
12
+
13
+ require __DIR__+'/tools/rakehelp'
10
14
  include FileUtils
11
15
 
16
+
12
17
  NAME = "merb"
13
- VERS = "0.0.8"
18
+ VERS = "0.0.9"
14
19
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
15
20
  RDOC_OPTS = ['--quiet', '--title', "Merb Documentation",
16
21
  "--opname", "index.html",
@@ -19,19 +24,15 @@ RDOC_OPTS = ['--quiet', '--title', "Merb Documentation",
19
24
  "--inline-source"]
20
25
 
21
26
  setup_clean [ "pkg", "lib/*.bundle", "*.gem",
22
- "doc", ".config", "examples/sample_app/dist/public/files/**/*"]
27
+ "doc", ".config", "examples/sample_app/dist/public/files/**/*", 'examples/sample_app/log/*']
23
28
 
24
29
 
25
30
  desc "Packages up Merb."
26
31
  task :default => [:package]
27
- task :package => [:really_clean, :clean, :rdoc]
32
+ task :merb => [:clean, :rdoc, :package]
28
33
 
29
34
  task :doc => [:rdoc]
30
35
 
31
- task :really_clean do
32
- rm_rf 'examples/sample_app/log/*'
33
- end
34
-
35
36
 
36
37
  Rake::RDocTask.new do |rdoc|
37
38
  rdoc.rdoc_dir = 'doc/rdoc'
@@ -59,22 +60,20 @@ spec = Gem::Specification.new do |s|
59
60
  s.add_dependency('mongrel')
60
61
  s.add_dependency('erubis')
61
62
  s.add_dependency('json')
62
- s.add_dependency('mime-types')
63
63
  s.required_ruby_version = '>= 1.8.4'
64
64
 
65
- s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{app,bin,test,lib,examples}/**/*")
65
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{bin,test,lib,examples}/**/*")
66
66
 
67
67
  s.require_path = "lib"
68
68
  s.bindir = "bin"
69
69
  end
70
70
 
71
71
  Rake::GemPackageTask.new(spec) do |p|
72
- p.need_tar = true
72
+ #p.need_tar = true
73
73
  p.gem_spec = spec
74
74
  end
75
75
 
76
76
  task :install do
77
- sh %{rake clean}
78
77
  sh %{rake package}
79
78
  sh %{sudo gem install pkg/#{NAME}-#{VERS}}
80
79
  end
@@ -90,6 +89,20 @@ task :doc_rforge do
90
89
  sh %{scp -r -p doc/rdoc/* ezmobius@rubyforge.org:/var/www/gforge-projects/merb}
91
90
  end
92
91
 
92
+
93
+ desc "Pack skeleton app as a tar.gz file"
94
+ task :skeleton do
95
+ require 'archive/tar/minitar'
96
+ include Archive::Tar
97
+ Find.find(File.join(__DIR__,'examples/skeleton')) do |f|
98
+ FileUtils.rm_rf(f) if /\.svn$/ =~ f
99
+ end
100
+ File.open(File.join(__DIR__,'examples/skeleton.tar'), 'wb') do |tar|
101
+ Dir.chdir 'examples/skeleton'
102
+ Minitar.pack('.', tar, true)
103
+ end
104
+ end
105
+
93
106
  desc 'Run unit tests'
94
107
  Rake::TestTask.new('test_unit') do |t|
95
108
  t.libs << 'test'
data/bin/merb CHANGED
@@ -1,227 +1,6 @@
1
1
  #!/usr/local/bin/ruby
2
- require 'rubygems'
3
-
4
- begin
5
- require 'fastthread'
6
- require 'thread'
7
- puts 'Using FastThread'
8
- rescue LoadError
9
- puts "not using FastThread"
10
- end
11
-
12
- begin
13
- require 'fjson'
14
- puts "using fjson"
15
- rescue LoadError
16
- require 'json'
17
- end
18
- require 'optparse'
19
- require 'ostruct'
20
- require 'fileutils'
21
- require 'yaml'
22
- require 'erubis'
23
-
24
- module Erubis
25
- class MEruby < Erubis::Eruby
26
- include PercentLineEnhancer
27
- include StringBufferEnhancer
28
- end
29
- end
30
-
31
- module Merb; end
32
-
33
- class Merb::Config
34
- def self.setup
35
- defaults = {
36
- :host => "0.0.0.0",
37
- :port => "4000",
38
- :allow_reloading => true,
39
- :merb_root => Dir.pwd,
40
- :template_ext => {:html => :herb, :js => :jerb, :xml => :xerb}
41
- }
42
- begin
43
- options = defaults.merge(YAML.load(Erubis::MEruby.new(IO.read("#{defaults[:merb_root]}/dist/conf/merb.yml")).result))
44
- rescue
45
- options = defaults
46
- end
47
-
48
- options
49
- end
50
- end
51
-
52
- class Merb::Server
53
-
54
- def self.merb_config
55
- options = Merb::Config.setup
56
-
57
- opts = OptionParser.new do |opts|
58
- opts.banner = "Usage: merb [fdcphmisl] [argument]"
59
- opts.define_head "Merb Mongrel+ Erb. Lightweight replacement for ActionPack"
60
- opts.separator '*'*80
61
- opts.separator 'If no flags are given, Merb starts in the foreground on port 4000'
62
- opts.separator '*'*80
63
-
64
- opts.on("-f", "--config-file FILENAME", "This flag is for adding extra config files for things like the upload progress module") do |config|
65
- options[:config] = config
66
- end
67
-
68
- opts.on("-d", "--daemonize", "This will run a single merb in the background") do |config|
69
- options[:daemonize] = true
70
- end
71
-
72
- opts.on("-c", "--cluster-nodes NUM_MERBS", "Number of merb daemons to run") do |nodes|
73
- options[:cluster] = nodes
74
- end
75
-
76
- opts.on("-p", "--port PORTNUM", "Port to run merb on, defaults to 4000") do |port|
77
- options[:port] = port
78
- end
79
-
80
- opts.on("-h", "--host HOSTNAME", "Host to bind to(default is all IP's)") do |host|
81
- options[:host] = host
82
- end
83
-
84
- opts.on("-m", "--merb-root MERB_ROOT", "the path to the MERB_ROOT for the app you want to run") do |merb_root|
85
- options[:merb_root] = File.expand_path(merb_root)
86
- end
87
-
88
- opts.on("-i", "--irb-console", "This flag will start merb in irb console mode. All your models and other classes will be available for you in an irb session.") do |console|
89
- options[:console] = true
90
- end
91
-
92
- opts.on("-s", "--session-drb-port PORTNUM", "This is the port number to run the drb daemon on for sessions and uplod progress monitoring.") do |drb_port|
93
- options[:session] = drb_port
94
- end
95
-
96
- opts.on("-l", "--log-level LEVEL", "Log levels can be set to any of these options: DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN") do |loglevel|
97
- options[:log_level] = loglevel
98
- end
99
-
100
- opts.on("-?", "--help", "Show this help message") do
101
- puts opts
102
- exit
103
- end
104
-
105
- end
106
-
107
- opts.parse!(@@merb_raw_opts)
108
-
109
-
110
- @@merb_opts = options
111
- puts %{Merb started with these options:}
112
- puts @@merb_opts.to_yaml; puts
113
- end
114
-
115
- def self.initialize_merb
116
- require 'merb'
117
- require @@merb_opts[:merb_root]+'/dist/conf/router.rb'
118
- require @@merb_opts[:merb_root]+'/dist/conf/merb_init.rb'
119
- end
120
-
121
- def self.run
122
- @@merb_raw_opts = ARGV
123
- merb_config
124
-
125
- @@merb_opts[:dist_root] = @@merb_opts[:merb_root]+'/dist'
126
- $LOAD_PATH.unshift( File.join(@@merb_opts[:dist_root] , '/app/controllers') )
127
- $LOAD_PATH.unshift( File.join(@@merb_opts[:dist_root] , '/app/models') )
128
- $LOAD_PATH.unshift( File.join(@@merb_opts[:dist_root] , '/lib') )
129
-
130
- if @@merb_opts[:console]
131
- initialize_merb
132
- ARGV.clear # Avoid passing args to IRB
133
- require 'irb'
134
- require 'irb/completion'
135
- def exit
136
- exit!
137
- end
138
- if File.exists? ".irbrc"
139
- ENV['IRBRC'] = ".irbrc"
140
- end
141
- IRB.start
142
- exit!
143
- end
144
-
145
- if @@merb_opts[:session]
146
- start(@@merb_opts[:session], :drbserver_start)
147
- end
148
-
149
- if @@merb_opts[:cluster]
150
- delete_pidfiles
151
- @@merb_opts[:port].to_i.upto(@@merb_opts[:port].to_i+@@merb_opts[:cluster].to_i-1) do |port|
152
- puts "Starting merb server on port: #{port}"
153
- start(port)
154
- end
155
- elsif @@merb_opts[:daemonize]
156
- delete_pidfiles(@@merb_opts[:port])
157
- start(@@merb_opts[:port])
158
- else
159
- initialize_merb
160
- trap('TERM') { exit }
161
- mongrel_start(@@merb_opts[:port])
162
- end
163
-
164
- end
165
-
166
- def self.store_pid(pid,port)
167
- File.open("#{@@merb_opts[:merb_root]}/log/merb.#{port}.pid", 'w'){|f| f.write("#{Process.pid}\n")}
168
- end
169
-
170
- def self.start(port,what=:mongrel_start)
171
- fork do
172
- Process.setsid
173
- exit if fork
174
- if what == :mongrel_start
175
- store_pid(Process.pid, port)
176
- else
177
- store_pid(Process.pid, "drb.#{port}")
178
- end
179
- Dir.chdir @@merb_opts[:merb_root]
180
- File.umask 0000
181
- STDIN.reopen "/dev/null"
182
- STDOUT.reopen "/dev/null", "a"
183
- STDERR.reopen STDOUT
184
- trap("TERM") { exit }
185
- send(what, port)
186
- end
187
- end
188
-
189
- def self.delete_pidfiles(portor_star='*')
190
- Dir["#{@@merb_opts[:merb_root]}/log/merb.#{portor_star}.pid"].each do |pid|
191
- FileUtils.rm(pid) rescue nil
192
- end
193
- end
194
-
195
- def self.drbserver_start(port)
196
- puts "Starting merb drb server on port: #{port}"
197
- require 'merb/session/merb_drb_server'
198
- DRb.start_service("druby://#{@@merb_opts[:host]}:#{port}", Merb::DRbSession.setup)
199
- DRb.thread.join
200
- end
201
-
202
- def self.mongrel_start(port)
203
- @@merb_opts[:port] = port
204
- initialize_merb
205
-
206
- config = Mongrel::Configurator.new :host => (@@merb_opts[:host]||"0.0.0.0"), :port => (port ||4000) do
207
- config = YAML.load(Erubis::Eruby.new(IO.read(File.expand_path(@@merb_opts[:config]))).result) if @@merb_opts[:config]
208
- listener do
209
- uri( "/", :handler => MerbUploadHandler.new(config), :in_front => true) if @@merb_opts[:config]
210
- uri "/", :handler => MerbHandler.new(@@merb_opts[:dist_root]+'/public')
211
- uri "/favicon.ico", :handler => Mongrel::Error404Handler.new("")
212
- end
213
-
214
- trap("INT") { stop }
215
- run
216
- end
217
- config.join
218
- end
219
-
220
- def self.config
221
- @@merb_opts
222
- end
223
-
224
- end
225
2
 
3
+ require 'rubygems'
4
+ require 'merb/merb_server'
226
5
 
227
6
  Merb::Server.run