ramaze 2008.11 → 2009.01

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 (110) hide show
  1. data/README.markdown +7 -7
  2. data/benchmark/run.rb +1 -1
  3. data/doc/CHANGELOG +662 -0
  4. data/examples/app/blog/model/entry.rb +8 -1
  5. data/examples/app/blog/spec/blog.rb +2 -2
  6. data/examples/app/rapaste/spec/rapaste.rb +1 -1
  7. data/examples/app/rapaste/start.rb +2 -2
  8. data/examples/app/rapaste/view/view.xhtml +3 -0
  9. data/examples/app/todolist/spec/todolist.rb +1 -1
  10. data/examples/app/whywiki/spec/whywiki.rb +1 -1
  11. data/examples/app/wikore/spec/wikore.rb +1 -1
  12. data/examples/app/wikore/src/model.rb +8 -2
  13. data/examples/app/wiktacular/spec/wiktacular.rb +1 -1
  14. data/examples/app/wiktacular/src/model.rb +1 -1
  15. data/examples/basic/partial.rb +28 -0
  16. data/examples/helpers/httpdigest.rb +68 -10
  17. data/examples/misc/ramaise.rb +2 -2
  18. data/examples/templates/template_amrita2.rb +1 -1
  19. data/examples/templates/template_erubis.rb +1 -1
  20. data/examples/templates/template_ezamar.rb +1 -1
  21. data/examples/templates/template_haml.rb +2 -2
  22. data/examples/templates/template_liquid.rb +1 -1
  23. data/examples/templates/template_markaby.rb +2 -2
  24. data/examples/templates/template_nagoro.rb +1 -1
  25. data/examples/templates/template_redcloth.rb +1 -1
  26. data/examples/templates/template_remarkably.rb +2 -2
  27. data/examples/templates/template_tenjin.rb +1 -1
  28. data/examples/templates/template_xslt.rb +1 -1
  29. data/lib/proto/controller/init.rb +2 -1
  30. data/lib/proto/model/init.rb +3 -3
  31. data/lib/proto/public/dispatch.fcgi +2 -2
  32. data/lib/proto/spec/main.rb +3 -3
  33. data/lib/proto/start.rb +4 -0
  34. data/lib/ramaze.rb +6 -0
  35. data/lib/ramaze/action.rb +7 -1
  36. data/lib/ramaze/action/render.rb +6 -5
  37. data/lib/ramaze/cache.rb +1 -0
  38. data/lib/ramaze/cache/file.rb +71 -0
  39. data/lib/ramaze/contrib.rb +1 -1
  40. data/lib/ramaze/contrib/email.rb +2 -0
  41. data/lib/ramaze/contrib/facebook.rb +2 -2
  42. data/lib/ramaze/contrib/file_cache.rb +2 -64
  43. data/lib/ramaze/contrib/sequel/image.rb +1 -1
  44. data/lib/ramaze/controller.rb +9 -1
  45. data/lib/ramaze/controller/resolve.rb +10 -5
  46. data/lib/ramaze/current/request.rb +87 -70
  47. data/lib/ramaze/current/session.rb +3 -5
  48. data/lib/ramaze/current/session/hash.rb +7 -11
  49. data/lib/ramaze/dispatcher/action.rb +2 -0
  50. data/lib/ramaze/dispatcher/file.rb +6 -1
  51. data/lib/ramaze/helper.rb +12 -4
  52. data/lib/ramaze/helper/aspect.rb +2 -2
  53. data/lib/ramaze/helper/bench.rb +43 -0
  54. data/lib/ramaze/helper/form.rb +5 -2
  55. data/lib/ramaze/helper/formatting.rb +4 -0
  56. data/lib/ramaze/helper/gravatar.rb +18 -1
  57. data/lib/ramaze/helper/httpdigest.rb +55 -28
  58. data/lib/ramaze/helper/markaby.rb +1 -1
  59. data/lib/ramaze/helper/maruku.rb +2 -0
  60. data/lib/ramaze/helper/paginate.rb +1 -1
  61. data/lib/ramaze/helper/partial.rb +1 -1
  62. data/lib/ramaze/helper/redirect.rb +22 -4
  63. data/lib/ramaze/helper/user.rb +4 -4
  64. data/lib/ramaze/option.rb +1 -1
  65. data/lib/ramaze/option/holder.rb +3 -3
  66. data/lib/ramaze/reloader.rb +25 -41
  67. data/lib/ramaze/reloader/watch_inotify.rb +85 -0
  68. data/lib/ramaze/reloader/watch_stat.rb +58 -0
  69. data/lib/ramaze/snippets/divide.rb +2 -0
  70. data/lib/ramaze/snippets/numeric/time.rb +1 -1
  71. data/lib/ramaze/snippets/object/__dir__.rb +3 -3
  72. data/lib/ramaze/snippets/object/acquire.rb +3 -6
  73. data/lib/ramaze/snippets/ramaze/acquire.rb +31 -0
  74. data/lib/ramaze/snippets/ramaze/deprecated.rb +2 -1
  75. data/lib/ramaze/spec/helper/mock_http.rb +6 -5
  76. data/lib/ramaze/template/ezamar/render_partial.rb +8 -0
  77. data/lib/ramaze/tool/mime.rb +1 -1
  78. data/lib/ramaze/tool/project_creator.rb +2 -1
  79. data/lib/ramaze/version.rb +2 -2
  80. data/rake_tasks/coverage.rake +4 -5
  81. data/rake_tasks/spec.rake +6 -6
  82. data/ramaze-2008.11.gem +0 -0
  83. data/ramaze.gemspec +759 -758
  84. data/spec/contrib/profiling.rb +2 -2
  85. data/spec/ramaze/action/file_cache.rb +1 -1
  86. data/spec/ramaze/action/layout.rb +1 -1
  87. data/spec/ramaze/controller/actionless_templates.rb +1 -1
  88. data/spec/ramaze/controller/resolve.rb +1 -1
  89. data/spec/ramaze/controller/template_resolving.rb +1 -1
  90. data/spec/ramaze/dispatcher/directory.rb +3 -3
  91. data/spec/ramaze/helper/aspect.rb +1 -1
  92. data/spec/ramaze/helper/partial.rb +1 -1
  93. data/spec/ramaze/localize.rb +1 -1
  94. data/spec/ramaze/rewrite.rb +1 -1
  95. data/spec/ramaze/template.rb +3 -3
  96. data/spec/ramaze/template/amrita2.rb +1 -1
  97. data/spec/ramaze/template/erubis.rb +1 -1
  98. data/spec/ramaze/template/ezamar.rb +1 -1
  99. data/spec/ramaze/template/haml.rb +2 -2
  100. data/spec/ramaze/template/nagoro.rb +1 -1
  101. data/spec/ramaze/template/redcloth.rb +1 -1
  102. data/spec/ramaze/template/sass.rb +1 -1
  103. data/spec/ramaze/template/tenjin.rb +1 -1
  104. data/spec/snippets/object/__dir__.rb +6 -0
  105. data/spec/snippets/{object → ramaze}/acquire.rb +24 -18
  106. metadata +18 -16
  107. data/lib/ramaze/contrib/auto_params.rb +0 -135
  108. data/lib/ramaze/contrib/auto_params/get_args.rb +0 -58
  109. data/spec/contrib/auto_params.rb +0 -121
  110. data/spec/snippets/divide.rb +0 -19
