ramaze 2008.06 → 2008.11

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 (184) hide show
  1. data/README.markdown +6 -6
  2. data/Rakefile +33 -3
  3. data/bin/ramaze +18 -0
  4. data/doc/CHANGELOG +960 -0
  5. data/doc/LEGAL +5 -1
  6. data/doc/meta/announcement.txt +20 -36
  7. data/doc/tutorial/todolist.html +421 -313
  8. data/doc/tutorial/todolist.mkd +33 -16
  9. data/examples/app/blog/spec/blog.rb +3 -3
  10. data/examples/app/rapaste/controller/paste.rb +8 -1
  11. data/examples/app/rapaste/model/paste.rb +3 -0
  12. data/examples/app/rapaste/spec/rapaste.rb +3 -1
  13. data/examples/app/rapaste/start.rb +3 -2
  14. data/examples/app/sourceview/public/sourceview.js +2 -2
  15. data/examples/app/todolist/spec/todolist.rb +6 -6
  16. data/examples/app/todolist/template/index.xhtml +1 -1
  17. data/examples/app/whywiki/spec/whywiki.rb +2 -2
  18. data/examples/app/wikore/spec/wikore.rb +2 -2
  19. data/examples/app/wikore/src/model.rb +4 -3
  20. data/examples/app/wiktacular/spec/wiktacular.rb +7 -7
  21. data/examples/basic/simple.rb +2 -2
  22. data/examples/helpers/paginate.rb +71 -0
  23. data/examples/misc/simple_auth.rb +20 -8
  24. data/lib/proto/controller/init.rb +10 -0
  25. data/lib/proto/controller/main.rb +1 -3
  26. data/lib/proto/model/init.rb +4 -0
  27. data/lib/proto/public/dispatch.fcgi +1 -1
  28. data/lib/proto/spec/main.rb +2 -1
  29. data/lib/proto/start.rb +3 -3
  30. data/lib/proto/start.ru +1 -1
  31. data/lib/proto/view/error.xhtml +4 -4
  32. data/lib/ramaze.rb +8 -3
  33. data/lib/ramaze/action.rb +6 -6
  34. data/lib/ramaze/adapter.rb +1 -6
  35. data/lib/ramaze/adapter/base.rb +30 -27
  36. data/lib/ramaze/adapter/cgi.rb +1 -0
  37. data/lib/ramaze/cache.rb +1 -3
  38. data/lib/ramaze/cache/memcached.rb +3 -5
  39. data/lib/ramaze/contrib/auto_params.rb +2 -2
  40. data/lib/ramaze/contrib/auto_params/get_args.rb +2 -1
  41. data/lib/ramaze/contrib/gems.rb +17 -18
  42. data/lib/ramaze/contrib/gzip_filter.rb +22 -9
  43. data/lib/ramaze/contrib/maruku_uv.rb +59 -0
  44. data/lib/ramaze/contrib/profiling.rb +1 -1
  45. data/lib/ramaze/contrib/rest.rb +16 -13
  46. data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
  47. data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
  48. data/lib/ramaze/contrib/sequel/image.rb +198 -0
  49. data/lib/ramaze/contrib/sequel/relation.rb +82 -0
  50. data/lib/ramaze/controller.rb +33 -34
  51. data/lib/ramaze/controller/resolve.rb +29 -9
  52. data/lib/ramaze/current.rb +60 -20
  53. data/lib/ramaze/current/request.rb +8 -7
  54. data/lib/ramaze/current/response.rb +15 -3
  55. data/lib/ramaze/current/session/flash.rb +8 -0
  56. data/lib/ramaze/dispatcher.rb +17 -9
  57. data/lib/ramaze/dispatcher/action.rb +4 -5
  58. data/lib/ramaze/dispatcher/directory.rb +1 -1
  59. data/lib/ramaze/dispatcher/error.rb +4 -4
  60. data/lib/ramaze/dispatcher/file.rb +4 -4
  61. data/lib/ramaze/gestalt.rb +15 -20
  62. data/lib/ramaze/helper/cgi.rb +7 -15
  63. data/lib/ramaze/helper/formatting.rb +41 -1
  64. data/lib/ramaze/helper/httpdigest.rb +20 -7
  65. data/lib/ramaze/helper/link.rb +4 -6
  66. data/lib/ramaze/helper/paginate.rb +233 -0
  67. data/lib/ramaze/helper/redirect.rb +1 -1
  68. data/lib/ramaze/helper/rest.rb +1 -1
  69. data/lib/ramaze/helper/thread.rb +17 -0
  70. data/lib/ramaze/helper/ultraviolet.rb +44 -0
  71. data/lib/ramaze/helper/user.rb +4 -9
  72. data/lib/ramaze/log.rb +2 -2
  73. data/lib/ramaze/log/analogger.rb +21 -23
  74. data/lib/ramaze/log/growl.rb +21 -23
  75. data/lib/ramaze/log/hub.rb +1 -1
  76. data/lib/ramaze/log/informer.rb +97 -99
  77. data/lib/ramaze/log/knotify.rb +14 -16
  78. data/lib/ramaze/log/logger.rb +11 -13
  79. data/lib/ramaze/log/logging.rb +61 -63
  80. data/lib/ramaze/log/rotatinginformer.rb +168 -0
  81. data/lib/ramaze/log/syslog.rb +41 -31
  82. data/lib/ramaze/log/xosd.rb +70 -72
  83. data/lib/ramaze/option.rb +9 -6
  84. data/lib/ramaze/option/holder.rb +5 -27
  85. data/lib/ramaze/reloader.rb +186 -0
  86. data/lib/ramaze/setup.rb +1 -1
  87. data/lib/ramaze/snippets.rb +13 -0
  88. data/lib/ramaze/snippets/array/put_within.rb +31 -24
  89. data/lib/ramaze/snippets/binding/locals.rb +23 -11
  90. data/lib/ramaze/snippets/dictionary.rb +2 -2
  91. data/lib/ramaze/snippets/fiber.rb +63 -0
  92. data/lib/ramaze/snippets/kernel/constant.rb +36 -21
  93. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +12 -6
  94. data/lib/ramaze/snippets/numeric/filesize_format.rb +24 -17
  95. data/lib/ramaze/snippets/numeric/time.rb +63 -0
  96. data/lib/ramaze/snippets/object/__dir__.rb +29 -0
  97. data/lib/ramaze/snippets/object/acquire.rb +40 -0
  98. data/lib/ramaze/snippets/object/instance_variable_defined.rb +16 -5
  99. data/lib/ramaze/snippets/object/pretty.rb +14 -4
  100. data/lib/ramaze/snippets/object/scope.rb +14 -7
  101. data/lib/ramaze/snippets/ordered_set.rb +25 -14
  102. data/lib/ramaze/snippets/proc/locals.rb +17 -9
  103. data/lib/ramaze/snippets/ramaze/deprecated.rb +13 -0
  104. data/lib/ramaze/snippets/ramaze/fiber.rb +24 -0
  105. data/lib/ramaze/snippets/ramaze/state.rb +86 -0
  106. data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
  107. data/lib/ramaze/snippets/string/camel_case.rb +13 -8
  108. data/lib/ramaze/snippets/string/color.rb +24 -20
  109. data/lib/ramaze/snippets/string/each.rb +14 -3
  110. data/lib/ramaze/snippets/string/end_with.rb +20 -0
  111. data/lib/ramaze/snippets/string/esc.rb +26 -21
  112. data/lib/ramaze/snippets/string/ord.rb +12 -6
  113. data/lib/ramaze/snippets/string/snake_case.rb +13 -7
  114. data/lib/ramaze/snippets/string/start_with.rb +16 -5
  115. data/lib/ramaze/snippets/string/unindent.rb +23 -15
  116. data/lib/ramaze/snippets/thread/into.rb +3 -3
  117. data/lib/ramaze/spec/helper/bacon.rb +5 -5
  118. data/lib/ramaze/spec/helper/mock_http.rb +1 -1
  119. data/lib/ramaze/spec/helper/pretty_output.rb +2 -2
  120. data/lib/ramaze/spec/helper/snippets.rb +8 -0
  121. data/lib/ramaze/template.rb +4 -1
  122. data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
  123. data/lib/ramaze/template/maruku.rb +34 -0
  124. data/lib/ramaze/template/tagz.rb +2 -2
  125. data/lib/ramaze/template/xslt.rb +2 -2
  126. data/lib/ramaze/tool/create.rb +27 -53
  127. data/lib/ramaze/tool/localize.rb +8 -4
  128. data/lib/ramaze/tool/mime.rb +11 -1
  129. data/lib/ramaze/tool/project_creator.rb +110 -0
  130. data/lib/ramaze/trinity.rb +4 -1
  131. data/lib/ramaze/version.rb +1 -1
  132. data/lib/vendor/bacon.rb +323 -0
  133. data/rake_tasks/gem.rake +10 -1
  134. data/rake_tasks/maintenance.rake +40 -2
  135. data/rake_tasks/metric.rake +24 -0
  136. data/rake_tasks/release.rake +17 -4
  137. data/rake_tasks/spec.rake +1 -2
  138. data/ramaze.gemspec +549 -495
  139. data/spec/contrib/auto_params.rb +3 -3
  140. data/spec/contrib/profiling.rb +2 -2
  141. data/spec/examples/simple_auth.rb +2 -2
  142. data/spec/examples/templates/template_haml.rb +0 -2
  143. data/spec/ramaze/action/file_cache.rb +22 -0
  144. data/spec/ramaze/adapter.rb +2 -2
  145. data/spec/ramaze/controller/actionless_templates.rb +1 -1
  146. data/spec/ramaze/controller/subclass.rb +15 -0
  147. data/spec/ramaze/controller/template_resolving.rb +1 -1
  148. data/spec/ramaze/controller/view/bar.xhtml +1 -0
  149. data/spec/ramaze/controller/view/base/another.xhtml +1 -0
  150. data/spec/ramaze/current/session.rb +1 -1
  151. data/spec/ramaze/dispatcher/file.rb +2 -2
  152. data/spec/ramaze/helper/aspect.rb +26 -17
  153. data/spec/ramaze/helper/formatting.rb +13 -0
  154. data/spec/ramaze/log/informer.rb +10 -10
  155. data/spec/ramaze/log/syslog.rb +67 -4
  156. data/spec/ramaze/rewrite.rb +1 -1
  157. data/spec/ramaze/route.rb +1 -1
  158. data/spec/ramaze/struct.rb +47 -0
  159. data/spec/ramaze/template/markaby.rb +1 -1
  160. data/spec/ramaze/template/tagz.rb +1 -1
  161. data/spec/snippets/binding/locals.rb +9 -0
  162. data/spec/snippets/numeric/time.rb +12 -0
  163. data/spec/snippets/{kernel → object}/__dir__.rb +0 -0
  164. data/spec/snippets/{kernel → object}/acquire.rb +0 -0
  165. metadata +90 -81
  166. data/cache.yaml +0 -7
  167. data/examples/app/rammit/spec/rammit.rb +0 -31
  168. data/examples/app/rammit/src/controller/main.rb +0 -3
  169. data/examples/app/rammit/src/controller/page.rb +0 -16
  170. data/examples/app/rammit/src/model.rb +0 -33
  171. data/examples/app/rammit/start.rb +0 -8
  172. data/examples/app/rammit/template/index.xhtml +0 -14
  173. data/examples/app/rammit/template/page/view.xhtml +0 -4
  174. data/lib/ramaze/snippets/kernel/__dir__.rb +0 -23
  175. data/lib/ramaze/snippets/kernel/acquire.rb +0 -34
  176. data/lib/ramaze/snippets/object/thread_accessor.rb +0 -5
  177. data/lib/ramaze/snippets/ramaze/thread_accessor.rb +0 -58
  178. data/lib/ramaze/snippets/struct/fill.rb +0 -23
  179. data/lib/ramaze/snippets/struct/values_at.rb +0 -39
  180. data/lib/ramaze/snippets/symbol/to_proc.rb +0 -24
  181. data/lib/ramaze/sourcereload.rb +0 -176
  182. data/spec/snippets/struct/fill.rb +0 -26
  183. data/spec/snippets/struct/values_at.rb +0 -52
  184. data/spec/snippets/symbol/to_proc.rb +0 -13
