merb 0.0.7 → 0.0.8

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 (62) hide show
  1. data/README +66 -31
  2. data/Rakefile +3 -1
  3. data/bin/merb +47 -13
  4. data/examples/app_skeleton/Rakefile +4 -3
  5. data/examples/app_skeleton/dist/app/helpers/global_helper.rb +6 -0
  6. data/examples/app_skeleton/dist/conf/merb.yml +11 -0
  7. data/examples/app_skeleton/dist/conf/mup.conf +5 -0
  8. data/examples/app_skeleton/dist/conf/router.rb +1 -3
  9. data/examples/app_skeleton/scripts/merb_stop +10 -2
  10. data/examples/sample_app/Rakefile +3 -3
  11. data/examples/sample_app/dist/app/controllers/files.rb +3 -3
  12. data/examples/sample_app/dist/app/controllers/posts.rb +25 -23
  13. data/examples/sample_app/dist/app/controllers/test.rb +7 -3
  14. data/examples/sample_app/dist/app/helpers/global_helper.rb +7 -0
  15. data/examples/sample_app/dist/app/helpers/posts_helper.rb +4 -0
  16. data/examples/sample_app/dist/app/views/layout/application.herb +5 -4
  17. data/examples/sample_app/dist/app/views/layout/foo.herb +1 -1
  18. data/examples/sample_app/dist/app/views/posts/new.herb +9 -2
  19. data/examples/sample_app/dist/app/views/shared/_test.herb +1 -0
  20. data/examples/sample_app/dist/conf/merb.yml +7 -7
  21. data/examples/sample_app/dist/conf/merb_init.rb +8 -1
  22. data/examples/sample_app/dist/conf/mup.conf +5 -11
  23. data/examples/sample_app/dist/conf/router.rb +1 -1
  24. data/examples/sample_app/dist/public/test.html +5 -0
  25. data/examples/sample_app/dist/schema/migrations/002_add_sessions_table.rb +1 -1
  26. data/examples/sample_app/dist/schema/schema.rb +1 -1
  27. data/examples/sample_app/log/merb.4000.pid +1 -0
  28. data/lib/merb.rb +35 -17
  29. data/lib/merb/core_ext.rb +2 -0
  30. data/lib/merb/{merb_class_extensions.rb → core_ext/merb_class.rb} +42 -0
  31. data/lib/merb/core_ext/merb_enumerable.rb +7 -0
  32. data/lib/merb/{merb_utils.rb → core_ext/merb_hash.rb} +1 -78
  33. data/lib/merb/core_ext/merb_kernel.rb +16 -0
  34. data/lib/merb/core_ext/merb_module.rb +10 -0
  35. data/lib/merb/core_ext/merb_numeric.rb +20 -0
  36. data/lib/merb/core_ext/merb_object.rb +6 -0
  37. data/lib/merb/core_ext/merb_string.rb +40 -0
  38. data/lib/merb/core_ext/merb_symbol.rb +12 -0
  39. data/lib/merb/merb_constants.rb +18 -0
  40. data/lib/merb/merb_controller.rb +150 -76
  41. data/lib/merb/{session/merb_drb_server.rb → merb_drb_server.rb} +13 -46
  42. data/lib/merb/merb_exceptions.rb +4 -0
  43. data/lib/merb/merb_handler.rb +29 -17
  44. data/lib/merb/merb_request.rb +95 -0
  45. data/lib/merb/merb_upload_handler.rb +46 -0
  46. data/lib/merb/merb_upload_progress.rb +48 -0
  47. data/lib/merb/merb_view_context.rb +46 -0
  48. data/lib/merb/merb_yaml_store.rb +31 -0
  49. data/lib/merb/mixins/basic_authentication_mixin.rb +2 -2
  50. data/lib/merb/mixins/controller_mixin.rb +24 -75
  51. data/lib/merb/mixins/erubis_capture_mixin.rb +84 -0
  52. data/lib/merb/mixins/javascript_mixin.rb +103 -19
  53. data/lib/merb/mixins/merb_status_codes.rb +59 -0
  54. data/lib/merb/mixins/render_mixin.rb +114 -40
  55. data/lib/merb/mixins/responder_mixin.rb +2 -1
  56. data/lib/merb/session/merb_ar_session.rb +120 -0
  57. data/lib/merb/session/merb_drb_session.rb +0 -6
  58. data/lib/merb/vendor/paginator/paginator.rb +102 -99
  59. metadata +44 -8
  60. data/examples/sample_app/script/startdrb +0 -8
  61. data/lib/merb/session/merb_session.rb +0 -64
  62. data/lib/mutex_hotfix.rb +0 -34