@@ -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
@@ -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,121 +0,0 @@
1
- require 'spec/helper'
2
- spec_require 'parse_tree', 'ruby2ruby'
3
-
4
- Ramaze.contrib :auto_params
5
-
6
- module AnotherController
7
- Ramaze::Helper::LOOKUP << self
8
-
9
- def another_page
10
- 'another page'
11
- end
12
-
13
- define_method('css/style.css') { 'style.css' }
14
- end
15
-
16
- class MainController < Ramaze::Controller
17
- include AnotherController
18
- engine :None
19
-
20
- def search query
21
- query.inspect
22
- end
23
-
24
- def create name, age = '?', occupation = nil
25
- [name, age, occupation].compact.join(', ')
26
- end
27
-
28
- def show *args
29
- args.join(', ')
30
- end
31
-
32
- def add item, price = 1.0, *args
33
- [item, price, *args].join(', ')
34
- end
35
-
36
- def find width, height, depth
37
- [width, height, depth].join(', ')
38
- end
39
-
40
- define_method('page') do
41
- 'page'
42
- end
43
- end
44
-
45
- class GetArgsTest
46
- def one(a, b, c) end
47
- def two(a, b = 1, c = nil) end
48
- def three(a, *args) end
49
- end
50
-
51
- describe 'Method#get_args' do
52
- it 'should return a list of arguments' do
53
- gat = GetArgsTest.new
54
- gat.method(:one).get_args.should == [[:a], [:b], [:c]]
55
- gat.method(:two).get_args.should == [[:a], [:b, 1], [:c, nil]]
56
- gat.method(:three).get_args.should == [[:a], [:"*args"]]
57
- end
58
- end
59
-
60
- describe 'Parameterized actions' do
61
- behaves_like 'http'
62
- ramaze
63
-
64
- it 'should pass in values from request.params' do
65
- get('/create/Aman/20').body.should == 'Aman, 20'
66
- get('/create', :name => 'Aman', :age => 20).body.should == 'Aman, 20'
67
-
68
- get('/create/Aman/20/Unemployed').body.should == 'Aman, 20, Unemployed'
69
- get('/create', :name => 'Aman', :age => 20, :occupation => 'Unemployed').body.should == 'Aman, 20, Unemployed'
70
-
71
- get('/create/Aman').body.should == 'Aman, ?'
72
- get('/create', :name => 'Aman').body.should == 'Aman, ?'
73
- end
74
-
75
- it 'should insert nil for arguments not found' do
76
- get('/find', :width => 10, :depth => 20).body.should == '10, , 20'
77
- end
78
-
79
- it 'should work with variable arguments' do
80
- get('/show/1/2/3').body.should == '1, 2, 3'
81
-
82
- get('/add/Shoe').body.should == 'Shoe, 1.0'
83
- get('/add', :item => 'Shoe').body.should == 'Shoe, 1.0'
84
-
85
- get('/add/Shoe/10.50/1/2/3').body.should == 'Shoe, 10.50, 1, 2, 3'
86
- get('/add/Shoe/11.00').body.should == 'Shoe, 11.00'
87
- end
88
-
89
- it 'should not break existing methods' do
90
- get('/search/Aman').body.should == '"Aman"'
91
- get('/search', 'query=Aman').body.should == '"Aman"'
92
- get('/search/tmm1', 'query=Aman').body.should == ['tmm1','Aman'].inspect
93
- end
94
-
95
- it 'should consolidate all values for the same key into an array' do
96
- get('/add', 'item=Shoe&item=Shirt').body.should == 'Shoe, Shirt, 1.0'
97
- get('/add/Pants', 'item=Shoe&item=Shirt').body.should == 'Pants, Shoe, Shirt, 1.0'
98
- get('/add/Shoe', :item => 'Shirt').body.should == 'Shoe, Shirt, 1.0'
99
- end
100
- end if method(:puts).respond_to? :get_args
101
-
102
- describe 'Normal behavior' do
103
- behaves_like 'http'
104
- ramaze
105
-
106
- it 'should work with no arguments' do
107
- get('/page').body.should == 'page'
108
- end
109
-
110
- it 'should raise no action' do
111
- get('/none').body.should =~ /No Action found/
112
- end
113
-
114
- it 'should work with included actions' do
115
- get('/another_page').body.should == 'another page'
116
- end
117
-
118
- it 'should work with /' do
119
- get('/css/style.css').body.should == 'style.css'
120
- end
121
- end
@@ -1,19 +0,0 @@
1
- require 'lib/ramaze/spec/helper/snippets'
2
-
3
- describe 'String#/ and Symbol#/' do
4
- it 'should join two strings' do
5
- ('a' / 'b').should == 'a/b'
6
- end
7
-
8
- it 'should join a string and a symbol' do
9
- ('a' / :b).should == 'a/b'
10
- end
11
-
12
- it 'should join two symbols' do
13
- (:a / :b).should == 'a/b'
14
- end
15
-
16
- it 'should be usable in concatenation' do
17
- ('a' / :b / :c).should == 'a/b/c'
18
- end
19
- end