ramaze 0.3.5 → 0.3.9

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 (204) hide show
  1. data/Rakefile +5 -20
  2. data/bin/ramaze +0 -4
  3. data/doc/AUTHORS +5 -0
  4. data/doc/meta/announcement.txt +2 -1
  5. data/doc/tutorial/todolist.html +20 -21
  6. data/doc/tutorial/todolist.mkd +10 -9
  7. data/examples/blog/{src/controller.rb → controller/main.rb} +2 -0
  8. data/examples/blog/{src/model.rb → model/entry.rb} +0 -0
  9. data/examples/blog/spec/blog.rb +3 -3
  10. data/examples/blog/start.rb +2 -3
  11. data/examples/blog/view/edit.xhtml +17 -0
  12. data/examples/blog/view/index.xhtml +17 -0
  13. data/examples/blog/view/layout.xhtml +11 -0
  14. data/examples/blog/view/new.xhtml +16 -0
  15. data/examples/facebook.rb +15 -8
  16. data/examples/identity.rb +1 -1
  17. data/examples/memleak_detector.rb +1 -1
  18. data/examples/rammit/src/model.rb +1 -1
  19. data/examples/rapaste/controller/paste.rb +7 -7
  20. data/examples/rapaste/model/paste.rb +1 -3
  21. data/examples/rapaste/public/css/display.css +2 -1
  22. data/examples/rapaste/start.rb +2 -3
  23. data/examples/sourceview/sourceview.rb +1 -1
  24. data/examples/templates/template/external.tenjin +28 -0
  25. data/examples/templates/template_amrita2.rb +0 -3
  26. data/examples/templates/template_tenjin.rb +57 -0
  27. data/examples/todolist/spec/todolist.rb +13 -2
  28. data/examples/todolist/src/controller/main.rb +1 -1
  29. data/examples/todolist/template/index.xhtml +1 -1
  30. data/examples/wiktacular/spec/wiktacular.rb +18 -0
  31. data/examples/wiktacular/src/controller.rb +2 -2
  32. data/examples/wiktacular/src/model.rb +8 -2
  33. data/lib/proto/public/css/ramaze_error.css +4 -0
  34. data/lib/proto/public/dispatch.fcgi +11 -0
  35. data/lib/proto/spec/main.rb +1 -1
  36. data/lib/proto/start.ru +8 -0
  37. data/lib/proto/view/error.xhtml +2 -0
  38. data/lib/ramaze.rb +28 -5
  39. data/lib/ramaze/action.rb +9 -2
  40. data/lib/ramaze/action/render.rb +40 -24
  41. data/lib/ramaze/adapter.rb +10 -17
  42. data/lib/ramaze/adapter/base.rb +8 -12
  43. data/lib/ramaze/adapter/cgi.rb +14 -13
  44. data/lib/ramaze/adapter/ebb.rb +34 -0
  45. data/lib/ramaze/adapter/evented_mongrel.rb +1 -1
  46. data/lib/ramaze/adapter/fcgi.rb +14 -14
  47. data/lib/ramaze/adapter/lsws.rb +15 -11
  48. data/lib/ramaze/adapter/mongrel.rb +2 -1
  49. data/lib/ramaze/adapter/scgi.rb +24 -0
  50. data/lib/ramaze/adapter/swiftiplied_mongrel.rb +1 -1
  51. data/lib/ramaze/adapter/thin.rb +4 -5
  52. data/lib/ramaze/adapter/webrick.rb +5 -5
  53. data/lib/ramaze/cache.rb +1 -1
  54. data/lib/ramaze/cache/memcached.rb +1 -1
  55. data/lib/ramaze/contrib.rb +70 -10
  56. data/lib/ramaze/contrib/auto_params.rb +1 -1
  57. data/lib/ramaze/contrib/email.rb +15 -15
  58. data/lib/ramaze/contrib/facebook.rb +2 -2
  59. data/lib/ramaze/contrib/facebook/facebook.rb +7 -4
  60. data/lib/ramaze/contrib/file_cache.rb +65 -0
  61. data/lib/ramaze/contrib/gettext.rb +56 -55
  62. data/lib/ramaze/contrib/profiling.rb +36 -0
  63. data/lib/ramaze/contrib/sequel_cache.rb +92 -0
  64. data/lib/ramaze/controller.rb +80 -47
  65. data/lib/ramaze/controller/error.rb +10 -5
  66. data/lib/ramaze/controller/resolve.rb +36 -48
  67. data/lib/ramaze/current.rb +70 -0
  68. data/lib/ramaze/{trinity → current}/request.rb +62 -15
  69. data/lib/ramaze/current/response.rb +19 -0
  70. data/lib/ramaze/{trinity → current}/session.rb +32 -110
  71. data/lib/ramaze/current/session/flash.rb +67 -0
  72. data/lib/ramaze/current/session/hash.rb +65 -0
  73. data/lib/ramaze/dispatcher.rb +1 -28
  74. data/lib/ramaze/dispatcher/action.rb +6 -3
  75. data/lib/ramaze/dispatcher/directory.rb +1 -1
  76. data/lib/ramaze/dispatcher/error.rb +26 -5
  77. data/lib/ramaze/dispatcher/file.rb +13 -2
  78. data/lib/ramaze/gestalt.rb +3 -1
  79. data/lib/ramaze/global.rb +6 -3
  80. data/lib/ramaze/global/globalstruct.rb +3 -1
  81. data/lib/ramaze/helper.rb +66 -20
  82. data/lib/ramaze/helper/aspect.rb +25 -17
  83. data/lib/ramaze/helper/auth.rb +4 -3
  84. data/lib/ramaze/helper/cache.rb +5 -4
  85. data/lib/ramaze/helper/cgi.rb +11 -9
  86. data/lib/ramaze/helper/flash.rb +28 -3
  87. data/lib/ramaze/helper/formatting.rb +1 -3
  88. data/lib/ramaze/helper/identity.rb +2 -3
  89. data/lib/ramaze/helper/inform.rb +7 -6
  90. data/lib/ramaze/helper/link.rb +15 -17
  91. data/lib/ramaze/helper/markaby.rb +2 -4
  92. data/lib/ramaze/helper/maruku.rb +1 -1
  93. data/lib/ramaze/helper/nitroform.rb +4 -4
  94. data/lib/ramaze/helper/pager.rb +4 -6
  95. data/lib/ramaze/helper/partial.rb +24 -21
  96. data/lib/ramaze/helper/redirect.rb +8 -5
  97. data/lib/ramaze/helper/{file.rb → sendfile.rb} +1 -3
  98. data/lib/ramaze/helper/sequel.rb +1 -3
  99. data/lib/ramaze/helper/stack.rb +1 -3
  100. data/lib/ramaze/helper/tagz.rb +19 -0
  101. data/lib/ramaze/helper/user.rb +63 -0
  102. data/lib/ramaze/inform.rb +2 -24
  103. data/lib/ramaze/log.rb +28 -0
  104. data/lib/ramaze/{inform → log}/analogger.rb +3 -3
  105. data/lib/ramaze/{inform → log}/growl.rb +2 -2
  106. data/lib/ramaze/{inform → log}/hub.rb +4 -6
  107. data/lib/ramaze/{inform → log}/informer.rb +4 -4
  108. data/lib/ramaze/{inform → log}/knotify.rb +2 -2
  109. data/lib/ramaze/log/logger.rb +22 -0
  110. data/lib/ramaze/{inform/informing.rb → log/logging.rb} +16 -16
  111. data/lib/ramaze/{inform → log}/syslog.rb +0 -0
  112. data/lib/ramaze/{inform → log}/xosd.rb +2 -2
  113. data/lib/ramaze/route.rb +64 -36
  114. data/lib/ramaze/snippets/array/put_within.rb +13 -0
  115. data/lib/ramaze/snippets/binding/locals.rb +13 -0
  116. data/lib/ramaze/snippets/kernel/__dir__.rb +10 -8
  117. data/lib/ramaze/snippets/kernel/aquire.rb +1 -1
  118. data/lib/ramaze/snippets/kernel/constant.rb +1 -1
  119. data/lib/ramaze/snippets/object/pretty.rb +6 -0
  120. data/lib/ramaze/snippets/object/scope.rb +11 -0
  121. data/lib/ramaze/snippets/object/thread_accessor.rb +5 -0
  122. data/lib/ramaze/snippets/ordered_set.rb +1 -1
  123. data/lib/ramaze/snippets/proc/locals.rb +11 -0
  124. data/lib/ramaze/snippets/ramaze/thread_accessor.rb +44 -0
  125. data/lib/ramaze/snippets/string/esc.rb +29 -0
  126. data/lib/ramaze/snippets/string/start_with.rb +7 -0
  127. data/lib/ramaze/snippets/string/unindent.rb +6 -1
  128. data/lib/ramaze/snippets/struct/values_at.rb +1 -5
  129. data/lib/ramaze/sourcereload.rb +16 -14
  130. data/lib/ramaze/spec.rb +1 -0
  131. data/lib/ramaze/spec/helper.rb +11 -3
  132. data/lib/ramaze/spec/helper/browser.rb +25 -1
  133. data/lib/ramaze/spec/helper/pretty_output.rb +11 -11
  134. data/lib/ramaze/template.rb +5 -4
  135. data/lib/ramaze/template/amrita2.rb +2 -3
  136. data/lib/ramaze/template/ezamar/element.rb +2 -3
  137. data/lib/ramaze/template/ezamar/morpher.rb +1 -2
  138. data/lib/ramaze/template/ezamar/render_partial.rb +1 -1
  139. data/lib/ramaze/template/haml.rb +5 -2
  140. data/lib/ramaze/template/markaby.rb +2 -0
  141. data/lib/ramaze/template/tagz.rb +79 -0
  142. data/lib/ramaze/template/tenjin.rb +34 -0
  143. data/lib/ramaze/tool/create.rb +0 -3
  144. data/lib/ramaze/tool/localize.rb +107 -105
  145. data/lib/ramaze/tool/mime.rb +0 -2
  146. data/lib/ramaze/trinity.rb +1 -26
  147. data/lib/ramaze/version.rb +1 -1
  148. data/lib/vendor/bacon.rb +47 -41
  149. data/rake_tasks/conf.rake +18 -0
  150. data/rake_tasks/darcs.rake +5 -0
  151. data/rake_tasks/maintenance.rake +37 -24
  152. data/rake_tasks/spec.rake +1 -1
  153. data/spec/contrib/auto_params.rb +3 -1
  154. data/spec/contrib/profiling.rb +26 -0
  155. data/spec/examples/templates/template_redcloth.rb +1 -1
  156. data/spec/examples/templates/template_tenjin.rb +28 -0
  157. data/spec/helper.rb +0 -1
  158. data/spec/ramaze/action/layout.rb +28 -0
  159. data/spec/ramaze/controller/actionless_templates.rb +32 -0
  160. data/spec/ramaze/controller/template/other_wrapper.xhtml +1 -0
  161. data/spec/ramaze/controller/template_resolving.rb +37 -0
  162. data/spec/ramaze/{trinity → current}/request.rb +12 -2
  163. data/spec/ramaze/current/session.rb +97 -0
  164. data/spec/ramaze/dispatcher/directory.rb +2 -1
  165. data/spec/ramaze/dispatcher/file.rb +8 -3
  166. data/spec/ramaze/dispatcher/public/file name.txt +1 -0
  167. data/spec/ramaze/gestalt.rb +11 -0
  168. data/spec/ramaze/helper/aspect.rb +28 -22
  169. data/spec/ramaze/helper/cgi.rb +2 -2
  170. data/spec/ramaze/helper/flash.rb +33 -15
  171. data/spec/ramaze/helper/formatting.rb +2 -2
  172. data/spec/ramaze/helper/link.rb +46 -18
  173. data/spec/ramaze/helper/pager.rb +8 -5
  174. data/spec/ramaze/helper/partial.rb +8 -1
  175. data/spec/ramaze/helper/template/recursive_local_ivars.xhtml +7 -0
  176. data/spec/ramaze/helper/user.rb +46 -0
  177. data/spec/ramaze/{inform → log}/informer.rb +0 -0
  178. data/spec/ramaze/{inform → log}/syslog.rb +1 -1
  179. data/spec/ramaze/request.rb +14 -10
  180. data/spec/ramaze/route.rb +23 -0
  181. data/spec/ramaze/template.rb +48 -1
  182. data/spec/ramaze/template/haml.rb +6 -16
  183. data/spec/ramaze/template/haml/locals.haml +2 -1
  184. data/spec/ramaze/template/tagz.rb +62 -0
  185. data/spec/ramaze/template/tagz/external.tagz +8 -0
  186. data/spec/ramaze/template/tagz/sum.tagz +1 -0
  187. data/spec/ramaze/template/tenjin.rb +49 -0
  188. data/spec/ramaze/template/tenjin/external.tenjin +1 -0
  189. data/spec/snippets/string/unindent.rb +15 -0
  190. metadata +509 -475
  191. data/doc/README.html +0 -729
  192. data/doc/changes.txt +0 -5757
  193. data/doc/changes.xml +0 -5759
  194. data/examples/blog/src/view.rb +0 -16
  195. data/examples/blog/template/edit.xhtml +0 -19
  196. data/examples/blog/template/index.xhtml +0 -19
  197. data/examples/blog/template/new.xhtml +0 -18
  198. data/examples/wiktacular/mkd/newpagename/current.mkd +0 -1
  199. data/examples/wiktacular/mkd/newpagename/current.mkd.bak +0 -1
  200. data/lib/ramaze/contrib/email.rb-darcs-backup0 +0 -81
  201. data/lib/ramaze/template/bijou.rb +0 -39
  202. data/lib/ramaze/trinity/response.rb +0 -32
  203. data/spec/ramaze/template/bijou.rb +0 -25
  204. data/spec/ramaze/trinity/session.rb +0 -29
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
- Ramaze::Inform.debug "Using Swiftiplied Mongrel"
4
+ Ramaze::Log.debug "Using Swiftiplied Mongrel"
5
5
 