@@ -1,8 +1,7 @@
1
-
2
1
  class Test < Merb::Controller
3
2
 
4
- before :authenticate
5
- before lambda{|c| puts 'lambda filter called'}
3
+ #before :authenticate
4
+ #before lambda{|c| puts 'lambda filter called'}
6
5
 
7
6
  def bfilter
8
7
  puts "Filter Called!"
@@ -24,6 +23,11 @@ class Test < Merb::Controller
24
23
  render_js
25
24
  end
26
25
 
26
+ def rails
27
+ puts session.inspect
28
+ session[:foo]
29
+ end
30
+
27
31
  def foo
28
32
  @args = params
29
33
  render
@@ -0,0 +1,7 @@
1
+ module Merb
2
+ module GlobalHelper
3
+ end
4
+ end
5
+
6
+
7
+
@@ -0,0 +1,4 @@
1
+ module Merb
2
+ module PostsHelper
3
+ end
4
+ end
@@ -4,8 +4,8 @@
4
4
  <head>
5
5
  <title>Merb: Mongrel + Erb</title>
6
6
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
7
- <%= require_css :merb %>
8
- <%= require_js :prototype, :effects %>
7
+ <%= css_include_tag :merb %>
8
+ <%= js_include_tag :prototype, :effects %>
9
9
  </head>
10
10
 
11
11
  <body>
@@ -33,10 +33,11 @@
33
33
  <ul>
34
34
  <li><img src="/images/louiecon.gif" /></li>
35
35
  </ul>
36
+ <%= catch_content :sidebar %>
36
37
  </div>
37
38
 
38
- <%= @layout_content %>
39
-
39
+ <%= catch_content :layout %>
40
+
40
41
  <div class="maintext3">
41
42
  <div class="splitleft">
42
43
  <p>This is a split left box in the split left class.</p>
@@ -1,6 +1,6 @@
1
1
  <html>
2
2
  <title>Foo.rhtml</title>
3
3
  <body>
4
- <%= @layout_content %>
4
+ <%= @_layout_content %>
5
5
  </body>
6
6
  </html>
@@ -1,6 +1,4 @@
1
1
 
2
-
3
-
4
2
  <h2>Make a post doofus.</h2>
5
3
 
6
4
  <form action="/posts/create" method="post">
@@ -28,3 +26,12 @@
28
26
  <input name="commit" type="submit" value="Submit" />
29
27
  </p>
30
28
  </form>
29
+
30
+ <pre>
31
+ <%= "session: #{session.to_yaml}" %>
32
+ </pre>
33
+
34
+
35
+ <% throw_content :sidebar do %>
36
+ <h3>This is the sidebar thrown to the layout.</h3>
37
+ <% end %>
@@ -0,0 +1 @@
1
+ <h1>Nested Partial works!</h1>
@@ -1,11 +1,11 @@
1
1
  ---
2
- :host: 0.0.0.0
2
+ :host: 127.0.0.1
3
3
  :port: "4000"
4
- :allow_reloading: true
5
- :basic_auth:
6
- :username: ezra
7
- :password: test
8
- :domain: localhost
4
+ :allow_reloading: false
5
+ #:sql_session: true
6
+ #:basic_auth:
7
+ # :username: ezra
8
+ # :password: test
9
+ # :domain: localhost
9
10
  #:daemonize: true
10
11
  #:cluster: 3
11
- #:session: true
@@ -14,4 +14,11 @@ ActiveRecord::Base.establish_connection(
14
14
  )
15
15
  ActiveRecord::Base.verification_timeout = 14400