@@ -0,0 +1,24 @@
1
+ module Ramaze
2
+ class Fiber < ::Fiber
3
+ # initialize isn't being called, so we have to hook into ::new
4
+ def self.new(*args)
5
+ instance = super
6
+ instance.state = {}
7
+ instance
8
+ end
9
+
10
+ attr_accessor :state
11
+
12
+ def [](key)
13
+ @state[key]
14
+ end
15
+
16
+ def []=(key, value)
17
+ @state[key] = value
18
+ end
19
+
20
+ def key?(key)
21
+ @state.key?(key)
22
+ end
23
+ end if defined?(::Fiber)
24
+ end
@@ -0,0 +1,86 @@
1
+ module Ramaze
2
+ class State
3
+ def initialize
4
+ @core = detect
5
+ end
6
+
7
+ def detect
8
+ require 'fiber'
9
+ @extract = :resume
10
+ Ramaze::Fiber
11
+ rescue LoadError
12
+ @extract = :value
13
+ ::Thread
14
+ end
15
+
16
+ def [](key)
17
+ @core.current[key]
18
+ end
19
+
20
+ def []=(key, value)
21
+ @core.current[key] = value
22
+ end
23
+
24
+ def key?(key)
25
+ @core.current.key?(key)
26
+ end
27
+
28
+ def wrap(&block)
29
+ @core.new(&block).send(@extract)
30
+ end
31
+ end
32
+
33
+ module StateAccessor
34
+
35
+ # Iterate over the names and yield accordingly.
36
+ # names are either objects responding to #to_sym or hashes.
37
+ #
38
+ # It's only used within this module for abstractin-purposes.
39
+ # Usage below.
40
+ def self.each(*names)
41
+ names.each do |name|
42
+ if name.respond_to?(:to_hash)
43
+ name.to_hash.each do |key, meth|
44
+ key, meth = key.to_sym, meth.to_sym
45
+ yield key, meth
46
+ end
47
+ else
48
+ key = meth = name.to_sym
49
+ yield key, meth
50
+ end
51
+ end
52
+ end
53
+
54
+ # state_writer and state_reader, initializer is a block that may be given
55
+ # and its result will be the new value in case the reader was never called
56
+ # before or the value wasn't set before.
57
+ def state_accessor(*names, &initializer)
58
+ state_writer(*names)
59
+ state_reader(*names, &initializer)
60
+ end
61
+
62
+ # Simple writer accessor to STATE[key]=
63
+ def state_writer(*names)
64
+ StateAccessor.each(*names) do |key, meth|
65
+ define_method("#{meth}="){|obj| STATE[key] = obj }
66
+ end
67
+ end
68
+
69
+ # Reader accessor for STATE[key]
70
+ def state_reader(*names, &initializer)
71
+ StateAccessor.each(*names) do |key, meth|
72
+ if initializer
73
+ define_method(meth) do
74
+ unless STATE.key?(key)
75
+ STATE[key] = instance_eval(&initializer)
76
+ else
77
+ STATE[key]
78
+ end
79
+ end
80
+ else
81
+ define_method(meth){ STATE[key] }
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,45 @@
1
+
2
+ # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
3
+ # All files in this distribution are subject to the terms of the Ruby license.
4
+
5
+ module Ramaze
6
+ class Struct < ::Struct
7
+
8
+ # Makes it possible to access the keys directly by their name, not only
9
+ # their index. The original Struct#values_at tries to call #to_int on the
10
+ # arguments.
11
+ # in Ruby < 1.9 this would lead to a quite unintuitive IndexError, while
12
+ # in 1.9 it will say outright that it cannot convert Symbol into Integer.
13
+ # I think this is neither useful nor expected, so we extend
14
+ # Struct#values_at to recognize valid members of the Struct passed into
15
+ # the method and return their values in the same order, just like
16
+ # Hash#values_at.
17
+ #
18
+ # Example:
19
+ # Point = Struct.new(:x, :y)
20
+ # point = Point.new(15, 10)
21
+ #
22
+ # # Old behaviour:
23
+ # point.values_at(0, 1)
24
+ # # => [15, 10]
25
+ # point.values_at(0..1)
26
+ # # => [15, 10]
27
+ # point.values_at(:y, :x)
28
+ # # => IndexError: offset 20697 too large for struct(size:2)
29
+ #
30
+ # # Added new behaviour:
31
+ # point.values_at(:y, :x)
32
+ # # => [10, 15]
33
+
34
+ def values_at(*keys)
35
+ keys.map do |key|
36
+ case key
37
+ when String, Symbol
38
+ self[key]
39
+ else
40
+ return super
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,16 +1,21 @@
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
- # Extensions for String
4
+ module Ramaze
5
+ module CoreExtensions
5
6
 