6
6
  require 'swiftcore/swiftiplied_mongrel'
7
7
  require 'ramaze/adapter/mongrel'
@@ -1,21 +1,20 @@
1
1
  require 'thin'
2
- require 'ramaze/adapter'
3
2
  require 'rack/handler/thin'
4
3
 
5
4
  module Ramaze
6
- module Adapter
5
+ Global.test_connections = true
7
6
 
7
+ module Adapter
8
8
  class Thin < Base
9
9
  class << self
10
10
 
11
11
  # start server on given host and port.
12
12
  def run_server host, port
13
13
  server = ::Thin::Server.new(host, port, self)
14
- server.silent = true
14
+ ::Thin::Logging.silent = true
15
15
  server.timeout = 3
16
- server.start
17
16
 
18
- thread = Thread.new{ server.listen! }
17
+ thread = Thread.new{ server.start }
19
18
  thread[:adapter] = server
20
19
  thread
21
20
  end
@@ -1,13 +1,13 @@
1
1
  # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
- require 'ramaze/adapter'
5
4
  require 'webrick'
6
5
  require 'rack/handler/webrick'
7
6
 
8
7
  module Ramaze
9
- module Adapter
8
+ Global.test_connections = true
10
9
 
10
+ module Adapter
11
11
  # Our WEBrick adapter acts as wrapper for the Rack::Handler::WEBrick.