16
16
 
17
- Dir[DIST_ROOT+"/app/models/*.rb"].each { |m| require m }
17
+ Dir[DIST_ROOT+"/app/**/*.rb"].each { |m| require m }
18
+ Dir[DIST_ROOT+"/plugins/*/init.rb"].each { |m| require m }
19
+
20
+ module Merb
21
+ class ViewContext
22
+ include Merb::GlobalHelper
23
+ end
24
+ end
@@ -1,11 +1,5 @@
1
- uri "/",
2
- :handler => plugin("/handlers/upload", :path_info => '/files/upload'),
3
- :in_front => true,
4
- :frequency => 1
5
-
6
- #uri "/",
7
- # :handler => plugin("/handlers/upload",
8
- # :path_info => '/files/upload',
9
- # :frequency => 1,
10
- # :drb => 'druby://0.0.0.0:2999'),
11
- # :in_front => true
1
+ # upload progress conf
2
+ ---
3
+ #:drb: true
4
+ :path_info: /files/upload
5
+ :frequency: 2
@@ -15,5 +15,5 @@ Merb::RouteMatcher.prepare do |r|
15
15
  r.add '/bar/:bar_id/baz/:id', :controller => 'Test', :action => 'foo'
16
16
  r.add '/:controller/:action/:id'
17
17
  r.add '/bar/:*rest', :controller => 'Test', :action => 'glob'
18
- r.add '', :controller => 'posts', :action =>'index'
18
+ r.add '', :controller => 'posts', :action =>'list'
19
19
  end
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ <h1>Static cached page!</h1>
4
+ </body>
5
+ </html>
@@ -2,7 +2,7 @@ class AddSessionsTable < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :sessions, :force => true do |t|
4
4
  t.column :id, :integer, :null => false
5
- t.column :sess_id, :string, :limit => 32
5
+ t.column :session_id, :string, :limit => 32
6
6
  t.column :created_at, :datetime
7
7
  t.column :data, :text
8
8
  end
@@ -20,7 +20,7 @@ ActiveRecord::Schema.define(:version => 2) do
20
20
  end
21
21
 
22
22
  create_table "sessions", :force => true do |t|
23
- t.column "sess_id", :string, :limit => 32
23
+ t.column "session_id", :string, :limit => 32
24
24
  t.column "created_at", :datetime
25
25
  t.column "data", :text
26
26
  end
@@ -3,9 +3,11 @@ require 'mongrel'
3
3
  require 'fileutils'
4
4
  require 'erubis'
5
5
  require 'logger'
6
+ require 'mime/types'
7
+
6
8
 
7
9
  module Merb
8
- VERSION='0.0.7' unless defined?VERSION
10
+ VERSION='0.0.8' unless defined?VERSION
9
11
  class Server
10
12
  def self.config
11
13
  @@merb_opts ||= {}
@@ -17,25 +19,10 @@ class MerbControllerError < RuntimeError; end
17
19
 
18
20
  MERB_FRAMEWORK_ROOT = File.dirname(__FILE__)
19
21
 
20
- begin
21
- require 'thread'
22
- require 'fastthread'
23
- puts 'Using FastThread'
24
- rescue LoadError
25
- require 'mutex_hotfix'
26
- end
27
-
28
- begin
29
- require 'fjson'
30
- puts "using fjson"
31
- rescue LoadError
32
- require 'json'
33
- end
34
-
35
22
  MERB_ROOT = Merb::Server.config[:merb_root] || Dir.pwd
36
23
  DIST_ROOT = Merb::Server.config[:dist_root] || Dir.pwd+'/dist'
37
24
 
38
- MERB_LOGGER = Logger.new("#{MERB_ROOT}/log/merb.log")
25
+ MERB_LOGGER = Logger.new("#{MERB_ROOT}/log/merb.#{Merb::Server.config[:port]}.log")
39
26
  # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
40
27
  MERB_LOGGER.level = case (Merb::Server.config[:log_level].downcase rescue '')
41
28
  when 'debug'