6
- class String
7
+ # Extensions for String
7
8
 
8
- # simple transformation to CamelCase from snake_case
9
- #
10
- # 'foo_bar'.camel_case # => 'FooBar'
9
+ module String
10
+
11
+ # simple transformation to CamelCase from snake_case
12
+ #
13
+ # 'foo_bar'.camel_case # => 'FooBar'
14
+
15
+ def camel_case
16
+ split('_').map{|e| e.capitalize}.join
17
+ end
18
+ end
11
19
 
12
- def camel_case
13
- split('_').map{|e| e.capitalize}.join
14
20
  end
15
21
  end
16
-
@@ -1,27 +1,31 @@
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
- # Extensions for String
4
+ module Ramaze
5
+ module CoreExtensions
6
+ # Extensions for String
5
7
 
6
- class String
7
- { :reset => 0,
8
- :bold => 1,
9
- :dark => 2,
10
- :underline => 4,
11
- :blink => 5,
12
- :negative => 7,
13
- :black => 30,
14
- :red => 31,
15
- :green => 32,
16
- :yellow => 33,
17
- :blue => 34,
18
- :magenta => 35,
19
- :cyan => 36,
20
- :white => 37,
21
- }.each do |key, value|
22
- define_method key do
23
- "\e[#{value}m" + self + "\e[0m"
8
+ module String
9
+ { :reset => 0,
10
+ :bold => 1,
11
+ :dark => 2,
12
+ :underline => 4,
13
+ :blink => 5,
14
+ :negative => 7,
15
+ :black => 30,
16
+ :red => 31,
17
+ :green => 32,
18
+ :yellow => 33,
19
+ :blue => 34,
20
+ :magenta => 35,
21
+ :cyan => 36,
22
+ :white => 37,
23
+ }.each do |key, value|
24
+ define_method key do
25
+ "\e[#{value}m" + self + "\e[0m"
26
+ end
27
+ end
24
28
  end