12
12
  class WEBrick < Base
13
13
  class << self
@@ -17,10 +17,10 @@ module Ramaze
17
17
  options = {
18
18
  :Port => port,
19
19
  :BindAddress => host,
20
- :Logger => Inform,
20
+ :Logger => Log,
21
21
  :AccessLog => [
22
- [Inform, ::WEBrick::AccessLog::COMMON_LOG_FORMAT],
23
- [Inform, ::WEBrick::AccessLog::REFERER_LOG_FORMAT]
22
+ [Log, ::WEBrick::AccessLog::COMMON_LOG_FORMAT],
23
+ [Log, ::WEBrick::AccessLog::REFERER_LOG_FORMAT]
24
24
  ]
25
25
  }.merge(options)
26
26
 
@@ -41,7 +41,7 @@ module Ramaze
41
41
  klass = Global.cache_alternative.fetch(key, self)
42
42
  add_on(key, klass)
43
43
  }
44
- Inform.dev("Added caches for: #{keys.join(', ')}")
44
+ Log.dev("Added caches for: #{keys.join(', ')}")
45
45
  end
46
46
 
47
47
  def add_on(key, cache_class)
@@ -39,7 +39,7 @@ module Ramaze
39
39
  def method_missing(*args, &block)
40
40
  @cache.__send__(*args, &block)
