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,43 +1,44 @@
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 support simple routing using string, regex and lambda based routers.
5
- # Route are stored in a dictionary, which supports hash-like access but
6
- # preserves order, so routes are evaluated in the order they are added.
7
- #
8
- # String routers are the simplest way to route in Ramaze. One path is
9
- # translated into another:
10
- #
11
- # Ramaze::Route[ '/foo' ] = '/bar'
12
- # '/foo' => '/bar'
13
- #
14
- # Regex routers allow matching against paths using regex. Matches within
15
- # your regex using () are substituted in the new path using printf-like
16
- # syntax.
17
- #
18
- # Ramaze::Route[ %r!^/(\d+)\.te?xt$! ] = "/text/%d"
19
- # '/123.txt' => '/text/123'
20
- # '/789.text' => '/text/789'
21
- #
22
- # For more complex routing, lambda routers can be used. Lambda routers are
23
- # passed in the current path and request object, and must return either a new
24
- # path string, or nil.
25
- #
26
- # Ramaze::Route[ 'name of route' ] = lambda{ |path, request|
27
- # '/bar' if path == '/foo' and request[:bar] == '1'
28
- # }
29
- # '/foo' => '/foo'
30
- # '/foo?bar=1' => '/bar'
31
- #
32
- # Lambda routers can also use this alternative syntax:
33
- #
34
- # Ramaze::Route('name of route') do |path, request|
35
- # '/bar' if path == '/foo' and request[:bar] == '1'
36
- # end
37
-
38
4
  module Ramaze
5
+
6
+ # Ramaze support simple routing using string, regex and lambda based routers.
7
+ # Route are stored in a dictionary, which supports hash-like access but
8
+ # preserves order, so routes are evaluated in the order they are added.
9
+ #
10
+ # String routers are the simplest way to route in Ramaze. One path is
11
+ # translated into another:
12
+ #
13
+ # Ramaze::Route[ '/foo' ] = '/bar'
14
+ # '/foo' => '/bar'
15
+ #
16
+ # Regex routers allow matching against paths using regex. Matches within
17
+ # your regex using () are substituted in the new path using printf-like
18
+ # syntax.
19
+ #
20
+ # Ramaze::Route[ %r!^/(\d+)\.te?xt$! ] = "/text/%d"
21
+ # '/123.txt' => '/text/123'
22
+ # '/789.text' => '/text/789'
23
+ #
24
+ # For more complex routing, lambda routers can be used. Lambda routers are
25
+ # passed in the current path and request object, and must return either a new
26
+ # path string, or nil.
27
+ #
28
+ # Ramaze::Route[ 'name of route' ] = lambda{ |path, request|
29
+ # '/bar' if path == '/foo' and request[:bar] == '1'
30
+ # }
31
+ # '/foo' => '/foo'
32
+ # '/foo?bar=1' => '/bar'
33
+ #
34
+ # Lambda routers can also use this alternative syntax:
35
+ #
36
+ # Ramaze::Route('name of route') do |path, request|
37
+ # '/bar' if path == '/foo' and request[:bar] == '1'
38
+ # end
39
+
39
40
  class Route
40
- trait :routes => Dictionary.new
41
+ trait[:routes] ||= Dictionary.new
41
42
 
42
43
  class << self
43
44
  def [](key)
@@ -47,10 +48,37 @@ module Ramaze
47
48
  def []=(key, value)
48
49
  trait[:routes][key] = value
49
50
  end
51
+
52
+ def clear
53
+ trait[:routes].clear
54
+ end
55
+
56
+ def resolve(path)
57
+ trait[:routes].each do |key, val|
58
+ if key.is_a?(Regexp)
59
+ if md = path.match(key)
60
+ return val % md.to_a[1..-1]
61
+ end
62
+
63
+ elsif val.respond_to?(:call)
64
+ if new_path = val.call(path, Request.current)
65
+ return new_path
66
+ end
67
+
68
+ elsif val.is_a?(String)
69
+ return val if path == key
70
+
71
+ else
72
+ Log.error "Invalid route #{key} => #{val}"
73
+ end
74
+ end
75
+
76
+ nil
77
+ end
50
78
  end
51
79
  end
52
80
 
53
81
  def self.Route(name, &block)
54
82
  Route[name] = block
55
83
  end
56
- end
84
+ end
@@ -2,6 +2,11 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  class Array
5
+
6
+ # a = [1, 2, 3]
7
+ # a.put_within(4, :after => 2, :before => 3)
8
+ # a # => [1, 2, 4, 3]
9
+
5
10
  def put_within(object, constrain)
6
11
  pre, post = constrain.values_at(:after, :before)
7
12
 
@@ -12,11 +17,19 @@ class Array
12
17
  put_after(pre, object)
13
18
  end
14
19
 
20
+ # a = [1, 2, 3]
21
+ # a.put_after(2, 4)
22
+ # a # => [1, 2, 4, 3]
23
+
15
24
  def put_after(element, object)
16
25
  raise ArgumentError, "The given element doesn't exist" unless include?(element)
17
26
  self[index(element) + 1, 0] = object