29
+
25
30
  end
26
31
  end
27
-
@@ -1,8 +1,19 @@
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
- # Extensions for String
4
+ module Ramaze
5
+ module CoreExtensions
5
6
 
6
- class String
7
- alias each each_line unless ''.respond_to?(:each)
7
+ # Extensions for String
8
+
9
+ module String
10
+ # 1.9 Compatibility with 1.8
11
+
12
+ unless ''.respond_to?(:each)
13
+ def each(*args, &block)
14
+ each_line(*args, &block)
15
+ end
16
+ end
17
+ end
18
+ end
8
19
  end
@@ -0,0 +1,20 @@
1
+ # Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ module Ramaze
5
+ module CoreExtensions
6
+
7
+ # Extensions for String
8
+
9
+ module String
10
+ unless ''.respond_to?(:end_with?)
11
+ # Compatibility with 1.9
12
+ def end_with?(other)
13
+ other = other.to_s
14
+ self[-other.size, other.size] == other
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -1,29 +1,34 @@
1
1
  require 'cgi'
2
2
  require 'uri'
3
3
 
4
- class String
4
+ module Ramaze
5
+ module CoreExtensions
5
6
 
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)
7
+ # Extensions for String
11
8
 
12
- def escape which = :html
13
- case which
14
- when :html
15
- ::CGI.escapeHTML(self)
16
- when :cgi
17
- ::CGI.escape(self)
18
- when :uri
19
- ::URI.escape(self)
20
- when :sql
21
- Ramaze::deprecated("String#escape(:sql)")
22
- gsub(%r/'/, "''")
23
- else
24
- raise ArgumentError, "do not know how to escape '#{ which }'"
9
+ module String
10
+
11
+ # String#escape is an extensible escaping mechanism for string. currently
12
+ # it suports
13
+ # '<div>foo bar</div>'.esc(:html)
14
+ # 'foo bar'.esc(:uri)
15
+ # 'foo bar'.esc(:cgi)
16
+
17
+ def escape which = :html
18
+ case which
19
+ when :html
20
+ Rack::Utils.escape_html(self)
21
+ when :cgi
22
+ Rack::Utils.escape(self)
23
+ when :uri
24
+ ::URI.escape(self)
25
+ else
26
+ raise ArgumentError, "do not know how to escape '#{ which }'"
27
+ end
28
+ end
29
+
30
+ alias_method 'esc', 'escape'
25
31
  end
26
- end
27
32
 
28
- alias_method 'esc', 'escape'
33
+ end
29
34
  end
@@ -1,15 +1,21 @@
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
- # Extensions for String
4
+ module Ramaze
5
+ module CoreExtensions
5
6
 
6
- class String
7
- unless method_defined?(:ord)
7
+ # Extensions for String
8
8
 
9
- # compatibility with Ruby 1.9
9
+ module String
10
+ unless ''.respond_to?(:ord)
10
11
 
11
- def ord
12
- self[0]
12
+ # compatibility with Ruby 1.9
13
+
14
+ def ord
15
+ self[0]
16
+ end
17
+ end
13
18
  end
19
+
14
20
  end
15
21
  end
@@ -1,15 +1,21 @@
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
- # Extensions for String
4
+ module Ramaze
5
+ module CoreExtensions
5
6
 
6
- class String
7
+ # Extensions for String
7
8
 
8
- # convert to snake_case from CamelCase
9
- #
10
- # 'FooBar'.snake_case # => 'foo_bar'
9
+ module String
10
+
11
+ # convert to snake_case from CamelCase
12
+ #
13
+ # 'FooBar'.snake_case # => 'foo_bar'
14
+
15
+ def snake_case
16
+ gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
17
+ end
18
+ end
11
19
 
12
- def snake_case
13
- gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
14
20
  end
15
21
  end
@@ -1,8 +1,19 @@
1
- class String
2
- unless method_defined?(:start_with?)
3
- # Compatibility with 1.9
4
- def start_with?(other)
5
- self[0, other.size] == other
1
+ module Ramaze
2
+ module CoreExtensions
3
+
4
+ # Extensions for String
5
+
6
+ module String
7
+
8
+ unless ''.respond_to?(:start_with?)
9
+
10
+ # Compatibility with 1.9
11
+
12
+ def start_with?(other)
13
+ other = other.to_s
14
+ self[0, other.size] == other
15
+ end
16
+ end
6
17
  end
7
18
  end
8
19
  end
@@ -1,20 +1,28 @@
1
- class String
2
- # Useful for writing indented String and unindent on demand, based on the
3
- # first line with indentation.
4
- def unindent
5
- find_indent = proc{ |l| l.find{|l| !l.strip.empty?}.to_s[/^(\s+)/, 1] }
1
+ module Ramaze
2
+ module CoreExtensions
6
3
 
7
- lines = self.split("\n")
8
- space = find_indent[lines]
9
- space = find_indent[lines.reverse] unless space
4
+ # Extensions for String
10
5
 
11
- strip.gsub(/^#{space}/, '')
12
- end
13
- alias ui unindent
6
+ module String
7
+
8
+ # Useful for writing indented String and unindent on demand, based on the
9
+ # first line with indentation.
10
+ def unindent
11
+ find_indent = proc{ |l| l.find{|l| !l.strip.empty?}.to_s[/^(\s+)/, 1] }
12
+
13
+ lines = self.split("\n")
14
+ space = find_indent[lines]
15
+ space = find_indent[lines.reverse] unless space
16
+
17
+ strip.gsub(/^#{space}/, '')
18
+ end
19
+ alias ui unindent
14
20
 
15
- # Destructive variant of undindent, replacing the String
16
- def unindent!
17
- self.replace unindent
21
+ # Destructive variant of undindent, replacing the String
22
+ def unindent!
23
+ self.replace unindent
24
+ end
25
+ alias ui! unindent!
26
+ end
18
27
  end
19
- alias ui! unindent!
20
28
  end