ramaze 2011.01.30 → 2011.07.25

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 (229) hide show
  1. data/.gitignore +2 -1
  2. data/.mailmap +2 -0
  3. data/.rvmrc +1 -0
  4. data/README.md +119 -197
  5. data/Rakefile +14 -97
  6. data/bin/ramaze +6 -14
  7. data/doc/AUTHORS +8 -4
  8. data/doc/CHANGELOG +3784 -3339
  9. data/examples/app/chat/start.rb +2 -2
  10. data/lib/proto/app.rb +2 -3
  11. data/lib/proto/config.ru +4 -5
  12. data/lib/proto/controller/init.rb +11 -4
  13. data/lib/proto/controller/main.rb +12 -7
  14. data/lib/proto/layout/default.xhtml +56 -23
  15. data/lib/proto/model/init.rb +3 -1
  16. data/lib/proto/public/css/grid.css +107 -0
  17. data/lib/proto/public/css/layout.css +81 -0
  18. data/lib/proto/public/css/reset.css +123 -0
  19. data/lib/proto/public/css/text.css +109 -0
  20. data/lib/proto/public/images/bg.png +0 -0
  21. data/lib/proto/spec/main.rb +2 -2
  22. data/lib/proto/start.rb +11 -1
  23. data/lib/proto/view/index.xhtml +27 -23
  24. data/lib/ramaze.rb +0 -1
  25. data/lib/ramaze/app.rb +85 -12
  26. data/lib/ramaze/app_graph.rb +107 -0
  27. data/lib/ramaze/bin/console.rb +87 -0
  28. data/lib/ramaze/bin/create.rb +94 -0
  29. data/lib/ramaze/bin/helper.rb +107 -0
  30. data/lib/ramaze/bin/restart.rb +95 -0
  31. data/lib/ramaze/bin/runner.rb +141 -0
  32. data/lib/ramaze/bin/start.rb +206 -0
  33. data/lib/ramaze/bin/status.rb +152 -0
  34. data/lib/ramaze/bin/stop.rb +112 -0
  35. data/lib/ramaze/cache.rb +9 -4
  36. data/lib/ramaze/cache/localmemcache.rb +10 -13
  37. data/lib/ramaze/cache/lru.rb +49 -7
  38. data/lib/ramaze/cache/memcache.rb +170 -92
  39. data/lib/ramaze/cache/sequel.rb +301 -118
  40. data/lib/ramaze/controller.rb +108 -9
  41. data/lib/ramaze/controller/default.rb +15 -2
  42. data/lib/ramaze/current.rb +14 -2
  43. data/lib/ramaze/dependencies.rb +46 -0
  44. data/lib/ramaze/files.rb +38 -3
  45. data/lib/ramaze/gestalt.rb +12 -12
  46. data/lib/ramaze/helper.rb +0 -2
  47. data/lib/ramaze/helper/auth.rb +30 -23
  48. data/lib/ramaze/helper/blue_form.rb +175 -126
  49. data/lib/ramaze/helper/csrf.rb +76 -91
  50. data/lib/ramaze/helper/email.rb +105 -0
  51. data/lib/ramaze/helper/erector.rb +16 -15
  52. data/lib/ramaze/helper/gestalt.rb +2 -2
  53. data/lib/ramaze/helper/layout.rb +89 -73
  54. data/lib/ramaze/helper/link.rb +7 -6
  55. data/lib/ramaze/helper/localize.rb +6 -5
  56. data/lib/ramaze/helper/markaby.rb +25 -23
  57. data/lib/ramaze/helper/maruku.rb +3 -3
  58. data/lib/ramaze/helper/paginate.rb +19 -27
  59. data/lib/ramaze/helper/remarkably.rb +3 -3
  60. data/lib/ramaze/helper/request_accessor.rb +3 -3
  61. data/lib/ramaze/helper/send_file.rb +12 -8
  62. data/lib/ramaze/helper/simple_captcha.rb +5 -6
  63. data/lib/ramaze/helper/stack.rb +7 -4
  64. data/lib/ramaze/helper/tagz.rb +10 -11
  65. data/lib/ramaze/helper/thread.rb +19 -16
  66. data/lib/ramaze/helper/ultraviolet.rb +7 -4
  67. data/lib/ramaze/helper/user.rb +40 -21
  68. data/lib/ramaze/helper/xhtml.rb +29 -20
  69. data/lib/ramaze/log.rb +3 -11
  70. data/lib/ramaze/log/analogger.rb +5 -4
  71. data/lib/ramaze/log/growl.rb +9 -7
  72. data/lib/ramaze/log/hub.rb +3 -5
  73. data/lib/ramaze/log/informer.rb +15 -12
  74. data/lib/ramaze/log/knotify.rb +3 -5
  75. data/lib/ramaze/log/logger.rb +3 -5
  76. data/lib/ramaze/log/logging.rb +6 -8
  77. data/lib/ramaze/log/rotatinginformer.rb +27 -17
  78. data/lib/ramaze/log/syslog.rb +7 -7
  79. data/lib/ramaze/log/xosd.rb +3 -5
  80. data/lib/ramaze/middleware_compiler.rb +27 -4
  81. data/lib/ramaze/reloader.rb +50 -12
  82. data/lib/ramaze/reloader/watch_inotify.rb +4 -5
  83. data/lib/ramaze/reloader/watch_stat.rb +3 -3
  84. data/lib/ramaze/request.rb +18 -8
  85. data/lib/ramaze/response.rb +38 -7
  86. data/lib/ramaze/rest.rb +36 -0
  87. data/lib/ramaze/setup.rb +101 -31
  88. data/lib/ramaze/spec.rb +1 -1
  89. data/lib/ramaze/spec/bacon.rb +6 -3
  90. data/lib/ramaze/spec/helper/bacon.rb +0 -1
  91. data/lib/ramaze/version.rb +1 -1
  92. data/lib/ramaze/view.rb +2 -11
  93. data/lib/ramaze/view/erector.rb +46 -31
  94. data/lib/ramaze/view/erubis.rb +7 -3
  95. data/lib/ramaze/view/ezamar.rb +7 -3
  96. data/lib/ramaze/view/gestalt.rb +9 -3
  97. data/lib/ramaze/view/haml.rb +7 -3
  98. data/lib/ramaze/view/liquid.rb +3 -3
  99. data/lib/ramaze/view/lokar.rb +7 -3
  100. data/lib/ramaze/view/mustache.rb +11 -5
  101. data/lib/ramaze/view/nagoro.rb +3 -3
  102. data/lib/ramaze/view/sass.rb +1 -1
  103. data/lib/ramaze/view/slippers.rb +40 -13
  104. data/lib/ramaze/view/tagz.rb +9 -5
  105. data/ramaze.gemspec +23 -128
  106. data/spec/helper.rb +5 -0
  107. data/spec/ramaze/bin/app/config.ru +11 -0
  108. data/spec/ramaze/bin/create.rb +28 -0
  109. data/spec/ramaze/bin/runner.rb +30 -0
  110. data/spec/ramaze/bin/start.rb +38 -0
  111. data/spec/ramaze/cache/memcache.rb +10 -3
  112. data/spec/ramaze/cache/sequel.rb +7 -0
  113. data/spec/ramaze/controller/provide_inheritance.rb +0 -10
  114. data/spec/ramaze/dispatcher/file.rb +19 -15
  115. data/spec/ramaze/helper/auth.rb +10 -9
  116. data/spec/ramaze/helper/blue_form.rb +121 -68
  117. data/spec/ramaze/helper/email.rb +69 -0
  118. data/spec/ramaze/helper/layout.rb +12 -15
  119. data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
  120. data/spec/ramaze/helper/user.rb +2 -0
  121. data/spec/ramaze/log/growl.rb +14 -1
  122. data/spec/{contrib → ramaze}/rest.rb +1 -1
  123. data/spec/ramaze/session/memcache.rb +2 -2
  124. data/spec/ramaze/view/sass.rb +1 -1
  125. data/tasks/bacon.rake +3 -3
  126. data/tasks/gem.rake +17 -18
  127. data/tasks/rcov.rake +2 -3
  128. data/tasks/release.rake +8 -65
  129. data/tasks/setup.rake +10 -8
  130. data/tasks/todo.rake +9 -5
  131. data/tasks/yard.rake +3 -2
  132. metadata +105 -397
  133. data/MANIFEST +0 -532
  134. data/TODO.md +0 -19
  135. data/benchmark/bench_templates/bench.rb +0 -67
  136. data/benchmark/bench_templates/view/large.erb +0 -79
  137. data/benchmark/bench_templates/view/large.haml +0 -41
  138. data/benchmark/bench_templates/view/large.lok +0 -79
  139. data/benchmark/bench_templates/view/large.xhtml +0 -79
  140. data/benchmark/bench_templates/view/small.erb +0 -21
  141. data/benchmark/bench_templates/view/small.haml +0 -12
  142. data/benchmark/bench_templates/view/small.lok +0 -21
  143. data/benchmark/bench_templates/view/small.xhtml +0 -21
  144. data/benchmark/results.txt +0 -131
  145. data/benchmark/run.rb +0 -355
  146. data/benchmark/suite/minimal.rb +0 -11
  147. data/benchmark/suite/no_informer.rb +0 -7
  148. data/benchmark/suite/no_sessions.rb +0 -9
  149. data/benchmark/suite/no_template.rb +0 -7
  150. data/benchmark/suite/simple.rb +0 -5
  151. data/benchmark/suite/template_erubis.rb +0 -8
  152. data/benchmark/suite/template_etanni.rb +0 -8
  153. data/benchmark/suite/template_ezamar.rb +0 -8
  154. data/benchmark/suite/template_haml.rb +0 -13
  155. data/benchmark/suite/template_liquid.rb +0 -11
  156. data/benchmark/suite/template_markaby.rb +0 -9
  157. data/benchmark/suite/template_nagoro.rb +0 -8
  158. data/benchmark/suite/template_redcloth.rb +0 -13
  159. data/benchmark/suite/template_tenjin.rb +0 -8
  160. data/benchmark/test.rb +0 -35
  161. data/doc/FAQ +0 -92
  162. data/doc/INSTALL +0 -92
  163. data/doc/TODO +0 -29
  164. data/doc/meta/announcement.txt +0 -119
  165. data/doc/meta/configuration.txt +0 -163
  166. data/doc/meta/internals.txt +0 -278
  167. data/doc/meta/users.kml +0 -64
  168. data/doc/tutorial/todolist.html +0 -1512
  169. data/doc/tutorial/todolist.txt +0 -920
  170. data/examples/app/sourceview/public/coderay.css +0 -104
  171. data/examples/app/sourceview/public/images/file.gif +0 -0
  172. data/examples/app/sourceview/public/images/folder.gif +0 -0
  173. data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
  174. data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
  175. data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
  176. data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
  177. data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
  178. data/examples/app/sourceview/public/images/tv-item.gif +0 -0
  179. data/examples/app/sourceview/public/jquery.js +0 -11
  180. data/examples/app/sourceview/public/jquery.treeview.css +0 -48
  181. data/examples/app/sourceview/public/jquery.treeview.js +0 -223
  182. data/examples/app/sourceview/public/sourceview.js +0 -52
  183. data/examples/app/sourceview/start.rb +0 -79
  184. data/examples/app/sourceview/view/index.haml +0 -59
  185. data/examples/helpers/httpdigest.rb +0 -107
  186. data/lib/proto/public/css/screen.css +0 -30
  187. data/lib/proto/public/js/jquery.js +0 -7179
  188. data/lib/ramaze/contrib/addressable_route.rb +0 -56
  189. data/lib/ramaze/contrib/app_graph.rb +0 -64
  190. data/lib/ramaze/contrib/email.rb +0 -88
  191. data/lib/ramaze/contrib/facebook.rb +0 -23
  192. data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
  193. data/lib/ramaze/contrib/gettext.rb +0 -113
  194. data/lib/ramaze/contrib/gettext/mo.rb +0 -155
  195. data/lib/ramaze/contrib/gettext/parser.rb +0 -46
  196. data/lib/ramaze/contrib/gettext/po.rb +0 -109
  197. data/lib/ramaze/contrib/gzip_filter.rb +0 -1
  198. data/lib/ramaze/contrib/maruku_uv.rb +0 -59
  199. data/lib/ramaze/contrib/profiling.rb +0 -36
  200. data/lib/ramaze/contrib/rest.rb +0 -23
  201. data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
  202. data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
  203. data/lib/ramaze/contrib/sequel/image.rb +0 -196
  204. data/lib/ramaze/contrib/sequel/relation.rb +0 -98
  205. data/lib/ramaze/helper/httpdigest.rb +0 -96
  206. data/lib/ramaze/tool/bin.rb +0 -340
  207. data/lib/ramaze/tool/create.rb +0 -48
  208. data/lib/ramaze/tool/project_creator.rb +0 -120
  209. data/lib/ramaze/view/less.rb +0 -12
  210. data/lib/ramaze/view/maruku.rb +0 -15
  211. data/lib/ramaze/view/redcloth.rb +0 -21
  212. data/spec/contrib/addressable_route.rb +0 -30
  213. data/spec/examples/helpers/httpdigest.rb +0 -64
  214. data/spec/examples/templates/template_redcloth.rb +0 -13
  215. data/spec/ramaze/bin/ramaze.rb +0 -96
  216. data/spec/ramaze/helper/httpdigest.rb +0 -176
  217. data/spec/ramaze/view/less.rb +0 -60
  218. data/spec/ramaze/view/less/file.css.less +0 -8
  219. data/spec/ramaze/view/redcloth.rb +0 -66
  220. data/spec/ramaze/view/redcloth/external.redcloth +0 -8
  221. data/tasks/copyright.rake +0 -21
  222. data/tasks/gem_setup.rake +0 -112
  223. data/tasks/git.rake +0 -46
  224. data/tasks/grancher.rake +0 -12
  225. data/tasks/jquery.rake +0 -15
  226. data/tasks/manifest.rake +0 -4
  227. data/tasks/metric_changes.rake +0 -24
  228. data/tasks/reversion.rake +0 -8
  229. data/tasks/traits.rake +0 -21
