ramaze 0.2.1 → 0.3.0

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 (304) hide show
  1. data/Rakefile +20 -3
  2. data/bin/ramaze +1 -4
  3. data/doc/AUTHORS +2 -1
  4. data/doc/CHANGELOG +539 -32
  5. data/doc/LEGAL +4 -0
  6. data/doc/meta/announcement.txt +79 -47
  7. data/examples/blog/README +2 -2
  8. data/examples/blog/spec/blog.rb +33 -48
  9. data/examples/blog/src/controller.rb +15 -13
  10. data/examples/blog/src/model.rb +28 -10
  11. data/examples/blog/start.rb +0 -10
  12. data/examples/blog/template/edit.xhtml +1 -1
  13. data/examples/blog/template/index.xhtml +2 -2
  14. data/examples/facebook.rb +152 -0
  15. data/examples/linking.rb +28 -0
  16. data/examples/ramaise.rb +4 -11
  17. data/examples/rammit/spec/rammit.rb +30 -0
  18. data/examples/rammit/src/controller/main.rb +3 -0
  19. data/examples/rammit/src/controller/page.rb +16 -0
  20. data/examples/rammit/src/model.rb +33 -0
  21. data/examples/rammit/start.rb +7 -0
  22. data/examples/rammit/template/index.xhtml +14 -0
  23. data/examples/rammit/template/page/view.xhtml +4 -0
  24. data/examples/rapaste/Rakefile +28 -0
  25. data/examples/rapaste/public/css/active4d.css +114 -0
  26. data/examples/rapaste/public/css/all_hallows_eve.css +72 -0
  27. data/examples/rapaste/public/css/amy.css +147 -0
  28. data/examples/rapaste/public/css/blackboard.css +88 -0
  29. data/examples/rapaste/public/css/brilliance_black.css +605 -0
  30. data/examples/rapaste/public/css/brilliance_dull.css +599 -0
  31. data/examples/rapaste/public/css/cobalt.css +149 -0
  32. data/examples/rapaste/public/css/dawn.css +121 -0
  33. data/examples/rapaste/public/css/display.css +179 -0
  34. data/examples/rapaste/public/css/eiffel.css +121 -0
  35. data/examples/rapaste/public/css/espresso_libre.css +109 -0
  36. data/examples/rapaste/public/css/idle.css +62 -0
  37. data/examples/rapaste/public/css/iplastic.css +80 -0
  38. data/examples/rapaste/public/css/lazy.css +73 -0
  39. data/examples/rapaste/public/css/mac_classic.css +123 -0
  40. data/examples/rapaste/public/css/magicwb_amiga.css +104 -0
  41. data/examples/rapaste/public/css/pastels_on_dark.css +188 -0
  42. data/examples/rapaste/public/css/slush_poppies.css +85 -0
  43. data/examples/rapaste/public/css/spacecadet.css +51 -0
  44. data/examples/rapaste/public/css/sunburst.css +180 -0
  45. data/examples/rapaste/public/css/twilight.css +137 -0
  46. data/examples/rapaste/public/css/zenburnesque.css +91 -0
  47. data/examples/rapaste/public/js/jquery.js +11 -0
  48. data/examples/rapaste/rapaste.sqlite +0 -0
  49. data/examples/rapaste/spec/rapaste.rb +49 -0
  50. data/examples/rapaste/src/controller.rb +69 -0
  51. data/examples/rapaste/src/model.rb +61 -0
  52. data/examples/rapaste/start.rb +20 -0
  53. data/examples/rapaste/template/copy.xhtml +10 -0
  54. data/examples/rapaste/template/index.xhtml +9 -0
  55. data/examples/rapaste/template/layout.xhtml +22 -0
  56. data/examples/rapaste/template/list.xhtml +28 -0
  57. data/examples/rapaste/template/view.xhtml +37 -0
  58. data/examples/sourceview/sourceview.rb +3 -3
  59. data/examples/templates/template_amrita2.rb +1 -3
  60. data/examples/todolist/spec/todolist.rb +15 -18
  61. data/examples/whywiki/spec/whywiki.rb +15 -20
  62. data/examples/whywiki/start.rb +0 -1
  63. data/examples/wikore/spec/wikore.rb +14 -19
  64. data/examples/wiktacular/spec/wiktacular.rb +8 -15
  65. data/lib/proto/{src/controller → controller}/main.rb +4 -4
  66. data/lib/proto/public/css/ramaze_error.css +39 -3
  67. data/lib/proto/public/js/jquery.js +2039 -1020
  68. data/lib/proto/spec/main.rb +27 -0
  69. data/lib/proto/start.rb +5 -5
  70. data/lib/proto/view/error.xhtml +62 -0
  71. data/lib/proto/view/index.xhtml +34 -0
  72. data/lib/proto/view/page.xhtml +15 -0
  73. data/lib/ramaze.rb +9 -7
  74. data/lib/ramaze/action.rb +7 -3
  75. data/lib/ramaze/action/render.rb +15 -5
  76. data/lib/ramaze/adapter.rb +5 -5
  77. data/lib/ramaze/adapter/base.rb +2 -2
  78. data/lib/ramaze/adapter/cgi.rb +1 -1
  79. data/lib/ramaze/adapter/evented_mongrel.rb +1 -1
  80. data/lib/ramaze/adapter/fcgi.rb +2 -2
  81. data/lib/ramaze/adapter/mongrel.rb +1 -1
  82. data/lib/ramaze/adapter/swiftiplied_mongrel.rb +1 -1
  83. data/lib/ramaze/adapter/thin.rb +25 -0
  84. data/lib/ramaze/adapter/webrick.rb +1 -1
  85. data/lib/ramaze/cache.rb +3 -2
  86. data/lib/ramaze/cache/memcached.rb +1 -1
  87. data/lib/ramaze/cache/memory.rb +1 -1
  88. data/lib/ramaze/cache/yaml_store.rb +1 -1
  89. data/lib/ramaze/contrib.rb +1 -1
  90. data/lib/ramaze/contrib/auto_params.rb +12 -5
  91. data/lib/ramaze/contrib/auto_params/get_args.rb +1 -0
  92. data/lib/ramaze/contrib/facebook.rb +23 -0
  93. data/lib/ramaze/contrib/facebook/facebook.rb +168 -0
  94. data/lib/ramaze/contrib/gettext.rb +111 -0
  95. data/lib/ramaze/contrib/gettext/mo.rb +155 -0
  96. data/lib/ramaze/contrib/gettext/po.rb +109 -0
  97. data/lib/ramaze/contrib/gzip_filter.rb +1 -1
  98. data/lib/ramaze/contrib/route.rb +15 -5
  99. data/lib/ramaze/contrib/sequel/fill.rb +1 -1
  100. data/lib/ramaze/controller.rb +10 -4
  101. data/lib/ramaze/controller/error.rb +5 -13
  102. data/lib/ramaze/controller/main.rb +2 -0
  103. data/lib/ramaze/controller/resolve.rb +18 -10
  104. data/lib/ramaze/dispatcher.rb +1 -1
  105. data/lib/ramaze/dispatcher/action.rb +1 -1
  106. data/lib/ramaze/dispatcher/directory.rb +3 -2
  107. data/lib/ramaze/dispatcher/error.rb +5 -5
  108. data/lib/ramaze/dispatcher/file.rb +13 -2
  109. data/lib/ramaze/error.rb +1 -1
  110. data/lib/ramaze/gestalt.rb +2 -2
  111. data/lib/ramaze/global.rb +5 -5
  112. data/lib/ramaze/global/dsl.rb +1 -1
  113. data/lib/ramaze/global/globalstruct.rb +11 -5
  114. data/lib/ramaze/helper.rb +1 -1
  115. data/lib/ramaze/helper/aspect.rb +1 -1
  116. data/lib/ramaze/helper/auth.rb +2 -2
  117. data/lib/ramaze/helper/cache.rb +1 -1
  118. data/lib/ramaze/helper/cgi.rb +1 -1
  119. data/lib/ramaze/helper/file.rb +1 -1
  120. data/lib/ramaze/helper/flash.rb +1 -1
  121. data/lib/ramaze/helper/formatting.rb +1 -1
  122. data/lib/ramaze/helper/identity.rb +1 -1
  123. data/lib/ramaze/helper/inform.rb +1 -1
  124. data/lib/ramaze/helper/link.rb +4 -4
  125. data/lib/ramaze/helper/markaby.rb +1 -1
  126. data/lib/ramaze/helper/nitroform.rb +1 -1
  127. data/lib/ramaze/helper/pager.rb +2 -1
  128. data/lib/ramaze/helper/partial.rb +1 -1
  129. data/lib/ramaze/helper/redirect.rb +6 -1
  130. data/lib/ramaze/helper/sequel.rb +54 -0
  131. data/lib/ramaze/helper/stack.rb +1 -1
  132. data/lib/ramaze/inform.rb +1 -1
  133. data/lib/ramaze/inform/analogger.rb +1 -1
  134. data/lib/ramaze/inform/growl.rb +1 -1
  135. data/lib/ramaze/inform/hub.rb +1 -1
  136. data/lib/ramaze/inform/informer.rb +1 -1
  137. data/lib/ramaze/inform/informing.rb +2 -2
  138. data/lib/ramaze/inform/knotify.rb +1 -1
  139. data/lib/ramaze/inform/syslog.rb +1 -1
  140. data/lib/ramaze/inform/xosd.rb +1 -1
  141. data/lib/ramaze/snippets.rb +1 -1
  142. data/lib/ramaze/snippets/array/put_within.rb +1 -1
  143. data/lib/ramaze/snippets/blankslate.rb +7 -0
  144. data/lib/ramaze/snippets/dictionary.rb +6 -1
  145. data/lib/ramaze/snippets/divide.rb +1 -1
  146. data/lib/ramaze/snippets/kernel/__dir__.rb +1 -1
  147. data/lib/ramaze/snippets/kernel/acquire.rb +39 -0
  148. data/lib/ramaze/snippets/kernel/aquire.rb +1 -34
  149. data/lib/ramaze/snippets/kernel/constant.rb +1 -1
  150. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +1 -1
  151. data/lib/ramaze/snippets/numeric/filesize_format.rb +1 -1
  152. data/lib/ramaze/snippets/object/traits.rb +1 -1
  153. data/lib/ramaze/snippets/ordered_set.rb +12 -7
  154. data/lib/ramaze/snippets/ramaze/caller_info.rb +1 -1
  155. data/lib/ramaze/snippets/ramaze/caller_lines.rb +1 -1
  156. data/lib/ramaze/snippets/string/camel_case.rb +1 -1
  157. data/lib/ramaze/snippets/string/color.rb +2 -4
  158. data/lib/ramaze/snippets/string/each.rb +1 -1
  159. data/lib/ramaze/snippets/string/ord.rb +15 -0
  160. data/lib/ramaze/snippets/string/snake_case.rb +1 -1
  161. data/lib/ramaze/snippets/struct/fill.rb +4 -2
  162. data/lib/ramaze/snippets/struct/values_at.rb +2 -2
  163. data/lib/ramaze/snippets/symbol/to_proc.rb +15 -8
  164. data/lib/ramaze/snippets/thread/into.rb +1 -1
  165. data/lib/ramaze/sourcereload.rb +4 -3
  166. data/lib/ramaze/spec/helper.rb +85 -32
  167. data/lib/ramaze/spec/helper/bacon.rb +7 -0
  168. data/lib/ramaze/spec/helper/browser.rb +1 -2
  169. data/lib/ramaze/spec/helper/mock_http.rb +1 -1
  170. data/lib/ramaze/spec/helper/pretty_output.rb +70 -0
  171. data/lib/ramaze/spec/helper/requester.rb +1 -1
  172. data/lib/ramaze/spec/helper/simple_http.rb +5 -4
  173. data/lib/ramaze/spec/helper/snippets.rb +6 -0
  174. data/lib/ramaze/store/default.rb +1 -1
  175. data/lib/ramaze/template.rb +1 -1
  176. data/lib/ramaze/template/amrita2.rb +6 -5
  177. data/lib/ramaze/template/erubis.rb +1 -1
  178. data/lib/ramaze/template/ezamar.rb +1 -1
  179. data/lib/ramaze/template/ezamar/element.rb +1 -1
  180. data/lib/ramaze/template/ezamar/engine.rb +1 -1
  181. data/lib/ramaze/template/ezamar/morpher.rb +1 -1
  182. data/lib/ramaze/template/ezamar/render_partial.rb +1 -1
  183. data/lib/ramaze/template/haml.rb +1 -1
  184. data/lib/ramaze/template/liquid.rb +1 -1
  185. data/lib/ramaze/template/markaby.rb +1 -1
  186. data/lib/ramaze/template/nagoro.rb +4 -6
  187. data/lib/ramaze/template/none.rb +1 -1
  188. data/lib/ramaze/template/remarkably.rb +1 -1
  189. data/lib/ramaze/template/sass.rb +1 -1
  190. data/lib/ramaze/tool.rb +1 -1
  191. data/lib/ramaze/tool/create.rb +7 -1
  192. data/lib/ramaze/tool/localize.rb +7 -14
  193. data/lib/ramaze/tool/mime.rb +1 -1
  194. data/lib/ramaze/tool/record.rb +1 -1
  195. data/lib/ramaze/trinity.rb +1 -1
  196. data/lib/ramaze/trinity/request.rb +4 -2
  197. data/lib/ramaze/trinity/response.rb +1 -1
  198. data/lib/ramaze/trinity/session.rb +7 -1
  199. data/lib/ramaze/version.rb +3 -3
  200. data/lib/vendor/bacon.rb +317 -0
  201. data/rake_tasks/conf.rake +1 -1
  202. data/rake_tasks/maintenance.rake +7 -5
  203. data/rake_tasks/spec.rake +54 -40
  204. data/spec/contrib/auto_params.rb +21 -4
  205. data/spec/contrib/route.rb +31 -4
  206. data/spec/contrib/sequel/fill.rb +3 -4
  207. data/spec/examples/caching.rb +5 -2
  208. data/spec/examples/css.rb +5 -2
  209. data/spec/examples/element.rb +5 -4
  210. data/spec/examples/hello.rb +1 -0
  211. data/spec/examples/linking.rb +18 -0
  212. data/spec/examples/simple.rb +13 -18
  213. data/spec/examples/templates/template_amrita2.rb +3 -2
  214. data/spec/examples/templates/template_erubis.rb +3 -2
  215. data/spec/examples/templates/template_ezamar.rb +2 -1
  216. data/spec/examples/templates/template_haml.rb +3 -2
  217. data/spec/examples/templates/template_liquid.rb +3 -2
  218. data/spec/examples/templates/template_markaby.rb +3 -2
  219. data/spec/examples/templates/template_remarkably.rb +3 -2
  220. data/spec/ramaze/action/basics.rb +4 -4
  221. data/spec/ramaze/action/cache.rb +11 -13
  222. data/spec/ramaze/action/layout.rb +47 -3
  223. data/spec/ramaze/action/render.rb +3 -3
  224. data/spec/ramaze/action/template/instancevars/layout.xhtml +1 -0
  225. data/spec/ramaze/adapter.rb +7 -7
  226. data/spec/ramaze/adapter/mongrel.rb +1 -1
  227. data/spec/ramaze/adapter/record.rb +7 -7
  228. data/spec/ramaze/adapter/webrick.rb +1 -1
  229. data/spec/ramaze/cache.rb +6 -8
  230. data/spec/ramaze/controller.rb +77 -65
  231. data/spec/ramaze/controller/resolve.rb +2 -1
  232. data/spec/ramaze/controller/template_resolving.rb +3 -4
  233. data/spec/ramaze/dispatcher.rb +3 -4
  234. data/spec/ramaze/dispatcher/directory.rb +35 -35
  235. data/spec/ramaze/dispatcher/file.rb +8 -5
  236. data/spec/ramaze/element.rb +4 -4
  237. data/spec/ramaze/error.rb +13 -11
  238. data/spec/ramaze/gestalt.rb +1 -1
  239. data/spec/ramaze/helper/aspect.rb +2 -1
  240. data/spec/ramaze/helper/auth.rb +4 -2
  241. data/spec/ramaze/helper/cache.rb +10 -9
  242. data/spec/ramaze/helper/cgi.rb +2 -2
  243. data/spec/ramaze/helper/file.rb +1 -0
  244. data/spec/ramaze/helper/flash.rb +5 -4
  245. data/spec/ramaze/helper/formatting.rb +1 -1
  246. data/spec/ramaze/helper/link.rb +3 -3
  247. data/spec/ramaze/helper/pager.rb +44 -80
  248. data/spec/ramaze/helper/partial.rb +2 -3
  249. data/spec/ramaze/helper/redirect.rb +10 -1
  250. data/spec/ramaze/helper/stack.rb +4 -3
  251. data/spec/ramaze/helper/template/loop.xhtml +2 -1
  252. data/spec/ramaze/inform/informer.rb +2 -2
  253. data/spec/ramaze/inform/syslog.rb +1 -1
  254. data/spec/ramaze/localize.rb +26 -26
  255. data/spec/ramaze/morpher.rb +6 -7
  256. data/spec/ramaze/params.rb +7 -8
  257. data/spec/ramaze/request.rb +27 -6
  258. data/spec/ramaze/request/mongrel.rb +1 -1
  259. data/spec/ramaze/request/thin.rb +9 -0
  260. data/spec/ramaze/session.rb +2 -1
  261. data/spec/ramaze/store/default.rb +14 -17
  262. data/spec/ramaze/template.rb +5 -7
  263. data/spec/ramaze/template/amrita2.rb +4 -1
  264. data/spec/ramaze/template/erubis.rb +2 -1
  265. data/spec/ramaze/template/ezamar.rb +2 -3
  266. data/spec/ramaze/template/ezamar/other__index.xhtml +1 -0
  267. data/spec/ramaze/template/haml.rb +2 -1
  268. data/spec/ramaze/template/liquid.rb +4 -2
  269. data/spec/ramaze/template/markaby.rb +4 -2
  270. data/spec/ramaze/template/nagoro.rb +3 -4
  271. data/spec/ramaze/template/remarkably.rb +4 -2
  272. data/spec/ramaze/template/sass.rb +3 -2
  273. data/spec/ramaze/template/xslt.rb +4 -7
  274. data/spec/ramaze/trinity/request.rb +4 -3
  275. data/spec/ramaze/trinity/session.rb +6 -4
  276. data/spec/snippets/array/put_within.rb +3 -2
  277. data/spec/snippets/divide.rb +1 -4
  278. data/spec/snippets/kernel/__dir__.rb +1 -1
  279. data/spec/snippets/kernel/acquire.rb +71 -0
  280. data/spec/snippets/kernel/constant.rb +4 -8
  281. data/spec/snippets/numeric/filesize_format.rb +1 -1
  282. data/spec/snippets/ordered_set.rb +9 -2
  283. data/spec/snippets/ramaze/caller_info.rb +3 -3
  284. data/spec/snippets/ramaze/caller_lines.rb +3 -3
  285. data/spec/snippets/string/camel_case.rb +1 -1
  286. data/spec/snippets/string/color.rb +2 -2
  287. data/spec/snippets/string/snake_case.rb +5 -1
  288. data/spec/snippets/string/unindent.rb +1 -1
  289. data/spec/snippets/struct/fill.rb +14 -15
  290. data/spec/snippets/struct/values_at.rb +15 -10
  291. data/spec/snippets/symbol/to_proc.rb +13 -0
  292. data/spec/snippets/thread/into.rb +3 -4
  293. metadata +458 -386
  294. data/doc/README.html +0 -729
  295. data/doc/changes.txt +0 -5044
  296. data/doc/changes.xml +0 -5046
  297. data/lib/proto/public/error.zmr +0 -61
  298. data/lib/proto/src/element/page.rb +0 -17
  299. data/lib/proto/src/model.rb +0 -6
  300. data/lib/proto/template/index.xhtml +0 -15
  301. data/lib/ramaze/spec/helper/layout.rb +0 -58
  302. data/lib/ramaze/spec/helper/minimal.rb +0 -23
  303. data/lib/ramaze/spec/helper/wrap.rb +0 -198
  304. data/spec/snippets/kernel/aquire.rb +0 -71
