Pistos-ramaze 2008.09 → 2008.12
Sign up to get free protection for your applications and to get access to all the features.
- data/benchmark/run.rb +1 -1
- data/examples/app/blog/spec/blog.rb +2 -2
- data/examples/app/rapaste/spec/rapaste.rb +1 -1
- data/examples/app/rapaste/start.rb +2 -2
- data/examples/app/rapaste/view/view.xhtml +3 -0
- data/examples/app/todolist/spec/todolist.rb +1 -1
- data/examples/app/whywiki/spec/whywiki.rb +1 -1
- data/examples/app/wikore/spec/wikore.rb +1 -1
- data/examples/app/wikore/src/model.rb +1 -1
- data/examples/app/wiktacular/spec/wiktacular.rb +1 -1
- data/examples/app/wiktacular/src/model.rb +1 -1
- data/examples/basic/partial.rb +28 -0
- data/examples/helpers/httpdigest.rb +68 -10
- data/examples/misc/ramaise.rb +2 -2
- data/examples/templates/template_amrita2.rb +1 -1
- data/examples/templates/template_erubis.rb +1 -1
- data/examples/templates/template_ezamar.rb +1 -1
- data/examples/templates/template_haml.rb +2 -2
- data/examples/templates/template_liquid.rb +1 -1
- data/examples/templates/template_markaby.rb +2 -2
- data/examples/templates/template_nagoro.rb +1 -1
- data/examples/templates/template_redcloth.rb +1 -1
- data/examples/templates/template_remarkably.rb +2 -2
- data/examples/templates/template_tenjin.rb +1 -1
- data/examples/templates/template_xslt.rb +1 -1
- data/lib/proto/controller/init.rb +2 -1
- data/lib/proto/model/init.rb +3 -3
- data/lib/proto/public/dispatch.fcgi +2 -2
- data/lib/proto/spec/main.rb +3 -3
- data/lib/proto/start.rb +4 -0
- data/lib/ramaze/action/render.rb +6 -5
- data/lib/ramaze/action.rb +7 -1
- data/lib/ramaze/cache/file.rb +71 -0
- data/lib/ramaze/cache.rb +1 -0
- data/lib/ramaze/contrib/email.rb +2 -0
- data/lib/ramaze/contrib/facebook.rb +2 -2
- data/lib/ramaze/contrib/file_cache.rb +2 -64
- data/lib/ramaze/contrib/sequel/image.rb +1 -1
- data/lib/ramaze/contrib.rb +1 -1
- data/lib/ramaze/controller/resolve.rb +8 -3
- data/lib/ramaze/controller.rb +9 -1
- data/lib/ramaze/current/request.rb +85 -68
- data/lib/ramaze/current/session/hash.rb +7 -11
- data/lib/ramaze/current/session.rb +3 -5
- data/lib/ramaze/dispatcher/action.rb +2 -0
- data/lib/ramaze/dispatcher/file.rb +6 -1
- data/lib/ramaze/helper/aspect.rb +2 -2
- data/lib/ramaze/helper/form.rb +5 -2
- data/lib/ramaze/helper/formatting.rb +4 -0
- data/lib/ramaze/helper/gravatar.rb +18 -1
- data/lib/ramaze/helper/httpdigest.rb +57 -28
- data/lib/ramaze/helper/maruku.rb +2 -0
- data/lib/ramaze/helper/paginate.rb +2 -3
- data/lib/ramaze/helper/partial.rb +1 -1
- data/lib/ramaze/helper/redirect.rb +22 -4
- data/lib/ramaze/helper/user.rb +4 -4
- data/lib/ramaze/helper.rb +12 -4
- data/lib/ramaze/log/rotatinginformer.rb +168 -0
- data/lib/ramaze/option/holder.rb +3 -3
- data/lib/ramaze/option.rb +1 -1
- data/lib/ramaze/reloader/watch_inotify.rb +85 -0
- data/lib/ramaze/reloader/watch_stat.rb +58 -0
- data/lib/ramaze/reloader.rb +25 -41
- data/lib/ramaze/snippets/divide.rb +2 -0
- data/lib/ramaze/snippets/numeric/time.rb +1 -1
- data/lib/ramaze/snippets/object/__dir__.rb +3 -3
- data/lib/ramaze/snippets/object/acquire.rb +3 -6
- data/lib/ramaze/snippets/ramaze/acquire.rb +31 -0
- data/lib/ramaze/snippets/ramaze/deprecated.rb +2 -1
- data/lib/ramaze/spec/helper/mock_http.rb +6 -5
- data/lib/ramaze/template/ezamar/render_partial.rb +8 -0
- data/lib/ramaze/tool/mime.rb +1 -1
- data/lib/ramaze/tool/project_creator.rb +2 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze.rb +6 -0
- data/rake_tasks/coverage.rake +4 -5
- data/rake_tasks/spec.rake +6 -6
- data/ramaze.gemspec +769 -756
- data/spec/contrib/profiling.rb +2 -2
- data/spec/ramaze/action/file_cache.rb +1 -1
- data/spec/ramaze/action/layout.rb +1 -1
- data/spec/ramaze/controller/actionless_templates.rb +1 -1
- data/spec/ramaze/controller/resolve.rb +1 -1
- data/spec/ramaze/controller/template_resolving.rb +1 -1
- data/spec/ramaze/dispatcher/directory.rb +3 -3
- data/spec/ramaze/helper/aspect.rb +1 -1
- data/spec/ramaze/helper/partial.rb +1 -1
- data/spec/ramaze/localize.rb +1 -1
- data/spec/ramaze/rewrite.rb +1 -1
- data/spec/ramaze/template/amrita2.rb +1 -1
- data/spec/ramaze/template/erubis.rb +1 -1
- data/spec/ramaze/template/ezamar.rb +1 -1
- data/spec/ramaze/template/haml.rb +2 -2
- data/spec/ramaze/template/nagoro.rb +1 -1
- data/spec/ramaze/template/redcloth.rb +1 -1
- data/spec/ramaze/template/sass.rb +1 -1
- data/spec/ramaze/template/tenjin.rb +1 -1
- data/spec/ramaze/template.rb +3 -3
- data/spec/snippets/object/__dir__.rb +6 -0
- data/spec/snippets/{object → ramaze}/acquire.rb +24 -18
- metadata +15 -12
- data/lib/ramaze/contrib/auto_params/get_args.rb +0 -58
- data/lib/ramaze/contrib/auto_params.rb +0 -135
- data/spec/contrib/auto_params.rb +0 -121
- data/spec/snippets/divide.rb +0 -19
data/spec/contrib/profiling.rb
CHANGED
@@ -15,14 +15,14 @@ Ramaze::Log.loggers << Ramaze::Logger::Informer.new(output)
|
|
15
15
|
|
16
16
|
describe 'Profiling' do
|
17
17
|
behaves_like "http"
|
18
|
-
ramaze :public_root => __DIR__
|
18
|
+
ramaze :public_root => __DIR__(:public)
|
19
19
|
|
20
20
|
it "should profile" do
|
21
21
|
output = StringIO.new
|
22
22
|
Ramaze::Log.loggers << Ramaze::Logger::Informer.new(output)
|
23
23
|
|
24
24
|
get('/')
|
25
|
-
output.string.should =~ /Thread ID:\s
|
25
|
+
output.string.should =~ /Thread ID:\s-?\d+/
|
26
26
|
output.string.should =~ /Total:/
|
27
27
|
output.string.should =~ /self\s+total\s+self\s+wait\s+child\s+call/
|
28
28
|
end
|
@@ -19,7 +19,7 @@ end
|
|
19
19
|
describe "Testing Actionless Templates" do
|
20
20
|
behaves_like 'http'
|
21
21
|
ramaze :actionless_templates => false,
|
22
|
-
:view_root => __DIR__
|
22
|
+
:view_root => __DIR__(:view), :error_page => true
|
23
23
|
|
24
24
|
it "should not find template file for non existant method" do
|
25
25
|
get('/non_existant_method').status.should == 404
|
@@ -12,8 +12,8 @@ describe 'Dispatcher::Directory' do
|
|
12
12
|
/test/six.txt ]
|
13
13
|
|
14
14
|
@hierarchy.each do |path|
|
15
|
-
FileUtils.mkdir_p(__DIR__
|
16
|
-
FileUtils.touch(__DIR__
|
15
|
+
FileUtils.mkdir_p(__DIR__(:public, File.dirname(path)))
|
16
|
+
FileUtils.touch(__DIR__(:public, path))
|
17
17
|
end
|
18
18
|
|
19
19
|
def build_listing(path)
|
@@ -51,5 +51,5 @@ describe 'Dispatcher::Directory' do
|
|
51
51
|
check '/test', 'Directory listing of /test', files
|
52
52
|
end
|
53
53
|
|
54
|
-
FileUtils.rm_rf(__DIR__
|
54
|
+
FileUtils.rm_rf(__DIR__('public/test'))
|
55
55
|
end
|
data/spec/ramaze/localize.rb
CHANGED
data/spec/ramaze/rewrite.rb
CHANGED
@@ -7,7 +7,7 @@ spec_require 'ramaze/template/haml'
|
|
7
7
|
|
8
8
|
class TCTemplateHamlController < Ramaze::Controller
|
9
9
|
map :/
|
10
|
-
view_root __DIR__
|
10
|
+
view_root __DIR__(:haml)
|
11
11
|
engine :Haml
|
12
12
|
|
13
13
|
helper :link
|
@@ -22,7 +22,7 @@ end
|
|
22
22
|
|
23
23
|
class TCRamazeLocals < Ramaze::Controller
|
24
24
|
map '/locals'
|
25
|
-
view_root __DIR__
|
25
|
+
view_root __DIR__(:haml)
|
26
26
|
|
27
27
|
def output
|
28
28
|
render_template 'locals.haml', :abc => 'def'
|
data/spec/ramaze/template.rb
CHANGED
@@ -21,7 +21,7 @@ end
|
|
21
21
|
class TCTemplateController < Ramaze::Controller
|
22
22
|
map '/'
|
23
23
|
engine :TestTemplate
|
24
|
-
view_root __DIR__
|
24
|
+
view_root __DIR__('template/ramaze')
|
25
25
|
|
26
26
|
def index *args
|
27
27
|
end
|
@@ -32,7 +32,7 @@ end
|
|
32
32
|
|
33
33
|
class TCMultipleTemplateRoots < Ramaze::Controller
|
34
34
|
map '/multiple'
|
35
|
-
view_root __DIR__
|
35
|
+
view_root __DIR__('helper/view'), __DIR__('template/ezamar')
|
36
36
|
|
37
37
|
def sum
|
38
38
|
@num1, @num2 = 1, 2
|
@@ -49,7 +49,7 @@ class TCMultipleTemplateRoots < Ramaze::Controller
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe "testing ramaze template" do
|
52
|
-
ramaze :view_root => __DIR__
|
52
|
+
ramaze :view_root => __DIR__(:view)
|
53
53
|
|
54
54
|
def getpage page
|
55
55
|
content = Ramaze::Controller.handle(page)
|
@@ -5,4 +5,10 @@ describe '__DIR__' do
|
|
5
5
|
it 'should report the directory of the current file' do
|
6
6
|
__DIR__.should == File.dirname(File.expand_path(__FILE__))
|
7
7
|
end
|
8
|
+
|
9
|
+
should 'join passed arguments and prefix with directory of current file' do
|
10
|
+
__DIR__(:foo).should == File.join(File.dirname(File.expand_path(__FILE__)), 'foo')
|
11
|
+
__DIR__('foo/bar').should == File.join(File.dirname(File.expand_path(__FILE__)), 'foo/bar')
|
12
|
+
__DIR__(:foo, :bar).should == File.join(File.dirname(File.expand_path(__FILE__)), 'foo/bar')
|
13
|
+
end
|
8
14
|
end
|
@@ -1,11 +1,17 @@
|
|
1
1
|
require 'lib/ramaze/spec/helper/snippets'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
# Mock require to only record attempts
|
6
|
+
$required = []
|
7
|
+
|
8
|
+
module Ramaze
|
9
|
+
def self.require(name)
|
10
|
+
$required << name
|
7
11
|
end
|
12
|
+
end
|
8
13
|
|
14
|
+
describe 'Ramaze::acquire' do
|
9
15
|
before do
|
10
16
|
dir = 'tmp_dir_for_acquire'
|
11
17
|
FileUtils.mkdir_p(dir + '/sub')
|
@@ -15,43 +21,43 @@ describe 'acquire' do
|
|
15
21
|
FileUtils.touch("#{dir}/#{path}")
|
16
22
|
end
|
17
23
|
|
18
|
-
|
24
|
+
$required = []
|
19
25
|
end
|
20
26
|
|
21
27
|
it 'should not load a single file' do
|
22
|
-
acquire 'tmp_dir_for_acquire/foo'
|
23
|
-
|
28
|
+
Ramaze::acquire 'tmp_dir_for_acquire/foo'
|
29
|
+
$required.should == []
|
24
30
|
end
|
25
31
|
|
26
32
|
it 'should load dir' do
|
27
|
-
acquire 'tmp_dir_for_acquire/sub/*'
|
28
|
-
|
33
|
+
Ramaze::acquire 'tmp_dir_for_acquire/sub/*'
|
34
|
+
$required.should == %w[
|
29
35
|
tmp_dir_for_acquire/sub/baz.rb]
|
30
36
|
end
|
31
37
|
|
32
38
|
it 'should be aliased to acquire' do
|
33
|
-
acquire 'tmp_dir_for_acquire/sub/*'
|
34
|
-
|
39
|
+
Ramaze::acquire 'tmp_dir_for_acquire/sub/*'
|
40
|
+
$required.should.not.be.empty
|
35
41
|
end
|
36
42
|
|
37
43
|
it 'should load {so,rb}, not others' do
|
38
|
-
acquire 'tmp_dir_for_acquire/*'
|
39
|
-
|
44
|
+
Ramaze::acquire 'tmp_dir_for_acquire/*'
|
45
|
+
$required.sort.should == %w[
|
40
46
|
tmp_dir_for_acquire/bar.rb
|
41
47
|
tmp_dir_for_acquire/baz.so
|
42
48
|
tmp_dir_for_acquire/foo.rb]
|
43
49
|
end
|
44
50
|
|
45
51
|
it 'should use globbing' do
|
46
|
-
acquire 'tmp_dir_for_acquire/ba*'
|
47
|
-
|
52
|
+
Ramaze::acquire 'tmp_dir_for_acquire/ba*'
|
53
|
+
$required.sort.should == %w[
|
48
54
|
tmp_dir_for_acquire/bar.rb
|
49
55
|
tmp_dir_for_acquire/baz.so]
|
50
56
|
end
|
51
57
|
|
52
58
|
it 'should use recursive globbing' do
|
53
|
-
acquire 'tmp_dir_for_acquire/**/*'
|
54
|
-
|
59
|
+
Ramaze::acquire 'tmp_dir_for_acquire/**/*'
|
60
|
+
$required.sort.should == %w[
|
55
61
|
tmp_dir_for_acquire/bar.rb
|
56
62
|
tmp_dir_for_acquire/baz.so
|
57
63
|
tmp_dir_for_acquire/foo.rb
|
@@ -59,8 +65,8 @@ describe 'acquire' do
|
|
59
65
|
end
|
60
66
|
|
61
67
|
it 'should accept multiple arguments' do
|
62
|
-
acquire 'tmp_dir_for_acquire/*', 'tmp_dir_for_acquire/sub/*'
|
63
|
-
|
68
|
+
Ramaze::acquire 'tmp_dir_for_acquire/*', 'tmp_dir_for_acquire/sub/*'
|
69
|
+
$required.sort.should == %w[
|
64
70
|
tmp_dir_for_acquire/bar.rb
|
65
71
|
tmp_dir_for_acquire/baz.so
|
66
72
|
tmp_dir_for_acquire/foo.rb
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Pistos-ramaze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "2008.
|
4
|
+
version: "2008.12"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael 'manveru' Fellinger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-22 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -264,6 +264,7 @@ files:
|
|
264
264
|
- examples/basic/hello.rb
|
265
265
|
- examples/basic/layout.rb
|
266
266
|
- examples/basic/linking.rb
|
267
|
+
- examples/basic/partial.rb
|
267
268
|
- examples/basic/simple.rb
|
268
269
|
- examples/helpers
|
269
270
|
- examples/helpers/cache.rb
|
@@ -352,14 +353,12 @@ files:
|
|
352
353
|
- lib/ramaze/adapter/webrick.rb
|
353
354
|
- lib/ramaze/cache
|
354
355
|
- lib/ramaze/cache.rb
|
356
|
+
- lib/ramaze/cache/file.rb
|
355
357
|
- lib/ramaze/cache/memcached.rb
|
356
358
|
- lib/ramaze/cache/memory.rb
|
357
359
|
- lib/ramaze/cache/yaml_store.rb
|
358
360
|
- lib/ramaze/contrib
|
359
361
|
- lib/ramaze/contrib.rb
|
360
|
-
- lib/ramaze/contrib/auto_params
|
361
|
-
- lib/ramaze/contrib/auto_params.rb
|
362
|
-
- lib/ramaze/contrib/auto_params/get_args.rb
|
363
362
|
- lib/ramaze/contrib/email.rb
|
364
363
|
- lib/ramaze/contrib/facebook
|
365
364
|
- lib/ramaze/contrib/facebook.rb
|
@@ -443,6 +442,7 @@ files:
|
|
443
442
|
- lib/ramaze/log/knotify.rb
|
444
443
|
- lib/ramaze/log/logger.rb
|
445
444
|
- lib/ramaze/log/logging.rb
|
445
|
+
- lib/ramaze/log/rotatinginformer.rb
|
446
446
|
- lib/ramaze/log/syslog.rb
|
447
447
|
- lib/ramaze/log/xosd.rb
|
448
448
|
- lib/ramaze/option
|
@@ -451,6 +451,8 @@ files:
|
|
451
451
|
- lib/ramaze/option/holder.rb
|
452
452
|
- lib/ramaze/option/merger.rb
|
453
453
|
- lib/ramaze/reloader.rb
|
454
|
+
- lib/ramaze/reloader/watch_inotify.rb
|
455
|
+
- lib/ramaze/reloader/watch_stat.rb
|
454
456
|
- lib/ramaze/route.rb
|
455
457
|
- lib/ramaze/setup.rb
|
456
458
|
- lib/ramaze/snippets
|
@@ -481,6 +483,7 @@ files:
|
|
481
483
|
- lib/ramaze/snippets/proc
|
482
484
|
- lib/ramaze/snippets/proc/locals.rb
|
483
485
|
- lib/ramaze/snippets/ramaze
|
486
|
+
- lib/ramaze/snippets/ramaze/acquire.rb
|
484
487
|
- lib/ramaze/snippets/ramaze/caller_info.rb
|
485
488
|
- lib/ramaze/snippets/ramaze/caller_lines.rb
|
486
489
|
- lib/ramaze/snippets/ramaze/deprecated.rb
|
@@ -561,7 +564,6 @@ files:
|
|
561
564
|
- ramaze.gemspec
|
562
565
|
- spec
|
563
566
|
- spec/contrib
|
564
|
-
- spec/contrib/auto_params.rb
|
565
567
|
- spec/contrib/profiling.rb
|
566
568
|
- spec/contrib/sequel
|
567
569
|
- spec/contrib/sequel/fill.rb
|
@@ -764,7 +766,6 @@ files:
|
|
764
766
|
- spec/snippets/array/put_within.rb
|
765
767
|
- spec/snippets/binding
|
766
768
|
- spec/snippets/binding/locals.rb
|
767
|
-
- spec/snippets/divide.rb
|
768
769
|
- spec/snippets/kernel
|
769
770
|
- spec/snippets/kernel/constant.rb
|
770
771
|
- spec/snippets/numeric
|
@@ -772,9 +773,9 @@ files:
|
|
772
773
|
- spec/snippets/numeric/time.rb
|
773
774
|
- spec/snippets/object
|
774
775
|
- spec/snippets/object/__dir__.rb
|
775
|
-
- spec/snippets/object/acquire.rb
|
776
776
|
- spec/snippets/ordered_set.rb
|
777
777
|
- spec/snippets/ramaze
|
778
|
+
- spec/snippets/ramaze/acquire.rb
|
778
779
|
- spec/snippets/ramaze/caller_info.rb
|
779
780
|
- spec/snippets/ramaze/caller_lines.rb
|
780
781
|
- spec/snippets/string
|
@@ -787,13 +788,15 @@ files:
|
|
787
788
|
has_rdoc: true
|
788
789
|
homepage: http://ramaze.rubyforge.org
|
789
790
|
post_install_message: |-
|
791
|
+
|
790
792
|
============================================================
|
791
793
|
|
792
794
|
Thank you for installing Ramaze!
|
793
|
-
|
795
|
+
The main website is http://ramaze.net .
|
794
796
|
|
795
|
-
|
796
|
-
|
797
|
+
Feel free to ask questions in our IRC channel:
|
798
|
+
irc.freenode.net #ramaze
|
799
|
+
http://mibbit.com/?server=irc.freenode.net&channel=%23ramaze
|
797
800
|
|
798
801
|
============================================================
|
799
802
|
rdoc_options: []
|
@@ -814,7 +817,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
814
817
|
version:
|
815
818
|
requirements: []
|
816
819
|
|
817
|
-
rubyforge_project:
|
820
|
+
rubyforge_project: ramaze
|
818
821
|
rubygems_version: 1.2.0
|
819
822
|
signing_key:
|
820
823
|
specification_version: 2
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# from merb/core_ext/get_args.rb
|
2
|
-
begin
|
3
|
-
require 'parse_tree'
|
4
|
-
require 'ruby2ruby'
|
5
|
-
|
6
|
-
class ParseTreeArray < Array
|
7
|
-
def self.translate(*args)
|
8
|
-
self.new(ParseTree.translate(*args))
|
9
|
-
end
|
10
|
-
|
11
|
-
def deep_array_node(type = nil)
|
12
|
-
each do |node|
|
13
|
-
return ParseTreeArray.new(node) if node.is_a?(Array) && (!type || node[0] == type)
|
14
|
-
next unless node.is_a?(Array)
|
15
|
-
return ParseTreeArray.new(node).deep_array_node(type)
|
16
|
-
end
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
|
20
|
-
def arg_nodes
|
21
|
-
self[1..-1].inject([]) do |sum,item|
|
22
|
-
sum << [item] unless item.is_a?(Array)
|
23
|
-
sum
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def get_args
|
28
|
-
arg_node = deep_array_node(:args)
|
29
|
-
return nil unless arg_node
|
30
|
-
args = arg_node.arg_nodes
|
31
|
-
default_node = arg_node.deep_array_node(:block)
|
32
|
-
return args unless default_node
|
33
|
-
lasgns = default_node[1..-1]
|
34
|
-
lasgns.each do |asgn|
|
35
|
-
args.assoc(asgn[1]) << eval(RubyToRuby.new.process(asgn[2]))
|
36
|
-
end
|
37
|
-
args
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
module GetArgs
|
43
|
-
def get_args
|
44
|
-
klass, meth = self.to_s.split(/ /).to_a[1][0..-2].split("#")
|
45
|
-
klass = $` if klass =~ /\(/
|
46
|
-
ParseTreeArray.translate(Object.const_get(klass), meth).get_args
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class UnboundMethod
|
51
|
-
include GetArgs
|
52
|
-
end
|
53
|
-
|
54
|
-
class Method
|
55
|
-
include GetArgs
|
56
|
-
end
|
57
|
-
rescue LoadError
|
58
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
# auto_params.rb
|
2
|
-
#
|
3
|
-
# AutoParams implements action parameterization ala merb 0.4 and Nitro
|
4
|
-
# using ruby2ruby and ParseTree
|
5
|
-
#
|
6
|
-
# Usage:
|
7
|
-
#
|
8
|
-
# Ramaze.contrib :auto_params
|
9
|
-
#
|
10
|
-
# Then, for example,
|
11
|
-
#
|
12
|
-
# def search(query) end
|
13
|
-
#
|
14
|
-
# can be accessed via
|
15
|
-
#
|
16
|
-
# - /search?query=findthis, which calls search('findthis')
|
17
|
-
# - /search/findthis search('findthis')
|
18
|
-
# - /search/findthis?query=andthis search(['findthis', 'andthis'])
|
19
|
-
#
|
20
|
-
# For more examples, take a look at spec/contrib/auto_params.rb
|
21
|
-
#
|
22
|
-
# Note: A simpler alternative for similar functionality would be:
|
23
|
-
#
|
24
|
-
# def search(query = request['query']) end
|
25
|
-
#
|
26
|
-
|
27
|
-
require __DIR__/:auto_params/:get_args
|
28
|
-
|
29
|
-
module Ramaze
|
30
|
-
|
31
|
-
module Contrib
|
32
|
-
class AutoParams
|
33
|
-
def self.startup
|
34
|
-
Ramaze::Cache.add :args
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class Action
|
40
|
-
|
41
|
-
# with parameterization, params may include
|
42
|
-
# arrays: /num?n=1&n=2 becomes [['1','2']] for def num(n) end
|
43
|
-
# nil: /calc?w=10&d=2 becomes ['10', nil, '2'] for def calc(w, h, d) end
|
44
|
-
|
45
|
-
def params=(*par)
|
46
|
-
par = *par
|
47
|
-
self[:params] = par.map{ |pa|
|
48
|
-
case pa
|
49
|
-
when Array
|
50
|
-
pa.map{|p| Rack::Utils.unescape(p)}
|
51
|
-
when nil
|
52
|
-
nil
|
53
|
-
else
|
54
|
-
Rack::Utils.unescape(pa)
|
55
|
-
end
|
56
|
-
} unless par.nil?
|
57
|
-
self[:params] ||= []
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
class Controller
|
63
|
-
|
64
|
-
# ignore cache when request.params is interesting
|
65
|
-
|
66
|
-
def self.cached(path)
|
67
|
-
if found = Cache.resolved[path]
|
68
|
-
if found.respond_to?(:relaxed_hash)
|
69
|
-
|
70
|
-
# don't use cache if we need to add request.params entries to the Action
|
71
|
-
if args = Cache.args[found.method]
|
72
|
-
param_keys = request.params.keys
|
73
|
-
return nil if args.find{|k,v| param_keys.include?(k.to_s) }
|
74
|
-
end
|
75
|
-
|
76
|
-
return found.dup
|
77
|
-
else
|
78
|
-
Log.warn("Found faulty `#{path}' in Cache.resolved, deleting it for sanity.")
|
79
|
-
Cache.resolved.delete path
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
nil
|
84
|
-
end
|
85
|
-
|
86
|
-
# use Method#get_args to insert values from request.params into Action#params
|
87
|
-
|
88
|
-
def self.resolve_method(name, *params)
|
89
|
-
if method = [ name, name.gsub('__','/') ].find{|n|
|
90
|
-
cached_action_methods.include?(n) }
|
91
|
-
meth = instance_method(method)
|
92
|
-
arity = meth.arity
|
93
|
-
|
94
|
-
if meth.respond_to? :get_args
|
95
|
-
unless args = Cache.args[name]
|
96
|
-
if args = meth.get_args
|
97
|
-
args = args.select{|e| e.to_s !~ /^\*/}
|
98
|
-
else
|
99
|
-
args = []
|
100
|
-
end
|
101
|
-
Cache.args[name] = args
|
102
|
-
end
|
103
|
-
|
104
|
-
param_keys = request.params.keys
|
105
|
-
|
106
|
-
# if there are missing args, or keys in request.params that match expected args
|
107
|
-
if args.size > params.size or args.find{|k,v| param_keys.include?(k.to_s) }
|
108
|
-
args.each_with_index do |(name, val), i|
|
109
|
-
r_params = request.params[name.to_s]
|
110
|
-
if params[i] and r_params and r_params.size > 0
|
111
|
-
params[i] = [params[i], r_params].flatten
|
112
|
-
else
|
113
|
-
params[i] ||= r_params
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# strip trailing nils so default argument values are used
|
118
|
-
params.reverse.each{|e| if e.nil? then params.pop else break end }
|
119
|
-
end
|
120
|
-
|
121
|
-
argity = args.select{|e| e.size==1}.size..args.size
|
122
|
-
else
|
123
|
-
argity = arity..arity
|
124
|
-
end
|
125
|
-
|
126
|
-
if arity < 0 or argity.include? params.size
|
127
|
-
return method, params
|
128
|
-
end
|
129
|
-
end
|
130
|
-
return nil, []
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
|
135
|
-
end
|