manveru-ramaze 2008.10 → 2008.12

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 (77) hide show
  1. data/benchmark/run.rb +1 -1
  2. data/examples/app/blog/spec/blog.rb +2 -2
  3. data/examples/app/rapaste/spec/rapaste.rb +1 -1
  4. data/examples/app/rapaste/start.rb +2 -2
  5. data/examples/app/todolist/spec/todolist.rb +1 -1
  6. data/examples/app/whywiki/spec/whywiki.rb +1 -1
  7. data/examples/app/wikore/spec/wikore.rb +1 -1
  8. data/examples/app/wikore/src/model.rb +1 -1
  9. data/examples/app/wiktacular/spec/wiktacular.rb +1 -1
  10. data/examples/app/wiktacular/src/model.rb +1 -1
  11. data/examples/basic/partial.rb +28 -0
  12. data/examples/misc/ramaise.rb +2 -2
  13. data/examples/templates/template_amrita2.rb +1 -1
  14. data/examples/templates/template_erubis.rb +1 -1
  15. data/examples/templates/template_ezamar.rb +1 -1
  16. data/examples/templates/template_haml.rb +2 -2
  17. data/examples/templates/template_liquid.rb +1 -1
  18. data/examples/templates/template_markaby.rb +2 -2
  19. data/examples/templates/template_nagoro.rb +1 -1
  20. data/examples/templates/template_redcloth.rb +1 -1
  21. data/examples/templates/template_remarkably.rb +2 -2
  22. data/examples/templates/template_tenjin.rb +1 -1
  23. data/examples/templates/template_xslt.rb +1 -1
  24. data/lib/proto/public/dispatch.fcgi +2 -2
  25. data/lib/proto/spec/main.rb +3 -3
  26. data/lib/ramaze/action.rb +7 -1
  27. data/lib/ramaze/cache/file.rb +71 -0
  28. data/lib/ramaze/cache.rb +1 -0
  29. data/lib/ramaze/contrib/email.rb +2 -0
  30. data/lib/ramaze/contrib/facebook.rb +2 -2
  31. data/lib/ramaze/contrib/file_cache.rb +2 -64
  32. data/lib/ramaze/contrib/sequel/image.rb +1 -1
  33. data/lib/ramaze/controller.rb +6 -1
  34. data/lib/ramaze/current/request.rb +85 -68
  35. data/lib/ramaze/current/session/hash.rb +7 -11
  36. data/lib/ramaze/current/session.rb +3 -5
  37. data/lib/ramaze/dispatcher/action.rb +2 -0
  38. data/lib/ramaze/dispatcher/file.rb +4 -0
  39. data/lib/ramaze/helper/aspect.rb +2 -2
  40. data/lib/ramaze/helper/form.rb +5 -2
  41. data/lib/ramaze/helper/formatting.rb +4 -0
  42. data/lib/ramaze/helper/gravatar.rb +18 -1
  43. data/lib/ramaze/helper/maruku.rb +2 -0
  44. data/lib/ramaze/helper/redirect.rb +22 -4
  45. data/lib/ramaze/helper.rb +9 -2
  46. data/lib/ramaze/reloader/watch_inotify.rb +73 -0
  47. data/lib/ramaze/reloader/watch_stat.rb +62 -0
  48. data/lib/ramaze/reloader.rb +25 -41
  49. data/lib/ramaze/snippets/object/__dir__.rb +3 -3
  50. data/lib/ramaze/snippets/ramaze/acquire.rb +31 -0
  51. data/lib/ramaze/spec/helper/mock_http.rb +6 -5
  52. data/lib/ramaze/template/ezamar/render_partial.rb +8 -0
  53. data/lib/ramaze.rb +4 -0
  54. data/ramaze.gemspec +757 -756
  55. data/spec/contrib/profiling.rb +1 -1
  56. data/spec/ramaze/action/file_cache.rb +1 -1
  57. data/spec/ramaze/action/layout.rb +1 -1
  58. data/spec/ramaze/controller/actionless_templates.rb +1 -1
  59. data/spec/ramaze/controller/resolve.rb +1 -1
  60. data/spec/ramaze/controller/template_resolving.rb +1 -1
  61. data/spec/ramaze/dispatcher/directory.rb +3 -3
  62. data/spec/ramaze/helper/aspect.rb +1 -1
  63. data/spec/ramaze/helper/partial.rb +1 -1
  64. data/spec/ramaze/localize.rb +1 -1
  65. data/spec/ramaze/rewrite.rb +1 -1
  66. data/spec/ramaze/template/amrita2.rb +1 -1
  67. data/spec/ramaze/template/erubis.rb +1 -1
  68. data/spec/ramaze/template/ezamar.rb +1 -1
  69. data/spec/ramaze/template/haml.rb +2 -2
  70. data/spec/ramaze/template/nagoro.rb +1 -1
  71. data/spec/ramaze/template/redcloth.rb +1 -1
  72. data/spec/ramaze/template/sass.rb +1 -1
  73. data/spec/ramaze/template/tenjin.rb +1 -1
  74. data/spec/ramaze/template.rb +3 -3
  75. data/spec/snippets/object/__dir__.rb +6 -0
  76. data/spec/snippets/ramaze/acquire.rb +77 -0
  77. metadata +8 -8