41
41
  rescue MemCache::MemCacheError => e
42
- Ramaze::Inform.error e.to_s
42
+ Log.error e.to_s
43
43
  nil
44
44
  end
45
45
 
@@ -2,21 +2,81 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
+
6
+ # Loads and sets up contrib modules.
7
+ #
8
+ # For more information @see Ramaze::Contrib.load
9
+ #
10
+ # Usage:
11
+ #
12
+ # Ramaze.contrib :gzip_filter
13
+
5
14
  def self.contrib(*args)
6
- Ramaze::Contrib.load *args
15
+ Contrib.load *args
7
16
  end
8
17
 
18
+ # A module used for loading contrib modules.
19
+
9
20
  module Contrib
10
- class << self
11
- def load(*contribs)
12
- contribs.each do |name|
13
- require 'ramaze/contrib'/name
14
- const = Ramaze::Contrib.const_get(name.to_s.camel_case)
15
- Ramaze::Global.contribs << const
21
+
22
+ # Loads and sets up contrib modules from /ramaze/contrib.
23
+ #
24
+ # === Usage:
25
+ #
26
+ # Ramaze::Contrib.load :gzip_filter
27
+ #
28
+ # === Creating a contrib module:
29
+ #
30
+ # module Ramaze::Contrib::Test
31
+ # def self.setup
32
+ # Log.info "Test module set up"
33
+ # end
34
+ # end
35
+ # class TestController < Ramaze::Controller
36
+ # map '/test'
37
+ # def index; "Chunky Bacon!"; end
38
+ # end
39
+ #
40
+ # # Save that to your <app dir>/contrib and use like:
41
+ # Ramaze.contrib :test
42
+
43
+ def self.load(*contribs)
44
+ contribs.each do |name|
45
+ mod_name = name.to_s.camel_case
46
+ begin
47
+ const = Contrib.const_get(mod_name)
48
+ Global.contribs << const
16
49
  const.startup if const.respond_to?(:startup)