@@ -1,56 +0,0 @@
1
- require "addressable/template"
2
-
3
- module Ramaze
4
- # This is a simple prototype-implementation of how we could do routing
5
- # supported by URI templates.
6
- #
7
- # Please see the spec for example usage as it's not integrated yet in any way.
8
- #
9
- # What it does is basically that you can give it any URI template and a final
10
- # mapping, and it will extract the variables from the URI and merge them into
11
- # the QUERY_STRING, which is parsed again in Ramaze if you issue
12
- # Request#params.
13
- #
14
- # @example given mapping like:
15
- #
16
- # map('/customer/{customer_id}/order/{order_id}', '/order/show')
17
- #
18
- # @example output of request.params at '/order/show'
19
- #
20
- # {'customer_id => '12', 'order_id' => '15'}
21
- #
22
- # I haven't explored the full capabilities of the templates yet, but the
23
- # specs of Addressable::Template suggest that there is a lot to be
24
- # discovered.
25
- class AddressableRoute
26
- def initialize(app, routes = {})
27
- @app = app
28
- @routes = {}
29
-
30
- routes.each{|from, to| map(from, to) }
31
- end
32
-
33
- def call(env)
34
- path_info = env['PATH_INFO']
35
-
36
- @routes.each do |template, target|
37
- extracted = template.extract(path_info)
38
- return dispatch(env, target, extracted) if extracted
39
- end
40
-
41
- @app.call(env)
42
- end
43
-
44
- def map(from, to)
45
- @routes[Addressable::Template.new(from)] = to
46
- end
47
-
48
- def dispatch(env, target, extracted)
49
- env['PATH_INFO'] = target
50
- original = Rack::Utils.parse_query(env['QUERY_STRING'])
51
- env['QUERY_STRING'] = Rack::Utils.build_query(original.merge(extracted))
52
-
53
- @app.call(env)
54
- end
55
- end
56
- end
@@ -1,64 +0,0 @@
1
- require 'set'
2
-
3
- # require 'ramaze/contrib/app_graph'
4
- #
5
- # graph = AppGraph.new
6
- # graph.generate
7
- # graph.show
8
-
9
- class AppGraph
10
- def initialize
11
- @out = Set.new
12
- end
13
-
14
- def generate
15
- Ramaze::AppMap.to_hash.each do |location, app|
16
- connect(location => app.name)
17
-
18
- app.url_map.to_hash.each do |c_location, c_node|
19
- connect(app.name => c_node)
20
- connect(c_node.mapping => c_node)
21
-
22
- c_node.update_template_mappings
23
- c_node.view_templates.each do |wish, mapping|
24
- mapping.each do |action_name, template|
25
- action_path = File.join(c_node.mapping, action_name)
26
- connect(c_node => action_path, action_path => template)
27
- end
28
- end
29
-
30
- c_node.update_method_arities
31
- c_node.method_arities.each do |method, arity|
32
- action_path = File.join(c_node.mapping, method.to_s)
33
- connect(action_path => "#{c_node}##{method}[#{arity}]", c_node => action_path)
34
- end
35
- end
36
- end
37
- end
38
-
39
- def connect(hash)
40
- hash.each do |from, to|
41
- @out << (" %p -> %p;" % [from.to_s, to.to_s])
42
- end
43
- end
44
-
45
- def write_dot
46
- File.open('graph.dot', 'w+') do |dot|
47
- dot.puts 'digraph appmap {'
48
- dot.puts(*@out)
49
- dot.puts '}'
50
- end
51
- end
52
-
53
- def show
54
- write_dot
55
- options = {
56
- 'rankdir' => 'LR',
57
- 'splines' => 'true',
58
- 'overlap' => 'false',
59
- }
60
- args = options.map{|k,v| "-G#{k}=#{v}" }
61
- system("dot -O -Tpng #{args.join(' ')} graph.dot")
62
- system('feh graph.dot.png')
63
- end
64
- end
@@ -1,88 +0,0 @@
1
- # EmailHelper can be used as a simple way to send basic e-mails from your app.
2
- #
3
- # Usage:
4
- #
5
- # require 'ramaze/contrib/email'
6
- #
7
- # # Set the required traits:
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
- #
14
- # # Optionally, set some other traits:
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
- #
21
- # To send an e-mail:
22
- #
23
- # Ramaze::EmailHelper.send(
24
- # "foo@foobarmail.com",
25
- # "Your fooness",
26
- # "Hey, you are very fooey!"
27
- # )
28
-
29
- require 'net/smtp'
30
-
31
- module Ramaze
32
- class EmailHelper
33
- include Innate::Traited
34
-
35
- # Required to be set
36
- trait :smtp_server => 'smtp.your-isp.com'
37
- trait :smtp_helo_domain => 'your.helo.domain.com'
38
- trait :smtp_username => 'no-username-set'
39
- trait :smtp_password => ''
40
- trait :sender_address => 'no-reply@your-domain.com'
41
-
42
- # Optionally set
43
- trait :smtp_port => 25
44
- trait :smtp_auth_type => :login
45
- trait :bcc_addresses => []
46
- trait :sender_full => nil
47
- trait :id_generator => lambda { "<" + Time.now.to_i.to_s + "@" + trait[ :smtp_helo_domain ] + ">" }
48
- trait :subject_prefix => ""
49
-
50
- class << self
51
- def send(recipient, subject, message)
52
- {:recipient => recipient, :subject => subject, :message => message}.each do |k,v|
53
- if v.nil? or v.empty?
54
- raise(ArgumentError, "EmailHelper error: Missing or invalid #{k}: #{v.inspect}")
55
- end
56
- end
57
- sender = trait[:sender_full] || "#{trait[:sender_address]} <#{trait[:sender_address]}>"
58
- subject = [trait[:subject_prefix], subject].join(' ').strip
59
- id = trait[:id_generator].call
60
- email = %{From: #{sender}
61
- To: <#{recipient}>
62
- Date: #{Time.now.rfc2822}
63
- Subject: #{subject}
64
- Message-Id: #{id}
65
-
66
- #{message}
67
- }
68
-
69
- send_smtp( email, recipient, subject )
70
- end
71
-
72
- # the raw mail sending method used by Ramaze::EmailHelper
73
-
74
- def send_smtp( email, recipient, subject )
75
- options = trait.values_at(:smtp_server, :smtp_port, :smtp_helo_domain,
76
- :smtp_username, :smtp_password, :smtp_auth_type)
77
-
78
- Net::SMTP.start( *options ) do |smtp|
79
- smtp.send_message( email, trait[ :sender_address ], Array[ recipient, *trait[ :bcc_addresses ] ] )
80
- Log.info "E-mail sent to #{recipient} - '#{subject}'"
81
- end
82
- rescue => e
83
- Log.error "Failed to send e-mail to #{recipient}"
84
- Log.error [ e.class.to_s, e.message, *e.backtrace ].join( "\t\n" )
85
- end
86
- end
87
- end
88
- end
@@ -1,23 +0,0 @@
1
- require __DIR__('facebook/facebook')
2
-
3
- module Ramaze
4
- module Helper::Facebook
5
- def self.included(klass)
6
- klass.send(:helper, :aspect)
7
- end
8
-
9
- def error
10
- if Facebook::ADMINS.include? facebook[:user]
11
- error = Ramaze::Dispatcher::Error.current
12
- [error, *error.backtrace].join '<br/>'
13
- end
14
- end
15
-
16
- private
17
-
18
- def facebook
19
- @facebook ||= Facebook::Client.new
20
- end
21
- alias fb facebook
22
- end
23
- end
@@ -1,171 +0,0 @@
1
- require 'rubygems'
2
- require 'socket'
3
- require 'digest'
4
- require 'json'
5
- require 'cgi'
6
-
7
- module Facebook
8
- class Error < StandardError
9
- end
10
-
11
- class APIProxy
12
- instance_methods.each { |m| undef_method m unless m =~ /^__/ }
13
-
14
- def initialize name, client
15
- @name, @client = name, client
16
- end
17
-
18
- def method_missing method, opts = {}
19
- @client.call "#{@name}.#{method}", opts
20
- end
21
- end
22
-
23
- class Client
24
- include Ramaze::Trinity if defined? Ramaze
25
-
26
- def initialize keepalive = true
27
- @keepalive = keepalive
28
- @proxies = {}
29
- end
30
-
31
- %w[ auth fbml feed fql friends notifications profile users pages events groups photos marketplace ].each do |n|
32
- define_method(n){ @proxies[n] ||= APIProxy.new(n, self) }
33
- end
34
-
35
- def call method, opts = {}
36
- args = { :api_key => KEY,
37
- :call_id => Time.now.to_f,
38
- :format => 'JSON',
39
- :v => '1.0',
40
- :session_key => params[:session_key] || SESSION,
41
- :method => method }.merge(opts).map{ |k,v|
42
- "#{k}=" + case v
43
- when Hash
44
- v.to_json
45
- when Array
46
- v.join(',')
47
- else
48
- v.to_s
49
- end
50
- }.sort
51
-
52
- data = Array["sig=#{Digest::MD5.hexdigest(args.join+SECRET)}", *args].join('&')
53
-
54
- begin
55
- ret = post(data)
56
- rescue Errno::ECONNRESET, Errno::EPIPE
57
- @server = connect
58
- retry
59
- end while ret.empty? and @server = connect
60
-
61
- ret = case
62
- when ret == 'true'; true
63
- when ret == 'false'; false
64
- when ret[0..0] == '"'; ret[1..-2]
65
- else
66
- begin
67
- JSON::parse(ret)
68
- rescue JSON::ParserError
69
- puts "Error parsing #{ret.inspect}"
70
- raise
71
- end
72
- end
73
-
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
-
78
- raise Facebook::Error, ret['error_msg'] if ret.is_a? Hash and ret['error_code']
79
-
80
- ret
81
- ensure
82
- unless @keepalive
83
- @server.close
84
- @server = nil
85
- end
86
- end
87
-
88
- def valid?
89
- return false unless respond_to?(:request) and not request['fb_sig'].nil?
90
- request['facebook.valid?'] ||= \
91
- request['fb_sig'] == Digest::MD5.hexdigest(request.params.map{|k,v| "#{$1}=#{v}" if k =~ /^fb_sig_(.+)$/ }.compact.sort.join+SECRET)
92
- end
93
-
94
- def [] key
95
- params[key]
96
- end
97
-
98
- def redirect url
99
- url[0,0] = URL unless url =~ /^http/
100
- if respond_to?(:response)
101
- response.build "<fb:redirect url='#{url}'/>"
102
- throw :respond
103
- else
104
- "<fb:redirect url='#{url}'/>"
105
- end
106
- end
107
-
108
- def addurl goto = '/'
109
- "http://apps.facebook.com/add.php?api_key=#{KEY}&next=#{CGI.escape '?next='+goto}"
110
- end
111
-
112
- def params
113
- return {} unless valid?
114
- request['facebook'] ||= \
115
- request.params.inject({}) { |h,(k,v)|
116
- next h unless k =~ /^fb_sig_(.+)$/
117
- k = $1.to_sym
118
-
119
- case k.to_s
120
- when 'friends'
121
- h[k] = v.split(',').map{|e|e.to_i}
122
- when /time$/
123
- h[k] = Time.at(v.to_f)
124
- when 'expires'
125
- v = v.to_i
126
- h[k] = v>0 ? Time.at(v) : v
127
- when 'user'
128
- h[k] = v.to_i
129
- when /^(position_|in_|is_|added)/
130
- h[k] = v=='1'
131
- else
132
- h[k] = v
133
- end
134
- h
135
- }
136
- end
137
-
138
- private
139
-
140
- def connect
141
- @socket.close if @socket
142
- TCPSocket.new('api.facebook.com', 80)
143
- end
144
-
145
- def post data
146
- @server ||= connect
147
-
148
- @server.puts "POST /restserver.php HTTP/1.1\r\n"
149
- @server.puts "Host: api.facebook.com\r\n"
150
- @server.puts "Connection: keep-alive\r\n" if @keepalive
151
- @server.puts "Content-Type: application/x-www-form-urlencoded\r\n"
152
- @server.puts "Content-Length: #{data.length}\r\n"
153
- @server.puts "\r\n#{data}\r\n"
154
- @server.puts "\r\n\r\n"
155
-
156
- buf = ''
157
- while @server.gets
158
- if $_ == "\r\n"
159
- @server.gets
160
- if $_.strip! == '0'
161
- @server.gets
162
- break
163
- end
164
- buf << @server.read($_.to_i(16))
165
- end
166
- end
167
-
168
- buf
169
- end
170
- end
171
- end
@@ -1,113 +0,0 @@
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
- require 'ramaze/tool/localize'
5
- require 'ramaze/contrib/gettext/mo'
6
- require 'ramaze/contrib/gettext/po'
7
-
8
- # Gettext helps transforming arbitrary text into localized forms using
9
- # a simple regular expression and substituting occurences with translations
10
- # stored in .mo files.
11
- #
12
- # == MO generation
13
- #
14
- # See http://www.gnu.org/software/gettext/ for a general overview over
15
- # Gettext. Generally it's easier to use a graphical translator like Poedit.
16
- #
17
- # The default language is en, a .po template file will be saved by default
18
- # under `conf/locale_en.mo.pot`. Individual languages are by default looked
19
- # up at `conf/locale_fi.mo` for localization.
20
- #
21
- # == Usage:
22
- #
23
- # Ramaze::Dispatcher::Action::FILTER << Ramaze::Tool::Gettext
24
-
25
- module Ramaze
26
- class Tool::Gettext < Tool::Localize
27
-
28
- # Enable Localization
29
- trait :enable => true
30
-
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'
34
-
35
- # languages supported
36
- trait :languages => %w[ en ]
37
-
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
41
-
42
- # The pattern that is substituted with the translation of the current locale.
43
- trait :regex => /\[\[(.*?)\]\]/
44
-
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'}
48
-
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
53
-
54
-
55
- # Load given locales from disk and save it into the dictionary.
56
-
57
- def self.load(*locales)
58
- Log.debug "loading locales: #{locales.inspect}"
59
-
60
- dict = trait[:dictionary] || {}
61
-
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
69
- end
70
-
71
- trait[:dictionary] = dict
72
- end
73
-
74
- # Reloads given locales from the disk to refresh the dictionary.
75
-
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
83
- end
84
- end
85
-
86
- # Stores given locales from the dictionary to disk.
87
-
88
- def self.store(*locales)
89
- keys = []
90
- dictionary.each do |locale, dict|
91
- keys.concat dict.keys
92
- end
93
- keys.delete ""
94
-
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
102
- end
103
- end
104
- end
105
-
106
- class Ramaze::Contrib::Gettext
107
-
108
- # Called by Ramaze::Contrib.load, adds Gettext to Action::Filter
109
-
110
- def self.startup
111
- Ramaze::Dispatcher::Action::FILTER << Ramaze::Tool::Gettext
112
- end
113
- end