@@ -11,9 +11,7 @@ module Ramaze
11
11
  # Reloader::Hooks module or include your own module to override the hooks.
12
12
  # You also might have to set the Log constant.
13
13
  #
14
- # What makes it especially suited for use in a production environment is that
15
- # any file will only be checked once and there will only be made one system
16
- # call stat(2).
14
+ # Currently, it uses RInotify if available and falls back to using File.stat.
17
15
  #
18
16
  # Please note that this will not reload files in the background, it does so
19
17
  # only when actively called
@@ -47,11 +45,21 @@ module Ramaze
47
45
  :control => nil, # lambda{ cycle },
48
46
  }
49
47
 
48
+ begin
49
+ gem 'RInotify', '>=0.9' # is older version ok?
50
+ require 'rinotify'
51
+ require 'ramaze/reloader/watch_inotify'
52
+ Watcher = WatchInotify
53
+ rescue LoadError
54
+ # stat always available
55
+ require 'ramaze/reloader/watch_stat'
56
+ Watcher = WatchStat
57
+ end
58
+
50
59
  def initialize(app)
51
60
  @app = app
52
- @last = Time.now
53
- @mtimes = {}
54
- @cache = {}
61
+ @files = {}
62
+ @watcher = Watcher.new
55
63
  options_reload
56
64
  end
57
65
 
@@ -63,7 +71,7 @@ module Ramaze
63
71
  def call(env)
64
72
  options_reload
65
73
 
66
- if @cooldown and Time.now > @last + @cooldown
74
+ @watcher.call(@cooldown) do
67
75
  if @control
68
76
  instance_eval(&@control)
69
77
  elsif @thread
@@ -71,8 +79,6 @@ module Ramaze
71
79
  else
72
80
  cycle
73
81
  end
74
-
75
- @last = Time.now
76
82
  end
77
83
 
78
84
  @app.call(env)
@@ -81,16 +87,8 @@ module Ramaze
81
87
  def cycle
82
88
  before_cycle
83
89
 
84
- rotation do |file, stat|
85
- if mtime = stat.mtime
86
- if mtime > (@mtimes[file] ||= mtime)
87
- safe_load(file)
88
- @mtimes[file] = mtime
89
- end
90
- else
91
- @cache.delete(file)
92
- end
93
- end
90
+ rotation{|file| @watcher.watch(file) }
91
+ @watcher.changed_files.each{|f| safe_load(f) }
94
92
 
95
93
  after_cycle
96
94
  end
@@ -111,37 +109,23 @@ module Ramaze
111
109
 
112
110
  files.each do |file|
113
111
  next if file =~ @ignore
114
- path, stat = figure_path(file, paths)
115
-
116
- if path and stat
117
- @cache[file] = path
118
- yield(path, stat)
119
- else
120
- # Quite harmless, we just couldn't figure out path for #{file}
112
+ if not @files.has_key?(file) and path = figure_path(file, paths)
113
+ @files[file] = path
114
+ yield path
121
115
  end
122
116
  end
123
117
  end
124
118
 
125
119
  def figure_path(file, paths)
126
- if cached = @cache[file]
127
- stat = File.stat(cached)
128
- return cached, stat if stat.file?
129
- elsif Pathname.new(file).absolute?
130
- stat = File.stat(file)
131
- return file, stat if stat.file? # do directories really end up in $" ?
120
+ if Pathname.new(file).absolute?
121
+ return File.exist?(file) ? file : nil
132
122
  end