17
- Inform.dev "Loaded contrib: #{const}"
50
+ Log.dev "Loaded contrib: #{const}"
51
+ rescue NameError
52
+ files = Dir["{contrib,#{BASEDIR/:ramaze/:contrib}}/#{name}.{so,bundle,rb}"]
53
+ raise LoadError, "#{mod_name} not found" unless files.any?
54
+ require(files.first) ? retry : raise
18
55
  end
19
56
  end
20
57
  end
21
- end
22
- end
58
+
59
+ # Will call .shutdown on all contrib modules which support it.
60
+ #---
61
+ # .shudown gets called by Ramaze :essentials.
62
+ #+++
63
+
64
+ def self.shutdown
65
+ Global.contribs.each do |contrib|
66
+ contrib.shutdown if contrib.respond_to?(:shutdown)
67
+ end
68
+ end
69
+
70
+ # Will load all contrib modules from options[:contrib]
71
+ #---
72
+ # .startup gets called by Ramaze :essentials.
73
+ #+++
74
+
75
+ def self.startup(options = {})
76
+ return unless options[:contrib]
77
+ [options[:contrib]].flatten.each do |contrib|
78
+ load(contrib)
79
+ end
80
+ end
81
+ end # class Contrib
82
+ end # class Ramaze
@@ -75,7 +75,7 @@ module Ramaze
75
75
 
76
76
  return found.dup
77
77
  else
78
- Inform.warn("Found faulty `#{path}' in Cache.resolved, deleting it for sanity.")
78
+ Log.warn("Found faulty `#{path}' in Cache.resolved, deleting it for sanity.")
79
79
  Cache.resolved.delete path
80
80
  end
81
81
  end
@@ -5,18 +5,18 @@
5
5
  # require 'ramaze/contrib/email'
6
6
  #
7
7
  # # Set the required traits:
8
- # Ramaze::EmailHelper.trait[ :smtp_server ] = 'smtp.your-isp.com'
9
- # Ramaze::EmailHelper.trait[ :smtp_helo_domain ] = "originating-server.com"
10
- # Ramaze::EmailHelper.trait[ :smtp_username ] = 'username'
11
- # Ramaze::EmailHelper.trait[ :smtp_password ] = 'password'
12
- # Ramaze::EmailHelper.trait[ :sender_address ] = 'no-reply@your-domain.com'
8
+ # Ramaze::EmailHelper.trait :smtp_server => 'smtp.your-isp.com',
9
+ # :smtp_helo_domain => "originating-server.com",
10
+ # :smtp_username => 'username',
11
+ # :smtp_password => 'password',
12
+ # :sender_address => 'no-reply@your-domain.com'
13
13
  #
14
14
  # # Optionally, set some other traits:
15
- # Ramaze::EmailHelper.trait[ :smtp_auth_type ] = :login
16
- # Ramaze::EmailHelper.trait[ :bcc_addresses ] = [ 'admin@your-domain.com' ]
17
- # Ramaze::EmailHelper.trait[ :sender_full ] = 'MailBot <no-reply@your-domain.com>'
18
- # Ramaze::EmailHelper.trait[ :id_generator ] = lambda { "<#{Time.now.to_i}@your-domain.com>" }
19
- # Ramaze::EmailHelper.trait[ :subject_prefix ] = "[SiteName]"
15
+ # Ramaze::EmailHelper.trait :smtp_auth_type => :login,
16
+ # :bcc_addresses => [ 'admin@your-domain.com' ],
17
+ # :sender_full => 'MailBot <no-reply@your-domain.com>',
18
+ # :id_generator => lambda { "<#{Time.now.to_i}@your-domain.com>" },
19
+ # :subject_prefix => "[SiteName]"
20
20
  #
21
21
  # To send an e-mail:
22
22
  #
@@ -70,15 +70,15 @@ Message-Id: #{id}
70
70
  def send_smtp( email, recipient, subject )
71
71
  options = trait.values_at(:smtp_server, :smtp_port, :smtp_helo_domain,
72
72
  :smtp_username, :smtp_password, :smtp_auth_type)
73
-
73
+
74
74
  Net::SMTP.start( *options ) do |smtp|
75
75
  smtp.send_message( email, trait[ :sender_address ], Array[ recipient, *trait[ :bcc_addresses ] ] )
76
- Inform.info "E-mail sent to #{recipient} - '#{subject}'"
76
+ Log.info "E-mail sent to #{recipient} - '#{subject}'"
77
77
  end
78
78
  rescue => e
79
- Inform.error "Failed to send e-mail to #{recipient}"
80
- Inform.error e
79
+ Log.error "Failed to send e-mail to #{recipient}"
80
+ Log.error e
81
81
  end
82
82
  end
83
83
  end
84
- end
84
+ end
@@ -1,9 +1,9 @@
1
1
  require __DIR__/:facebook/:facebook
2
2
 
3
3
  module Ramaze
4
- module FacebookHelper
4
+ module Helper::Facebook
5
5
  def self.included(klass)
6
- klass.send(:helper, :aspect, :inform)
6
+ klass.send(:helper, :aspect)
7
7
  end
8
8
 
9
9
  def error
@@ -47,7 +47,7 @@ module Facebook
47
47
  else
48
48
  v.to_s
49
49
  end
50
- }.sort
50
+ }.sort
51
51
 
52
52
  data = Array["sig=#{Digest::MD5.hexdigest(args.join+SECRET)}", *args].join('&')
53
53
 
@@ -71,7 +71,10 @@ module Facebook
71
71
  end
72
72
  end
73
73
 
74
- ret = ret.first if ret.is_a? Array and ret.size == 1 and ret.first.is_a? Hash
74
+ unless method == 'fql.query'
75
+ ret = ret.first if ret.is_a? Array and ret.size == 1 and ret.first.is_a? Hash
76
+ end
77
+
75
78
  raise Facebook::Error, ret['error_msg'] if ret.is_a? Hash and ret['error_code']
76
79
 
77
80
  ret
@@ -83,7 +86,7 @@ module Facebook
83
86
  end
84
87
 
85
88
  def valid?
86
- return false unless private_methods.include? 'request' and not request['fb_sig'].empty?
89
+ return false unless respond_to?(:request) and not request['fb_sig'].nil?
87
90
  request['facebook.valid?'] ||= \