@@ -25,6 +25,7 @@ begin
25
25
 
26
26
  def get_args
27
27
  arg_node = deep_array_node(:args)
28
+ return nil unless arg_node
28
29
  args = arg_node.arg_nodes
29
30
  default_node = arg_node.deep_array_node(:block)
30
31
  return args unless default_node
@@ -0,0 +1,23 @@
1
+ require __DIR__/:facebook/:facebook
2
+
3
+ module Ramaze
4
+ module FacebookHelper
5
+ def self.included(klass)
6
+ klass.send(:helper, :aspect, :inform)
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
@@ -0,0 +1,168 @@
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
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
+ ret = ret.first if ret.is_a? Array and ret.size == 1 and ret.first.is_a? Hash
75
+ raise Facebook::Error, ret['error_msg'] if ret.is_a? Hash and ret['error_code']
76
+
77
+ ret
78
+ ensure
79
+ unless @keepalive
80
+ @server.close
81
+ @server = nil
82
+ end
83
+ end
84
+
85
+ def valid?
86
+ return false unless private_methods.include? 'request' and not request['fb_sig'].empty?
87
+ request['facebook.valid?'] ||= \
88
+ request['fb_sig'] == Digest::MD5.hexdigest(request.params.map{|k,v| "#{$1}=#{v}" if k =~ /^fb_sig_(.+)$/ }.compact.sort.join+SECRET)
89
+ end
90
+
91
+ def [] key
92
+ params[key]
93
+ end
94
+
95
+ def redirect url
96
+ url[0,0] = URL unless url =~ /^http/
97
+ if private_methods.include? 'response'
98
+ response.build "<fb:redirect url='#{url}'/>"
99
+ throw :respond
100
+ else
101
+ "<fb:redirect url='#{url}'/>"
102
+ end
103
+ end
104
+
105
+ def addurl goto = '/'
106
+ "http://apps.facebook.com/add.php?api_key=#{KEY}&next=#{CGI.escape '?next='+goto}"
107
+ end
108
+
109
+ def params
110
+ return {} unless valid?
111
+ request['facebook'] ||= \
112
+ request.params.inject({}) { |h,(k,v)|
113
+ next h unless k =~ /^fb_sig_(.+)$/
114
+ k = $1.to_sym
115
+
116
+ case k.to_s
117
+ when 'friends'
118
+ h[k] = v.split(',').map{|e|e.to_i}
119
+ when /time$/
120
+ h[k] = Time.at(v.to_f)
121
+ when 'expires'
122
+ v = v.to_i
123
+ h[k] = v>0 ? Time.at(v) : v
124
+ when 'user'
125
+ h[k] = v.to_i
126
+ when /^(position_|in_|is_|added)/
127
+ h[k] = v=='1'
128
+ else
129
+ h[k] = v
130
+ end
131
+ h
132
+ }
133
+ end
134
+
135
+ private
136
+
137
+ def connect
138
+ @socket.close if @socket
139
+ TCPSocket.new('api.facebook.com', 80)
140
+ end
141
+
142
+ def post data
143
+ @server ||= connect
144
+
145
+ @server.puts "POST /restserver.php HTTP/1.1\r\n"
146
+ @server.puts "Host: api.facebook.com\r\n"
147
+ @server.puts "Connection: keep-alive\r\n" if @keepalive
148
+ @server.puts "Content-Type: application/x-www-form-urlencoded\r\n"
149
+ @server.puts "Content-Length: #{data.length}\r\n"
150
+ @server.puts "\r\n#{data}\r\n"
151
+ @server.puts "\r\n\r\n"
152
+
153
+ buf = ''
154
+ while @server.gets
155
+ if $_ == "\r\n"
156
+ @server.gets
157
+ if $_.strip! == '0'
158
+ @server.gets
159
+ break
160
+ end
161
+ buf << @server.read($_.to_i(16))
162
+ end
163
+ end
164
+
165
+ buf
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,111 @@
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
+ class Ramaze::Tool::Gettext < Ramaze::Tool::Localize
26
+
27
+ # Enable Localization
28
+ trait :enable => true
29
+
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'
33
+
34
+ # languages supported
35
+ trait :languages => %w[ en ]
36
+
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
40
+
41
+ # The pattern that is substituted with the translation of the current locale.
42
+ trait :regex => /\[\[(.*?)\]\]/
43
+
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'}
47
+
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
52
+
53
+
54
+ # Load given locales from disk and save it into the dictionary.
55
+
56
+ def self.load(*locales)
57
+ Ramaze::Inform.debug "loading locales: #{locales.inspect}"
58
+
59
+ dict = trait[:dictionary] || {}
60
+
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] = {}
67
+ end
68
+ end
69
+
70
+ trait[:dictionary] = dict
71
+ end
72
+
73
+ # Reloads given locales from the disk to refresh the dictionary.
74
+
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!
81
+ end
82
+ end
83
+ end
84
+
85
+ # Stores given locales from the dictionary to disk.
86
+
87
+ def self.store(*locales)
88
+ keys = []
89
+ dictionary.each do |locale, dict|
90
+ keys.concat dict.keys
91
+ end
92
+
93
+ data = ::GetText::RGetText.generate(keys.compact.uniq.sort.map {|x| [x] })
94
+ file = (trait[:file] % trait[:default_language]) + '.pot'
95
+ File.open(file, File::CREAT|File::TRUNC|File::WRONLY) do |fd|
96
+ fd.write data
97
+ end
98
+ rescue Errno::ENOENT => e
99
+ Ramaze::Inform.error e
100
+ end
101
+
102
+ end
103
+
104
+ class Ramaze::Contrib::Gettext
105
+
106
+ # Called by Ramaze::Contrib.load, adds Gettext to Action::Filter
107
+
108
+ def self.startup
109
+ Ramaze::Dispatcher::Action::FILTER << Ramaze::Tool::Gettext
110
+ end
111
+ end
@@ -0,0 +1,155 @@
1
+ =begin
2
+ mo.rb - A simple class for operating GNU MO file.
3
+
4
+ Copyright (C) 2003-2006 Masao Mutoh
5
+ Copyright (C) 2002 Masahiro Sakai, Masao Mutoh
6
+ Copyright (C) 2001 Masahiro Sakai
7
+
8
+ Masahiro Sakai <s01397ms@sfc.keio.ac.jp>
9
+ Masao Mutoh <mutoh@highway.ne.jp>
10
+
11
+ You can redistribute this file and/or modify it under the same term
12
+ of Ruby. License of Ruby is included with Ruby distribution in
13
+ the file "README".
14
+
15
+ $Id: mo.rb,v 1.7 2006/06/11 15:36:20 mutoh Exp $
16
+ =end
17
+
18
+ require 'iconv'
19
+
20
+ class MOFile < Hash
21
+ class InvalidFormat < RuntimeError; end;
22
+
23
+ attr_reader :filename
24
+
25
+ Header = Struct.new(:magic,
26
+ :revision,
27
+ :nstrings,
28
+ :orig_table_offset,
29
+ :translated_table_offset,
30
+ :hash_table_size,
31
+ :hash_table_offset)
32
+
33
+ MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde"
34
+ MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95"
35
+
36
+ def self.open(arg = nil, output_charset = nil)
37
+ result = self.new(output_charset)
38
+ result.load(arg)
39
+ end
40
+
41
+ def initialize(output_charset = nil)
42
+ @filename = nil
43
+ @last_modified = nil
44
+ @little_endian = true
45
+ @output_charset = output_charset
46
+ super
47
+ end
48
+
49
+ def update!
50
+ if FileTest.exist?(@filename)
51
+ st = File.stat(@filename)
52
+ load(@filename) unless (@last_modified == [st.ctime, st.mtime])
53
+ else
54
+ puts "#{@filename} was lost." if $DEBUG
55
+ clear
56
+ end
57
+ self
58
+ end
59
+
60
+ def load(arg)
61
+ case arg
62
+ when String
63
+ begin
64
+ st = File.stat(arg)
65
+ @last_modified = [st.ctime, st.mtime]
66
+ rescue Exception
67
+ end
68
+ load_from_file(arg)
69
+ when IO
70
+ load_from_stream(arg)
71
+ end
72
+ @filename = arg
73
+ self
74
+ end
75
+
76
+ def load_from_stream(io)
77
+ magic = io.read(4)
78
+ case magic
79
+ when MAGIC_BIG_ENDIAN
80
+ @little_endian = false
81
+ when MAGIC_LITTLE_ENDIAN
82
+ @little_endian = true
83
+ else
84
+ raise InvalidFormat.new("Unknown signature %s" % magic.dump)
85
+ end
86
+
87
+ header = Header.new(magic, *(io.read(4 * 6).unpack(@little_endian ? 'V6' : 'N6')))
88
+ raise InvalidFormat.new(sprintf("file format revision %d isn't supported", header.revision)) if header.revision > 0
89
+
90
+ io.pos = header.orig_table_offset
91
+ orig_table_data = io.read((4 * 2) * header.nstrings).unpack(@little_endian ? 'V*' : 'N*')
92
+
93
+ io.pos = header.translated_table_offset
94
+ trans_table_data = io.read((4 * 2) * header.nstrings).unpack(@little_endian ? 'V*' : 'N*')
95
+
96
+ original_strings = Array.new(header.nstrings)
97
+ for i in 0...header.nstrings
98
+ io.pos = orig_table_data[i * 2 + 1]
99
+ original_strings[i] = io.read(orig_table_data[i * 2 + 0])
100
+ end
101
+
102
+ clear
103
+ for i in 0...header.nstrings
104
+ io.pos = trans_table_data[i * 2 + 1]
105
+ str = io.read(trans_table_data[i * 2 + 0])
106
+
107
+ if original_strings[i] == ""
108
+ if str
109
+ @charset = nil
110
+ @nplurals = nil
111
+ @plural = nil
112
+ str.each_line{|line|
113
+ if /^Content-Type:/i =~ line and /charset=((?:\w|-)+)/i =~ line
114
+ @charset = $1
115
+ elsif /^Plural-Forms:\s*nplurals\s*\=\s*(\d*);\s*plural\s*\=\s*([^;]*)\n?/ =~ line
116
+ @nplurals = $1
117
+ @plural = $2
118
+ end
119
+ break if @charset and @nplurals
120
+ }
121
+ @nplurals = "1" unless @nplurals
122
+ @plural = "0" unless @plural
123
+ end
124
+ else
125
+ if @output_charset
126
+ begin
127
+ str = Iconv.iconv(@output_charset, @charset, str).join if @charset
128
+ rescue Iconv::Failure
129
+ if $DEBUG
130
+ $stderr.print "@charset = ", @charset, "\n"
131
+ $stderr.print "@output_charset = ", @output_charset, "\n"
132
+ $stderr.print "msgid = ", original_strings[i], "\n"
133
+ $stderr.print "msgstr = ", str, "\n"
134
+ end
135
+ end
136
+ end
137
+ end
138
+ self[original_strings[i]] = str
139
+ end
140
+ self
141
+ end
142
+
143
+ def load_from_file(filename)
144
+ @filename = filename
145
+ File.open(filename, 'rb'){|f| load_from_stream(f)}
146
+ end
147
+
148
+ def set_comment(msgid_or_sym, comment)
149
+ #Do nothing
150
+ end
151
+
152
+
153
+ attr_accessor :little_endian, :path, :last_modified
154
+ attr_reader :charset, :nplurals, :plural
155
+ end