18
27
  end
19
28
 
29
+ # a = [1, 2, 3]
30
+ # a.put_before(2, 4)
31
+ # a # => [1, 4, 2, 3]
32
+
20
33
  def put_before(element, object)
21
34
  raise ArgumentError, "The given element doesn't exist" unless include?(element)
22
35
  self[rindex(element), 0] = object
@@ -0,0 +1,13 @@
1
+ class Binding
2
+
3
+ # returns a hash of localvar/localvar-values from binding, useful for
4
+ # template engines that do not accept bindings and force passing locals via
5
+ # hash
6
+ # usage: x = 42; p binding.locals #=> {'x'=> 42}
7
+ def locals
8
+ eval '
9
+ local_variables.inject({}){|h,v| h.update v => eval(v)}
10
+ ', self
11
+ end
12
+
13
+ end
@@ -4,15 +4,17 @@
4
4
  # Extensions for Kernel
5
5
 
6
6
  module Kernel
7
- # This is similar to +__FILE__+ and +__LINE__+, and returns a String
8
- # representing the directory of the current file is.
9
- # Unlike +__FILE__+ the path returned is absolute.
10
- #
11
- # This method is convenience for the
12
- # File.expand_path(File.dirname(__FILE__))
13
- # idiom.
14
- #
15
7
  unless defined?__DIR__
8
+
9
+ # This is similar to +__FILE__+ and +__LINE__+, and returns a String
10
+ # representing the directory of the current file is.
11
+ # Unlike +__FILE__+ the path returned is absolute.
12
+ #
13
+ # This method is convenience for the
14
+ # File.expand_path(File.dirname(__FILE__))
15
+ # idiom.
16
+ #
17
+
16
18
  def __DIR__()
17
19
  filename = caller[0][/(.*?):/, 1]
18
20
  File.expand_path(File.dirname(filename))
@@ -1 +1 @@
1
- require File.join(File.dirname(__FILE__), 'acquire')
1
+ require(File.join(File.dirname(__FILE__), 'acquire'))
@@ -17,7 +17,7 @@ module Kernel
17
17
  # require 'test/unit'
18
18
  # Test.constant("Unit::Assertions") # -> Test::Unit::Assertions
19
19
  # Test.constant("::Test::Unit") # -> Test::Unit
20
- #
20
+
21
21
  def constant(const)
22
22
  const = const.to_s.dup
23
23
  base = const.sub!(/^::/, '') ? Object : ( self.kind_of?(Module) ? self : self.class )
@@ -0,0 +1,6 @@
1
+ class Object
2
+ def pretty s = ''
3
+ PP.pp(self, s)
4
+ s
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ class Object
2
+
3
+ # returns a new clean binding for this object
4
+ # usage: eval 'self', object.scope #=> returns object
5
+ #
6
+
7
+ def scope
8
+ lambda{}
9
+ end
10
+
11
+ end
@@ -0,0 +1,5 @@
1
+ require(File.join(File.dirname(__FILE__), '../ramaze/thread_accessor'))
2
+
3
+ class Object
4
+ include Ramaze::ThreadAccessor
5
+ end
@@ -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
- require File.join(File.dirname(__FILE__), 'blankslate')
4
+ require(File.join(File.dirname(__FILE__), 'blankslate'))
5
5
 
6
6
  class OrderedSet < BlankSlate
7
7
  def initialize(*args)