88
91
  request['fb_sig'] == Digest::MD5.hexdigest(request.params.map{|k,v| "#{$1}=#{v}" if k =~ /^fb_sig_(.+)$/ }.compact.sort.join+SECRET)
89
92
  end
@@ -94,7 +97,7 @@ module Facebook
94
97
 
95
98
  def redirect url
96
99
  url[0,0] = URL unless url =~ /^http/
97
- if private_methods.include? 'response'
100
+ if respond_to?(:response)
98
101
  response.build "<fb:redirect url='#{url}'/>"
99
102
  throw :respond
100
103
  else
@@ -0,0 +1,65 @@
1
+ #
2
+ # drop-in replacement for Ramaze's built-in MemoryCache built on the
3
+ # filesystem. # to use with sessions do
4
+ #
5
+ # Ramaze::Global::cache_alternative[:sessions] = Ramaze::FileCache
6
+ #
7
+ # to use with everything do
8
+ #
9
+ # Ramaze::Global::cache = Ramaze::FileCache
10
+ #
11
+
12
+ module Ramaze::FileCache
13
+ require "fileutils"
14
+ require "socket"
15
+
16
+ Host = Socket.gethostname
17
+ Pid = Process.pid
18
+ Fu = FileUtils
19
+ Root = File.join Ramaze::APPDIR, "cache"
20
+
21
+ Fu.mkdir_p(Root) rescue nil
22
+
23
+ def self.[] key
24
+ path = File.join Root, key, "data"
25
+ Marshal.load(IO.read(path))
26
+ rescue
27
+ nil
28
+ end
29
+
30
+ def self.[]= key, value
31
+ tmp = File.join Root, key, "data.#{ Host }.#{ Pid }"
32
+ dirname = File.join Root, key
33
+ path = File.join Root, key, "data"
34
+ data = Marshal.dump value
35
+ Fu.rm_rf dirname rescue nil
36
+ Fu.mkdir_p dirname rescue nil
37
+ open(tmp, 'w'){|fd| fd.write data}
38
+ Fu.mv tmp, path
39
+ rescue
40
+ nil
41
+ end
42
+
43
+ def self.values_at *keys
44
+ keys.map{|key| self[key]}
45
+ end
46
+
47
+ def self.delete *keys
48
+ keys.map do |key|
49
+ dirname = File.join Root, key
50
+ Fu.rm_rf dirname rescue next
51
+ end
52
+ end
53
+
54
+ def self.clear
55
+ Dir["#{ Root }/*"].each{|entry| Fu.rm_rf entry}
56
+ end
57
+
58
+ def self.new
59
+ self
60
+ end
61
+
62
+ def self.to_sym
63
+ name.split(%r/::/).last.to_sym
64
+ end
65
+ end
@@ -22,84 +22,85 @@ require 'ramaze/contrib/gettext/po'
22
22
  #
23
23
  # Ramaze::Dispatcher::Action::FILTER << Ramaze::Tool::Gettext
24
24
 
25
- class Ramaze::Tool::Gettext < Ramaze::Tool::Localize
25
+ module Ramaze
26
+ class Tool::Gettext < Tool::Localize
26
27
 
27
- # Enable Localization
28
- trait :enable => true
28
+ # Enable Localization
29
+ trait :enable => true
29
30
 
30
- # Default language that is used if the browser don't suggests otherwise or
31
- # the language requested is not available.
32
- trait :default_language => 'en'
31
+ # Default language that is used if the browser don't suggests otherwise or
32
+ # the language requested is not available.
33
+ trait :default_language => 'en'
33
34
 
34
- # languages supported
35
- trait :languages => %w[ en ]
35
+ # languages supported
36
+ trait :languages => %w[ en ]
36
37
 
37
- # YAML files the localizations are saved to and loaded from, %s is
38
- # substituted by the values from trait[:languages]
39
- trait :file => 'conf/locale_%s.mo'.freeze
38
+ # YAML files the localizations are saved to and loaded from, %s is
39
+ # substituted by the values from trait[:languages]
40
+ trait :file => 'conf/locale_%s.mo'.freeze
40
41
 
41
- # The pattern that is substituted with the translation of the current locale.
42
- trait :regex => /\[\[(.*?)\]\]/
42
+ # The pattern that is substituted with the translation of the current locale.
43
+ trait :regex => /\[\[(.*?)\]\]/
43
44
 
