merb 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README +64 -80
- data/Rakefile +25 -12
- data/bin/merb +2 -223
- data/examples/README_EXAMPLES +10 -0
- data/examples/skeleton.tar +0 -0
- data/lib/merb.rb +48 -21
- data/lib/merb/core_ext.rb +12 -2
- data/lib/merb/core_ext/merb_class.rb +21 -21
- data/lib/merb/core_ext/merb_kernel.rb +60 -0
- data/lib/merb/core_ext/merb_object.rb +14 -0
- data/lib/merb/core_ext/merb_string.rb +3 -13
- data/lib/merb/generators/merb_app/merb_app.rb +33 -0
- data/lib/merb/merb_constants.rb +7 -0
- data/lib/merb/merb_controller.rb +31 -23
- data/lib/merb/merb_drb_server.rb +6 -60
- data/lib/merb/merb_exceptions.rb +162 -2
- data/lib/merb/merb_handler.rb +8 -19
- data/lib/merb/merb_mailer.rb +60 -0
- data/lib/merb/merb_router.rb +1 -1
- data/lib/merb/merb_server.rb +240 -0
- data/lib/merb/merb_upload_handler.rb +1 -1
- data/lib/merb/merb_view_context.rb +11 -6
- data/lib/merb/mixins/basic_authentication_mixin.rb +11 -13
- data/lib/merb/mixins/controller_mixin.rb +12 -6
- data/lib/merb/mixins/form_control_mixin.rb +94 -0
- data/lib/merb/mixins/render_mixin.rb +50 -24
- data/lib/merb/mixins/view_context_mixin.rb +122 -0
- data/lib/merb/session/merb_ar_session.rb +13 -14
- data/lib/merb/session/merb_memory_session.rb +105 -0
- metadata +13 -132
- data/examples/app_skeleton/Rakefile +0 -82
- data/examples/app_skeleton/dist/app/helpers/global_helper.rb +0 -6
- data/examples/app_skeleton/dist/conf/merb.yml +0 -11
- data/examples/app_skeleton/dist/conf/merb_init.rb +0 -16
- data/examples/app_skeleton/dist/conf/mup.conf +0 -5
- data/examples/app_skeleton/dist/conf/router.rb +0 -19
- data/examples/app_skeleton/scripts/merb_stop +0 -13
- data/examples/app_skeleton/scripts/new_migration +0 -21
- data/examples/app_skeleton/test/test_helper.rb +0 -1
- data/examples/sample_app/Rakefile +0 -82
- data/examples/sample_app/dist/app/controllers/files.rb +0 -31
- data/examples/sample_app/dist/app/controllers/posts.rb +0 -71
- data/examples/sample_app/dist/app/controllers/test.rb +0 -40
- data/examples/sample_app/dist/app/helpers/global_helper.rb +0 -7
- data/examples/sample_app/dist/app/helpers/posts_helper.rb +0 -4
- data/examples/sample_app/dist/app/models/comment.rb +0 -3
- data/examples/sample_app/dist/app/models/post.rb +0 -4
- data/examples/sample_app/dist/app/views/files/progress.jerb +0 -3
- data/examples/sample_app/dist/app/views/files/start.herb +0 -62
- data/examples/sample_app/dist/app/views/files/upload.herb +0 -6
- data/examples/sample_app/dist/app/views/layout/application.herb +0 -61
- data/examples/sample_app/dist/app/views/layout/foo.herb +0 -6
- data/examples/sample_app/dist/app/views/posts/_comments.herb +0 -11
- data/examples/sample_app/dist/app/views/posts/comment.jerb +0 -1
- data/examples/sample_app/dist/app/views/posts/list.herb +0 -5
- data/examples/sample_app/dist/app/views/posts/new.herb +0 -37
- data/examples/sample_app/dist/app/views/posts/show.herb +0 -37
- data/examples/sample_app/dist/app/views/posts/xml_test.xerb +0 -3
- data/examples/sample_app/dist/app/views/shared/_test.herb +0 -1
- data/examples/sample_app/dist/app/views/test/foo.herb +0 -2
- data/examples/sample_app/dist/app/views/test/hello.herb +0 -5
- data/examples/sample_app/dist/app/views/test/json.jerb +0 -1
- data/examples/sample_app/dist/conf/merb.yml +0 -11
- data/examples/sample_app/dist/conf/merb_init.rb +0 -24
- data/examples/sample_app/dist/conf/mup.conf +0 -5
- data/examples/sample_app/dist/conf/router.rb +0 -19
- 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 +0 -975
- data/examples/sample_app/dist/public/javascripts/mup.js +0 -113
- data/examples/sample_app/dist/public/javascripts/prototype.js +0 -2264
- data/examples/sample_app/dist/public/stylesheets/merb.css +0 -277
- data/examples/sample_app/dist/public/test.html +0 -5
- data/examples/sample_app/dist/schema/migrations/001_add_comments_to_posts.rb +0 -22
- data/examples/sample_app/dist/schema/migrations/002_add_sessions_table.rb +0 -14
- data/examples/sample_app/dist/schema/schema.rb +0 -28
- data/examples/sample_app/foo.txt +0 -0
- data/examples/sample_app/log/merb.4000.pid +0 -1
- data/examples/sample_app/script/merb_stop +0 -13
- data/examples/sample_app/script/new_migration +0 -21
- data/examples/sample_app/test/test_helper.rb +0 -1
- data/lib/merb/mixins/javascript_mixin.rb +0 -147
- data/lib/merb/session/merb_drb_session.rb +0 -65
- data/test/test_helper.rb +0 -1
- 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
|
data/test/test_helper.rb
DELETED
@@ -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
|