@@ -54,5 +41,36 @@ MERB_LOGGER.level = case (Merb::Server.config[:log_level].downcase rescue '')
54
41
  Logger::INFO
55
42
  end
56
43
 
44
+ corelib = File.join(File.dirname(__FILE__), 'merb/core_ext')
45
+ Dir.entries(corelib).sort.each {|fn| require File.join(corelib, fn) if fn =~ /\.rb$/}
57
46
  lib = File.join(File.dirname(__FILE__), 'merb')
58
47
  Dir.entries(lib).sort.each {|fn| require File.join(lib, fn) if fn =~ /\.rb$/}
48
+
49
+ class Merb::Controller
50
+ if Merb::Server.config[:session]
51
+ require "drb"
52
+ DRb.start_service('druby://localhost:0')
53
+ Merb.const_set :DRbSession, DRbObject.new(nil, "druby://#{Merb::Server.config[:host]}:#{Merb::Server.config[:session]}")
54
+ require "merb/session/merb_drb_session"
55
+ include ::Merb::SessionMixin
56
+ puts "drb session mixed in"
57
+ end
58
+
59
+ if Merb::Server.config[:sql_session]
60
+ puts "ActiveRecord session mixed in"
61
+ begin
62
+ require 'action_controller/flash'
63
+ puts "Rails session compatibilty on."
64
+ rescue LoadError
65
+ puts "Rails session compatibilty disabled. If you need this then install the actionpack gem"
66
+ end
67
+ require "merb/session/merb_ar_session"
68
+ include ::Merb::SessionMixin
69
+ end
70
+
71
+ if Merb::Server.config[:basic_auth]
72
+ require "merb/mixins/basic_authentication_mixin"
73
+ include ::Merb::Authentication
74
+ puts "Basic Authentication mixed in"
75
+ end
76
+ end
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__)+'/core_ext/merb_kernel'
2
+ aquire File.dirname(__FILE__)+'/core_ext/*'
@@ -1,4 +1,46 @@
1
1
  class Class # :nodoc:
2
+
3
+ def cattr_reader(*syms)
4
+ syms.flatten.each do |sym|
5
+ class_eval(<<-EOS, __FILE__, __LINE__)
6
+ unless defined? @@#{sym}
7
+ @@#{sym} = nil
8
+ end
9
+
10
+ def self.#{sym}
11
+ @@#{sym}
12
+ end
13
+
14
+ def #{sym}
15
+ @@#{sym}
16
+ end
17
+ EOS
18
+ end
19
+ end
20
+
21
+ def cattr_writer(*syms)
22
+ syms.flatten.each do |sym|
23
+ class_eval(<<-EOS, __FILE__, __LINE__)
24
+ unless defined? @@#{sym}
25
+ @@#{sym} = nil
26
+ end
27
+
28
+ def self.#{sym}=(obj)
29
+ @@#{sym} = obj
30
+ end
31
+
32
+ def #{sym}=(obj)
33
+ @@#{sym} = obj
34
+ end
35
+ EOS
36
+ end
37
+ end
38
+
39
+ def cattr_accessor(*syms)
40
+ cattr_reader(*syms)
41
+ cattr_writer(*syms)
42
+ end
43
+
2
44
  def meta_reader(*syms)
3
45
  syms.each do |sym|
4
46
  class_eval <<-EOS