44
- # Browsers may send different keys for the same language, this allows you to
45
- # do some coercion between what you use as keys and what the browser sends.
46
- trait :mapping => { 'en-us' => 'en', 'ja' => 'jp'}
45
+ # Browsers may send different keys for the same language, this allows you to
46
+ # do some coercion between what you use as keys and what the browser sends.
47
+ trait :mapping => { 'en-us' => 'en', 'ja' => 'jp'}
47
48
 
48
- # When this is set to false, it will not save newly collected translatable
49
- # strings to disk. Disable this for production use, as it slows the
50
- # application down.
51
- trait :collect => true
49
+ # When this is set to false, it will not save newly collected translatable
50
+ # strings to disk. Disable this for production use, as it slows the
51
+ # application down.
52
+ trait :collect => true
52
53
 
53
54
 
54
- # Load given locales from disk and save it into the dictionary.
55
+ # Load given locales from disk and save it into the dictionary.
55
56
 
56
- def self.load(*locales)
57
- Ramaze::Inform.debug "loading locales: #{locales.inspect}"
57
+ def self.load(*locales)
58
+ Log.debug "loading locales: #{locales.inspect}"
58
59
 
59
- dict = trait[:dictionary] || {}
60
+ dict = trait[:dictionary] || {}
60
61
 
61
- locales.each do |locale|
62
- begin
63
- dict[locale] = ::MOFile.open(trait[:file] % locale)
64
- rescue Errno::ENOENT
65
- Ramaze::Inform.error "couldn't load #{trait[:file] % locale}"
66
- dict[locale] = {}
62
+ locales.each do |locale|
63
+ begin
64
+ dict[locale] = ::MOFile.open(trait[:file] % locale)
65
+ rescue Errno::ENOENT
66
+ Log.error "couldn't load #{trait[:file] % locale}"
67
+ dict[locale] = {}
68
+ end
67
69
  end
68
- end
69
70
 
70
- trait[:dictionary] = dict
71
- end
71
+ trait[:dictionary] = dict
72
+ end
72
73
 
73
- # Reloads given locales from the disk to refresh the dictionary.
74
+ # Reloads given locales from the disk to refresh the dictionary.
74
75
 
75
- def self.update
76
- trait[:dictionary] = nil
77
- dictionary.each do |locale, dict|
78
- if dict.kind_of?(MOFile)
79
- Ramaze::Inform.debug("Reloading #{dict.filename}")
80
- dict.update!
76
+ def self.update
77
+ trait[:dictionary] = nil
78
+ dictionary.each do |locale, dict|
79
+ if dict.kind_of?(MOFile)
80
+ Log.debug("Reloading #{dict.filename}")
81
+ dict.update!
82
+ end
81
83
  end
82
84
  end
83
- end
84
85
 
85
- # Stores given locales from the dictionary to disk.
86
+ # Stores given locales from the dictionary to disk.
86
87
 
87
- def self.store(*locales)
88
- keys = []
89
- dictionary.each do |locale, dict|
90
- keys.concat dict.keys
91
- end
92
- keys.delete ""
88
+ def self.store(*locales)
89
+ keys = []
90
+ dictionary.each do |locale, dict|
91
+ keys.concat dict.keys
92
+ end
93
+ keys.delete ""
93
94
 
94
- data = ::GetText::RGetText.generate(keys.compact.uniq.sort.map {|x| [x] })
95
- file = (trait[:file] % trait[:default_language]) + '.pot'
96
- File.open(file, File::CREAT|File::TRUNC|File::WRONLY) do |fd|
97
- fd.write data
95
+ data = ::GetText::RGetText.generate(keys.compact.uniq.sort.map {|x| [x] })
96
+ file = (trait[:file] % trait[:default_language]) + '.pot'
97
+ File.open(file, File::CREAT|File::TRUNC|File::WRONLY) do |fd|
98
+ fd.write data
99
+ end
100
+ rescue Errno::ENOENT => e
101
+ Log.error e
98
102
  end
99
- rescue Errno::ENOENT => e
100
- Ramaze::Inform.error e
101
103
  end
102
-
103
104
  end
104
105
 
105
106
  class Ramaze::Contrib::Gettext