@@ -0,0 +1,11 @@
1
+ class Proc
2
+
3
+ # returns a hash of localvar/localvar-values from proc, useful for template
4
+ # engines that do not accept bindings/proc and force passing locals via
5
+ # hash
6
+ # usage: x = 42; p Proc.new.locals #=> {'x'=> 42}
7
+ def locals
8
+ instance_eval('binding').locals
9
+ end
10
+
11
+ end
@@ -0,0 +1,44 @@
1
+ module Ramaze
2
+ module ThreadAccessor
3
+ def ThreadAccessor.each(*names)
4
+ names.each do |name|
5
+ if name.respond_to?(:to_hash)
6
+ name.to_hash.each do |key, meth|
7
+ key, meth = key.to_sym, meth.to_sym
8
+ yield key, meth
9
+ end
10
+ else
11
+ key = meth = name.to_sym
12
+ yield key, meth
13
+ end
14
+ end
15
+ end
16
+
17
+ def thread_accessor(*names, &initializer)
18
+ thread_writer(*names)
19
+ thread_reader(*names, &initializer)
20
+ end
21
+
22
+ def thread_writer(*names)
23
+ ThreadAccessor.each(*names) do |key, meth|
24
+ define_method("#{meth}="){|obj| Thread.current[key] = obj }
25
+ end
26
+ end
27
+
28
+ def thread_reader(*names, &initializer)
29
+ ThreadAccessor.each(*names) do |key, meth|
30
+ if initializer
31
+ define_method(meth) do
32
+ unless Thread.current.key?(key)
33
+ Thread.current[key] = instance_eval(&initializer)
34
+ else
35
+ Thread.current[key]
36
+ end
37
+ end
38
+ else
39
+ define_method(meth){ Thread.current[key] }
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ require 'cgi'
2
+ require 'uri'
3
+
4
+ class String
5
+
6
+ # String#escape is an extensible escaping mechanism for string. currently
7
+ # it suports
8
+ # '<div>foo bar</div>'.esc(:html)
9
+ # 'foo bar'.esc(:uri)
10
+ # 'foo bar'.esc(:cgi)
11
+ # "foo 'bar'".esc(:sql)
12
+
13
+ def escape which = :html
14
+ case which
15
+ when :html
16
+ ::CGI.escapeHTML(self)
17
+ when :cgi
18
+ ::CGI.escape(self)
19
+ when :uri
20
+ ::URI.escape(self)
21
+ when :sql # TODO - leverage DBI or something
22
+ gsub(%r/'/, "''")
23
+ else
24
+ raise ArgumentError, "do not know how to escape '#{ which }'"
25
+ end
26
+ end
27
+
28
+ alias_method 'esc', 'escape'
29
+ end
@@ -0,0 +1,7 @@
1
+ class String
2
+ unless method_defined?(:start_with?)
3
+ def start_with?(other)
4
+ self[0, other.size] == other
5
+ end
6
+ end
7
+ end
@@ -1,7 +1,12 @@
1
1
  class String
2
2
  def unindent
3
- space = self.split("\n")[1].to_s[/^(\s+)/, 1]
3
+ space = self.split("\n").find{|l| !l.strip.empty?}.to_s[/^(\s+)/, 1]
4
4
  strip.gsub(/^#{space}/, '')
5
5
  end
6
6
  alias ui unindent
7
+
8
+ def unindent!
9
+ self.replace unindent
10
+ end
11
+ alias ui! unindent!
7
12
  end
@@ -3,10 +3,6 @@
3
3
 
4
4
  # Extensions for Struct
5
5
 
6
- class Symbol
7
- undef_method :to_int if method_defined?(:to_int)
8
- end
9
-
10
6
  class Struct
11
7
 
12
8
  # Example:
@@ -18,7 +14,7 @@ class Struct
18
14
  # # => [15, 10]
19
15
 
20
16
  def values_at(*keys)
21
- if keys.all?{|key| key.respond_to?(:to_int) }
17
+ if keys.all?{|key| key.respond_to?(:to_int) and not key.is_a?(Symbol) }
22
18
  keys.map{|key| values[key.to_int] }
23
19
  else
24
20
  keys.map{|k| self[k] }
@@ -1,8 +1,6 @@
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 'set'
5
-
6
4
  module Ramaze
7
5
 
8
6
  # SourceReload provides a way to reload changed files automatically during
@@ -27,7 +25,7 @@ module Ramaze
27
25
  # start reloader-thread and assign it to this instance.
28
26
 
29
27
  def start
30
- Inform.dev("initialize automatic source reload every #{interval} seconds")
28
+ Log.dev("initialize automatic source reload every #{interval} seconds")
31
29
  @thread = reloader
32
30
  end
33
31
 
@@ -60,7 +58,7 @@ module Ramaze
60
58
  # Usage example:
61
59
  #
62
60
  # trap :HUP do
63
- # Ramaze::Inform.info "reloading source"
61
+ # Ramaze::Log.info "reloading source"
64
62
  # Thread.main[:sourcereload].reload
65
63
  # end
66
64
  #
@@ -72,7 +70,7 @@ module Ramaze
72
70
 
73
71
  next if (@mtimes[file] ||= mtime) == mtime
74
72
 
75
- Inform.debug("reload #{file}")
73
+ Log.debug("reload #{file}")
76
74
  @mtimes[file] = mtime if safe_load(file)
77
75
  end
78
76
  SourceReloadHooks.after_reload
@@ -83,18 +81,22 @@ module Ramaze
83
81
 
84
82
  def all_reload_files
85
83
  files = Array[$0, *$LOADED_FEATURES]
86
- paths = Array['', './', *$LOAD_PATH]
84
+ paths = Array['./', *$LOAD_PATH]
87
85
 
88
86
  unless [@files, @paths] == [files, paths]
89
87
  @files, @paths = files.dup, paths.dup
90
88
 
91
- map = files.map do |file|
92
- paths.map{|pa|
93
- File.expand_path(File.join(pa.to_s, file.to_s))
94
- }.find{|po| File.exists?(po) }
95
- end
96
-
97
- @map = map.compact
89
+ @map = files.map{|file|
90
+ if Pathname.new(file).absolute?
91
+ file
92
+ else
93
+ path = paths.find{|pa|
94
+ ex = File.expand_path(pa/file)
95
+ File.exists?(ex)
96
+ }
97
+ File.expand_path(path/file) if path
98
+ end
99
+ }.compact
98
100
  end
99
101
 
100
102
  @map.grep(class_trait[:reload_glob])
@@ -161,7 +163,7 @@ module Ramaze
161
163
  # by default we output an error-message with the exception.
162
164
 
163
165
  def after_safe_load_failed(file, error)
164
- Inform.error(error)
166
+ Log.error(error)
165
167
  end
166
168
  end
167
169
  end