@@ -0,0 +1,7 @@
1
+ module Enumerable
2
+ def injecting(s)
3
+ inject(s) do |k, i|
4
+ yield(k, i); k
5
+ end
6
+ end
7
+ end
@@ -1,79 +1,3 @@
1
- class String
2
-
3
- # reloads controller classes on each request if
4
- # :allow_reloading is set to true in the config
5
- # file or command line options.
6
- def import
7
- if Merb::Server.config[:allow_reloading]
8
- Object.send(:remove_const, self.camel_case.intern) rescue nil
9
- load(self.snake_case + '.rb')
10
- else
11
- require(self.snake_case)
12
- end
13
- end
14
-
15
- # "FooBar".snake_case #=> "foo_bar"
16
- def snake_case
17
- return self unless self =~ %r/[A-Z]/
18
- self.reverse.scan(%r/[A-Z]+|[^A-Z]*[A-Z]+?/).reverse.map{|word| word.reverse.downcase}.join '_'
19
- end
20
-
21
- # "foo_bar".camel_case #=> "FooBar"
22
- def camel_case
23
- return self if self =~ %r/[A-Z]/ and self !~ %r/_/
24
- words = self.strip.split %r/\s*_+\s*/
25
- words.map!{|w| w.downcase.sub(%r/^./){|c| c.upcase}}
26
- words.join
27
- end
28
-
29
- # Concatenates a path
30
- def /(o)
31
- File.join(self, o.to_s)
32
- end
33
-
34
- end
35
-
36
-
37
- module Enumerable
38
- def injecting(s)
39
- inject(s) do |k, i|
40
- yield(k, i); k
41
- end
42
- end
43
- end
44
-
45
- class Numeric
46
- def to_currency( pre_symbol='$', thousands=',', decimal='.',
47
- post_symbol=nil )
48
- "#{pre_symbol}#{
49
- ( "%.2f" % self ).gsub(
50
- /(\d)(?=(?:\d{3})+(?:$|\.))/,
51
- "\\1#{thousands}"
52
- )
53
- }#{post_symbol}"
54
- end
55
- end
56
-
57
- class Symbol
58
-
59
- # faster Symbol#to_s to speed up routing.
60
- def to_s
61
- @str_rep ||= id2name.freeze
62
- end
63
-
64
- # ["foo", "bar"].map &:reverse #=> ['oof', 'rab']
65
- def to_proc
66
- Proc.new{|*args| args.shift.__send__(self, *args)}
67
- end
68
- end
69
-
70
- class Object
71
- def returning(value)
72
- yield(value)
73
- value
74
- end
75
- end
76
-
77
1
  class Hash
78
2
  def with_indifferent_access
79
3
  MerbHash.new(self)
@@ -150,5 +74,4 @@ class MerbHash < Hash
150
74
  def convert_value(value)
151
75
  value.is_a?(Hash) ? value.with_indifferent_access : value
152
76
  end
153
- end
154
-
77
+ end
@@ -0,0 +1,16 @@
1
+ module Kernel
2
+ # Example:
3
+ # aquire 'foo/bar/*'
4
+ # requires all files inside foo/bar - recursive
5
+ # can take multiple parameters
6
+ def aquire(*files)
7
+ files.each do |file|
8
+ require file if %w(rb so).any?{|f| File.file?("#{file}.#{f}")}
9
+ $:.each do |path|
10
+ Dir[File.join(path, file, '*.rb')].each do |file|
11
+ require file
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ class Module
2
+ def alias_method_chain(target, feature)
3
+ # Strip out punctuation on predicates or bang methods since
4
+ # e.g. target?_without_feature is not a valid method name.
5
+ aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
6
+ yield(aliased_target, punctuation) if block_given?
7
+ alias_method "#{aliased_target}_without_#{feature}#{punctuation}", target
8
+ alias_method target, "#{aliased_target}_with_#{feature}#{punctuation}"
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ class Numeric
2
+ def to_currency(pre_symbol='$', thousands=',', decimal='.', post_symbol=nil) #:nodoc:
3
+ "#{pre_symbol}#{("%.2f" % self ).gsub(/(\d)(?=(?:\d{3})+(?:$|\.))/,"\\1#{thousands}")}#{post_symbol}"
4
+ end
5
+
6
+ def microseconds() Float(self * (10 ** -6)) end
7
+ def milliseconds() Float(self * (10 ** -3)) end
8
+ def seconds() self end
9
+ def minutes() 60 * seconds end
10
+ def hours() 60 * minutes end
11
+ def days() 24 * hours end
12
+ def weeks() 7 * days end
13
+ def months() 30 * days end
14
+ def years() 365 * days end
15
+ def decades() 10 * years end
16
+
17
+ %w{ microseconds milliseconds seconds minutes hours days weeks months years decades
18
+ }.each{ |m| mm = m.chop; alias_method mm, m }
19
+
20
+ end