ruil 0.0.1 → 0.1.0
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.rdoc +6 -2
- data/VERSION +1 -1
- data/lib/ruil/html_responder.rb +88 -0
- data/lib/ruil/json_responder.rb +35 -0
- data/lib/ruil/mongo_resource.rb +128 -0
- data/lib/ruil/path_info_parser.rb +50 -0
- data/lib/ruil/redirector.rb +33 -0
- data/lib/ruil/register.rb +45 -0
- data/lib/ruil/request.rb +49 -0
- data/lib/ruil/resource.rb +109 -68
- data/lib/ruil/session_widget.rb +43 -0
- data/lib/ruil/static_resource.rb +63 -0
- data/lib/ruil/widget.rb +39 -0
- data/lib/ruil.rb +5 -0
- data/rakefile +25 -28
- data/spec/html_responder_spec.rb +50 -0
- data/spec/json_responder_spec.rb +30 -0
- data/spec/path_info_parser_spec.rb +15 -0
- data/spec/redirector_spec.rb +22 -0
- data/spec/register_spec.rb +43 -0
- data/spec/request_spec.rb +26 -0
- data/spec/resource_spec.rb +31 -0
- data/spec/static_resource_spec.rb +38 -0
- metadata +40 -19
- data/.gitignore +0 -5
- data/lib/ruil/delegator.rb +0 -42
- data/lib/ruil/tenjin_template.rb +0 -20
- data/test/delegator_test.rb +0 -50
- data/test/resource_test.rb +0 -23
- data/test/templates/a.desktop.html +0 -1
- data/test/templates/a.mobile.html +0 -1
- data/test/templates/b.desktop.html +0 -1
- data/test/templates/b.mobile.html +0 -1
data/test/delegator_test.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'ruil/delegator'
|
3
|
-
require 'ruil/resource'
|
4
|
-
require 'ruil/tenjin_template'
|
5
|
-
|
6
|
-
describe 'Delegator' do
|
7
|
-
|
8
|
-
before(:all) do
|
9
|
-
a_resource = Class.new(Ruil::Resource) do
|
10
|
-
def path_pattern
|
11
|
-
/^\/a/
|
12
|
-
end
|
13
|
-
def template_pattern
|
14
|
-
'a.*.html'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
b_resource = Class.new(Ruil::Resource) do
|
18
|
-
def path_pattern
|
19
|
-
/^\/b/
|
20
|
-
end
|
21
|
-
def template_pattern
|
22
|
-
'b.*.html'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
user_agent_parser = Proc.new do |env|
|
26
|
-
/Mobile/ === env['HTTP_USER_AGENT'] ? :mobile : :desktop
|
27
|
-
end
|
28
|
-
template_dir = File.join(File.dirname(__FILE__), 'templates')
|
29
|
-
@delegator = Ruil::Delegator.new(user_agent_parser, template_dir, Ruil::TenjinTemplate) do |d|
|
30
|
-
d.add_resource a_resource
|
31
|
-
d.add_resource b_resource
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'delegate a request' do
|
36
|
-
env = { 'PATH_INFO' => '/a', 'HTTP_USER_AGENT' => 'Mobile' }
|
37
|
-
exp = [200, {"Content-Type" => "text/html"}, ["a mobile\n"]]
|
38
|
-
@delegator.call(env).should == exp
|
39
|
-
env = { 'PATH_INFO' => '/a', 'HTTP_USER_AGENT' => 'Desktop' }
|
40
|
-
exp = [200, {"Content-Type" => "text/html"}, ["a desktop\n"]]
|
41
|
-
@delegator.call(env).should == exp
|
42
|
-
env = { 'PATH_INFO' => '/b', 'HTTP_USER_AGENT' => 'Desktop' }
|
43
|
-
exp = [200, {"Content-Type" => "text/html"}, ["b desktop\n"]]
|
44
|
-
@delegator.call(env).should == exp
|
45
|
-
env = { 'PATH_INFO' => '/c', 'HTTP_USER_AGENT' => 'Desktop' }
|
46
|
-
exp =[ 302, {"Content-Type" => "text/html", 'Location'=> '/' }, [] ]
|
47
|
-
@delegator.call(env).should == exp
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
data/test/resource_test.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'ruil/resource'
|
3
|
-
|
4
|
-
describe 'Resource' do
|
5
|
-
|
6
|
-
before(:all) do
|
7
|
-
user_agent_parser = Proc.new do |env|
|
8
|
-
/Mobile/ === env['HTTP_USER_AGENT'] ? :mobile : :desktop
|
9
|
-
end
|
10
|
-
@resource = Ruil::Resource.new(user_agent_parser) do |r|
|
11
|
-
r.add_template :mobile, Proc.new { |opt| opt[:template_key].to_s }
|
12
|
-
r.add_template :desktop, Proc.new { |opt| opt[:template_key].to_s }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should display a content' do
|
17
|
-
env = { 'HTTP_USER_AGENT' => 'Mobile' }
|
18
|
-
@resource.call(env).should == [200, {"Content-Type" => "text/html"}, ['mobile']]
|
19
|
-
env = { 'HTTP_USER_AGENT' => 'Desktop' }
|
20
|
-
@resource.call(env).should == [200, {"Content-Type" => "text/html"}, ['desktop']]
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
a #{@template_key}
|
@@ -1 +0,0 @@
|
|
1
|
-
a #{@template_key}
|
@@ -1 +0,0 @@
|
|
1
|
-
b #{@template_key}
|
@@ -1 +0,0 @@
|
|
1
|
-
b #{@template_key}
|