merb 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,65 +0,0 @@
1
- module Merb
2
-
3
- module SessionMixin
4
-
5
- def setup_session
6
- MERB_LOGGER.info("Setting up session")
7
- @session = Merb::Session.persist(cookies)
8
- @fingerprint_before = Marshal.dump(@session).hash
9
- end
10
-
11
- def finalize_session
12
- MERB_LOGGER.info("Finalize session")
13
- unless Marshal.dump(@session).hash == @fingerprint_before
14
- @session.save
15
- end
16
- @headers['Set-Cookie'] = @cookies.map { |k,v| "#{k}=#{escape(v)}; path=/" if v != @k[k] } - [nil]
17
- end
18
-
19
- end
20
-
21
- class Session
22
-
23
- attr_reader :sess_id
24
-
25
- def []=(k, v) # :nodoc:
26
- (@data||={})[k] = v rescue nil
27
- end
28
- def [](k) # :nodoc:
29
- @data[k] rescue nil
30
- end
31
-
32
- def initialize(sess_id,data={})
33
- @data = data || {}
34
- @sess_id = sess_id
35
- end
36
-
37
- def save
38
- Merb::DRbSession[@sess_id] = @data
39
- end
40
-
41
- RAND_CHARS = [*'A'..'Z'] + [*'0'..'9'] + [*'a'..'z']
42
-
43
- # Generates a new session ID and creates a row for the new session in the database.
44
- def self.generate(cookies)
45
- rand_max = RAND_CHARS.size
46
- sid = (0...32).inject("") { |ret,_| ret << RAND_CHARS[rand(rand_max)] }
47
- sess = Merb::DRbSession.create(:sess_id => sid, :data => {})
48
- cookies[:sess_id] = sid
49
- new(sid, sess)
50
- end
51
-
52
- # Gets the existing session based on the <tt>camping_sid</tt> available in cookies.
53
- # If none is found, generates a new session.
54
- def self.persist cookies
55
- if cookies[:sess_id]
56
- session = new(cookies[:sess_id], Merb::DRbSession[cookies[:sess_id]])
57
- end
58
- unless session
59
- session = Merb::Session.generate(cookies)
60
- end
61
- session
62
- end
63
- end
64
-
65
- end
@@ -1 +0,0 @@
1
- require 'test/unit'
@@ -1,46 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require File.dirname(__FILE__) + '/../../lib/merb/merb_router'
3
- require File.dirname(__FILE__) + '/../../lib/merb/merb_utils'
4
- require 'set'
5
- class RouteMatcherTest < Test::Unit::TestCase
6
-
7
- def assert_same_hash(hsh1, hsh2)
8
- assert_equal hsh1.keys.map(&:to_s).sort, hsh2.keys.map(&:to_s).sort
9
- assert_equal hsh1.values.map(&:to_s).sort, hsh2.values.map(&:to_s).sort
10
- end
11
-
12
- def setup
13
- Merb::RouteMatcher.prepare do |r|
14
- r.add '/foo/:bar/baz/:id', :controller => 'Test', :action => 'foo'
15
- r.add '/:controller/:action/:id'
16
- r.add '/bar/:*rest', :controller => 'Test', :action => 'glob'
17
- end
18
- end
19
-
20
- def test_compiled_statement
21
- r = Merb::RouteMatcher.new
22
- assert( r.compiled_statement.kind_of?(String))
23
- assert( r.compiled_statement =~ /lambda\{\|path/)
24
- assert( r.compiled_statement =~ /Regexp\.new/)
25
- assert( r.compiled_statement =~ /merge\(@sections\)/)
26
- end
27
-
28
- def test_route_matching
29
- routes = Merb::RouteMatcher.new
30
- assert_same_hash( {:controller=>"Test", :id =>"456", :bar =>"123", :action=>"foo"}, routes.route_request("/foo/123/baz/456"))
31
- routes = Merb::RouteMatcher.new
32
- assert_same_hash({:controller=>"upload", :id=>"12", :action=>"test"},routes.route_request( "/upload/test/12"))
33
- routes = Merb::RouteMatcher.new
34
- assert_same_hash({:controller=>"upload", :id=>nil, :action=>"index"},routes.route_request( "/upload"))
35
- routes = Merb::RouteMatcher.new
36
- assert_same_hash({:controller=>"nik", :action=>"nak", :id => nil},routes.route_request( "/nik/nak"))
37
- routes = Merb::RouteMatcher.new
38
- assert_same_hash({:controller=>"lots", :action=>"of", :id => "12"},routes.route_request( "/lots/of/12"))
39
- end
40
-
41
- def test_catch_all_glob_route
42
- routes = Merb::RouteMatcher.new
43
- assert_same_hash({:controller=>"Test", :action=>"glob", :rest => "hey/you/guys"},routes.route_request( "/bar/hey/you/guys"))
44
- end
45
-
46
- end