133
123
 
134
124
  paths.each do |possible_path|
135
- path = File.join(possible_path, file)
136
-
137
- begin
138
- stat = File.stat(path)
139
- return path, stat if stat.file?
140
- rescue Errno::ENOENT, Errno::ENOTDIR
141
- end
125
+ full_path = File.join(possible_path, file)
126
+ return full_path if File.exist?(full_path)
142
127
  end
143
-
144
- return nil
128
+ nil
145
129
  end
146
130
 
147
131
 
@@ -16,11 +16,11 @@ module Ramaze
16
16
  # This method is convenience for the
17
17
  # File.expand_path(File.dirname(__FILE__))
18
18
  # idiom.
19
- #
20
19
 
21
- def __DIR__()
20
+ def __DIR__(*args)
22
21
  filename = caller[0][/^(.*):/, 1]
23
- File.expand_path(File.dirname(filename))
22
+ dir = File.expand_path(File.dirname(filename))
23
+ ::File.expand_path(::File.join(dir, *args.map{|a| a.to_s}))
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,31 @@
1
+ # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ module Ramaze
5
+ # Require all .rb and .so files on the given globs, utilizes Dir::[].
6
+ #
7
+ # Examples:
8
+ # # Given following directory structure:
9
+ # # src/foo.rb
10
+ # # src/bar.so
11
+ # # src/foo.yaml
12
+ # # src/foobar/baz.rb
13
+ # # src/foobar/README
14
+ #
15
+ # # requires all files in 'src':
16
+ # Ramaze.acquire 'src/*'
17
+ #
18
+ # # requires all files in 'src' recursive:
19
+ # Ramaze.acquire 'src/**/*'
20
+ #
21
+ # # require 'src/foo.rb' and 'src/bar.so' and 'src/foobar/baz.rb'
22
+ # Ramaze.acquire 'src/*', 'src/foobar/*'
23
+
24
+ def self.acquire(*globs)
25
+ globs.flatten.each do |glob|
26
+ Dir[glob].each do |file|
27
+ require file if file =~ /\.(rb|so)$/
28
+ end
29
+ end
30
+ end
31
+ end
@@ -42,8 +42,9 @@ module MockHTTP
42
42
 
43
43
  def process_request(path, query)
44
44
  options = {}
45
- FISHING.each{|key, value|
46
- options[value] = query.delete(key)} if query.is_a?(Hash)
45
+ FISHING.each do |key, value|
46
+ options[value] = query.delete(key) if query.key?(key)
47
+ end if query.is_a?(Hash)
47
48
  [create_url(path, query), options]
48
49
  end
49
50
 
@@ -54,10 +55,10 @@ module MockHTTP
54
55
  uri.to_s
55
56
  end
56
57
 
57
- def make_query query
58
- return query unless query and not query.is_a?(String)
58
+ def make_query query
59
+ return query unless query and not query.is_a?(String)
59
60
  query.map{|key, value|
60
61
  "#{Rack::Utils.escape(key)}=#{Rack::Utils.escape(value)}"
61
62
  }.join('&')
62
- end
63
+ end
63
64
  end
@@ -7,6 +7,14 @@ require 'ramaze/template/ezamar/engine'
7
7
  module Ezamar
8
8
 
9
9
  # A transformer for <render /> tags.
10
+ #
11
+ # Setup:
12
+ #
13
+ # pipeline = Ramaze::Template::Ezamar::TRANSFORM_PIPELINE
14
+ # pipeline.put_after(::Ezamar::Element, ::Ezamar::RenderPartial)
15
+ # pipline.uniq!
16
+ #
17
+ # See /examples/basic/partial.rb for usage.
10
18
 
11
19
  class RenderPartial
12
20
  extend Ramaze::Helper::Partial
data/lib/ramaze.rb CHANGED
@@ -99,10 +99,14 @@ module Ramaze
99
99
  end
100
100
  end
101
101
 
102
+ # A shortcut for setting Ramaze.trait[:started] = true.
103
+
102
104
  def skip_start
103
105
  trait[:started] = true
104
106
  end
105
107
 
108
+ # Forces the startup of Ramaze regardless if trait[:started] is set.
109
+
106
110
  def start!(options = {})
107
111
  trait[:started] = false
108
112
  startup(options)