manveru-ramaze 2008.08 → 2008.09

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/Rakefile +1 -1
  2. data/bin/ramaze +1 -0
  3. data/doc/CHANGELOG +966 -0
  4. data/doc/tutorial/todolist.html +421 -313
  5. data/doc/tutorial/todolist.mkd +26 -9
  6. data/examples/helpers/paginate.rb +71 -0
  7. data/examples/misc/simple_auth.rb +20 -8
  8. data/lib/proto/controller/init.rb +10 -0
  9. data/lib/proto/controller/main.rb +1 -3
  10. data/lib/proto/model/init.rb +4 -0
  11. data/lib/proto/spec/main.rb +2 -1
  12. data/lib/proto/start.rb +3 -3
  13. data/lib/ramaze.rb +6 -1
  14. data/lib/ramaze/action.rb +2 -2
  15. data/lib/ramaze/adapter.rb +0 -5
  16. data/lib/ramaze/adapter/base.rb +24 -7
  17. data/lib/ramaze/contrib/gzip_filter.rb +22 -9
  18. data/lib/ramaze/contrib/maruku_uv.rb +59 -0
  19. data/lib/ramaze/contrib/profiling.rb +1 -1
  20. data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
  21. data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
  22. data/lib/ramaze/contrib/sequel/image.rb +198 -0
  23. data/lib/ramaze/contrib/sequel/relation.rb +82 -0
  24. data/lib/ramaze/controller/resolve.rb +1 -1
  25. data/lib/ramaze/current.rb +60 -20
  26. data/lib/ramaze/current/response.rb +15 -3
  27. data/lib/ramaze/dispatcher.rb +9 -3
  28. data/lib/ramaze/dispatcher/action.rb +2 -3
  29. data/lib/ramaze/dispatcher/directory.rb +1 -1
  30. data/lib/ramaze/dispatcher/error.rb +1 -1
  31. data/lib/ramaze/dispatcher/file.rb +1 -1
  32. data/lib/ramaze/helper/formatting.rb +33 -0
  33. data/lib/ramaze/helper/paginate.rb +234 -0
  34. data/lib/ramaze/option.rb +2 -2
  35. data/lib/ramaze/reloader.rb +2 -2
  36. data/lib/ramaze/snippets.rb +13 -0
  37. data/lib/ramaze/snippets/array/put_within.rb +31 -24
  38. data/lib/ramaze/snippets/binding/locals.rb +23 -11
  39. data/lib/ramaze/snippets/kernel/constant.rb +36 -21
  40. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +12 -6
  41. data/lib/ramaze/snippets/numeric/filesize_format.rb +24 -17
  42. data/lib/ramaze/snippets/numeric/time.rb +63 -56
  43. data/lib/ramaze/snippets/object/__dir__.rb +29 -0
  44. data/lib/ramaze/snippets/object/acquire.rb +40 -0
  45. data/lib/ramaze/snippets/object/instance_variable_defined.rb +16 -5
  46. data/lib/ramaze/snippets/object/pretty.rb +14 -4
  47. data/lib/ramaze/snippets/object/scope.rb +14 -7
  48. data/lib/ramaze/snippets/ordered_set.rb +4 -0
  49. data/lib/ramaze/snippets/proc/locals.rb +17 -9
  50. data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
  51. data/lib/ramaze/snippets/string/camel_case.rb +13 -8
  52. data/lib/ramaze/snippets/string/color.rb +24 -20
  53. data/lib/ramaze/snippets/string/each.rb +14 -3
  54. data/lib/ramaze/snippets/string/end_with.rb +17 -6
  55. data/lib/ramaze/snippets/string/esc.rb +26 -18
  56. data/lib/ramaze/snippets/string/ord.rb +12 -6
  57. data/lib/ramaze/snippets/string/snake_case.rb +13 -7
  58. data/lib/ramaze/snippets/string/start_with.rb +16 -6
  59. data/lib/ramaze/snippets/string/unindent.rb +23 -15
  60. data/lib/ramaze/snippets/thread/into.rb +3 -3
  61. data/lib/ramaze/spec/helper/snippets.rb +8 -0
  62. data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
  63. data/lib/ramaze/tool/create.rb +27 -53
  64. data/lib/ramaze/tool/project_creator.rb +110 -0
  65. data/lib/ramaze/version.rb +1 -1
  66. data/rake_tasks/gem.rake +2 -1
  67. data/rake_tasks/maintenance.rake +38 -0
  68. data/rake_tasks/release.rake +6 -2
  69. data/rake_tasks/spec.rake +1 -2
  70. data/ramaze.gemspec +69 -78
  71. data/spec/examples/simple_auth.rb +2 -2
  72. data/spec/examples/templates/template_haml.rb +0 -2
  73. data/spec/ramaze/current/session.rb +1 -1
  74. data/spec/ramaze/dispatcher/file.rb +2 -2
  75. data/spec/ramaze/helper/formatting.rb +13 -0
  76. data/spec/ramaze/rewrite.rb +1 -1
  77. data/spec/ramaze/struct.rb +47 -0
  78. data/spec/ramaze/template/markaby.rb +1 -1
  79. data/spec/snippets/{kernel → object}/__dir__.rb +0 -0
  80. data/spec/snippets/{kernel → object}/acquire.rb +0 -0
  81. metadata +69 -78
  82. data/examples/app/rammit/spec/rammit.rb +0 -31
  83. data/examples/app/rammit/src/controller/main.rb +0 -3
  84. data/examples/app/rammit/src/controller/page.rb +0 -16
  85. data/examples/app/rammit/src/model.rb +0 -33
  86. data/examples/app/rammit/start.rb +0 -8
  87. data/examples/app/rammit/template/index.xhtml +0 -14
  88. data/examples/app/rammit/template/page/view.xhtml +0 -4
  89. data/lib/ramaze/snippets/kernel/__dir__.rb +0 -23
  90. data/lib/ramaze/snippets/kernel/acquire.rb +0 -34
  91. data/lib/ramaze/snippets/struct/fill.rb +0 -23
  92. data/lib/ramaze/snippets/struct/values_at.rb +0 -39
  93. data/lib/ramaze/snippets/symbol/to_proc.rb +0 -24
  94. data/lib/ramaze/sourcereload.rb +0 -183
  95. data/spec/snippets/struct/fill.rb +0 -26
  96. data/spec/snippets/struct/values_at.rb +0 -52
  97. data/spec/snippets/symbol/to_proc.rb +0 -13
data/lib/ramaze/option.rb CHANGED
@@ -73,7 +73,7 @@ module Ramaze
73
73
  :controllers, Set.new
74
74
 
75
75
  o "Instruction for daemonize, only works with bin/ramaze for now",
76
- :daemonize, 'start', :cli => [:start, :stop]
76
+ :daemonize, '', :cli => [:start, :stop]
77
77
 
78
78
  o "Turn on customized error pages. Use Rack::ShowException otherwise.",
79
79
  :error_page, true, :cli => true
@@ -106,7 +106,7 @@ module Ramaze
106
106
  :middleware, true
107
107
 
108
108
  o "For your own modes to decide on",
109
- :mode, :live, :cli => [:live, :dev]
109
+ :mode, :live, :cli => [:live, :dev, :spec]
110
110
 
111
111
  o "The place ramaze was started from, useful mostly for debugging",
112
112
  :origin, :main
@@ -106,7 +106,7 @@ module Ramaze
106
106
  end
107
107
 
108
108
  def rotation
109
- files = [$0, *$LOADED_FEATURES].uniq
109
+ files = [$0, __FILE__, *$LOADED_FEATURES].uniq
110
110
  paths = ['./', *$LOAD_PATH].uniq
111
111
 
112
112
  files.each do |file|
@@ -117,7 +117,7 @@ module Ramaze
117
117
  @cache[file] = path
118
118
  yield(path, stat)
119
119
  else
120
- Log::warn "Couldn't figure path for #{file}"
120
+ # Quite harmless, we just couldn't figure out path for #{file}
121
121
  end
122
122
  end
123
123
  end
@@ -7,3 +7,16 @@ glob = File.join(dir, '**', '*.rb')
7
7
  Dir[glob].each do |snippet|
8
8
  require(snippet)
9
9
  end
10
+
11
+ Ramaze::CoreExtensions.constants.each do |const|
12
+ ext = Ramaze::CoreExtensions.const_get(const)
13
+ into = Module.const_get(const)
14
+
15
+ collisions = ext.instance_methods & into.instance_methods
16
+
17
+ if collisions.empty?
18
+ into.__send__(:include, ext)
19
+ else
20
+ warn "Won't include %p with %p, %p exists" % [into, ext, collisions]
21
+ end
22
+ end
@@ -1,37 +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
- class Array
4
+ module Ramaze
5
+ module CoreExtensions
5
6
 
6
- # a = [1, 2, 3]
7
- # a.put_within(4, :after => 2, :before => 3)
8
- # a # => [1, 2, 4, 3]
7
+ # Extensions for Array
9
8
 
10
- def put_within(object, constrain)
11
- pre, post = constrain.values_at(:after, :before)
9
+ module Array
12
10
 
13
- unless rindex(post) - index(pre) == 1
14
- raise ArgumentError, "Too many elements within constrain"
15
- end
11
+ # a = [1, 2, 3]
12
+ # a.put_within(4, :after => 2, :before => 3)
13
+ # a # => [1, 2, 4, 3]
16
14
 
17
- put_after(pre, object)
18
- end
15
+ def put_within(object, constrain)
16
+ pre, post = constrain.values_at(:after, :before)
19
17
 
20
- # a = [1, 2, 3]
21
- # a.put_after(2, 4)
22
- # a # => [1, 2, 4, 3]
18
+ return put_after(pre, object) if rindex(post) - index(pre) == 1
23
19
 
24
- def put_after(element, object)
25
- raise ArgumentError, "The given element doesn't exist" unless include?(element)
26
- self[index(element) + 1, 0] = object
27
- end
20
+ raise ArgumentError, "Too many elements within constrain"
21
+ end
22
+
23
+ # a = [1, 2, 3]
24
+ # a.put_after(2, 4)
25
+ # a # => [1, 2, 4, 3]
28
26
 
29
- # a = [1, 2, 3]
30
- # a.put_before(2, 4)
31
- # a # => [1, 4, 2, 3]
27
+ def put_after(element, object)
28
+ return self[index(element) + 1, 0] = object if include?(element)
32
29
 
33
- def put_before(element, object)
34
- raise ArgumentError, "The given element doesn't exist" unless include?(element)
35
- self[rindex(element), 0] = object
30
+ raise ArgumentError, "The given element doesn't exist"
31
+ end
32
+
33
+ # a = [1, 2, 3]
34
+ # a.put_before(2, 4)
35
+ # a # => [1, 4, 2, 3]
36
+
37
+ def put_before(element, object)
38
+ return self[rindex(element), 0] = object if include?(element)
39
+
40
+ raise ArgumentError, "The given element doesn't exist"
41
+ end
42
+ end
36
43
  end
37
44
  end
@@ -1,13 +1,25 @@
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
- Kernel::eval '
9
- local_variables.inject({}){|h,v| k = v.to_s; h.merge!(k => eval(k)) }
10
- ', self
11
- end
1
+ module Ramaze
2
+ module CoreExtensions
3
+
4
+ # Extensions for Binding
5
+
6
+ module Binding
12
7
 
8
+ # Returns a hash of localvar/localvar-values from binding, useful for
9
+ # template engines that do not accept bindings and force passing locals
10
+ # via hash
11
+ #
12
+ # Usage:
13
+ # x = 42; p binding.locals #=> {'x'=> 42}
14
+
15
+ def locals
16
+ ::Kernel::eval '
17
+ local_variables.inject({}){|h,v|
18
+ k = v.to_s
19
+ h.merge!(k => eval(k))
20
+ }', self
21
+ end
22
+
23
+ end
24
+ end
13
25
  end
@@ -1,26 +1,41 @@
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 Kernel
5
-
6
- module Kernel
7
- # Original from Trans (Facets 1.4.5)
8
- # This is similar to +Module#const_get+ but is accessible at all levels,
9
- # and, unlike +const_get+, can handle module hierarchy.
10
- #
11
- # constant("Fixnum") # -> Fixnum
12
- # constant(:Fixnum) # -> Fixnum
13
- #
14
- # constant("Process::Sys") # -> Process::Sys
15
- # constant("Regexp::MULTILINE") # -> 4
16
- #
17
- # require 'test/unit'
18
- # Test.constant("Unit::Assertions") # -> Test::Unit::Assertions
19
- # Test.constant("::Test::Unit") # -> Test::Unit
20
-
21
- def constant(const)
22
- const = const.to_s.dup
23
- base = const.sub!(/^::/, '') ? Object : ( self.kind_of?(Module) ? self : self.class )
24
- const.split(/::/).inject(base){ |mod, name| mod.const_get(name) }
4
+ module Ramaze
5
+ module CoreExtensions
6
+
7
+ # Extensions for Kernel
8
+
9
+ module Object
10
+
11
+ # Original from Trans (Facets 1.4.5)
12
+ # This is similar to +Module#const_get+ but is accessible at all levels,
13
+ # and, unlike +const_get+, can handle module hierarchy.
14
+ #
15
+ # constant("Fixnum") # -> Fixnum
16
+ # constant(:Fixnum) # -> Fixnum
17
+ #
18
+ # constant("Process::Sys") # -> Process::Sys
19
+ # constant("Regexp::MULTILINE") # -> 4
20
+ #
21
+ # require 'test/unit'
22
+ # Test.constant("Unit::Assertions") # -> Test::Unit::Assertions
23
+ # Test.constant("::Test::Unit") # -> Test::Unit
24
+
25
+ def constant(const)
26
+ const = const.to_s.dup
27
+
28
+ if const.sub!(/^::/, '')
29
+ base = Object
30
+ elsif self.kind_of?(Module)
31
+ base = self
32
+ else
33
+ base = self.class
34
+ end
35
+
36
+ const.split(/::/).inject(base){ |mod, name| mod.const_get(name) }
37
+ end
38
+ end
39
+
25
40
  end
26
41
  end
@@ -3,13 +3,19 @@
3
3
 
4
4
  require 'pp'
5
5
 
6
- # Extensions for Kernel
6
+ module Ramaze
7
+ module CoreExtensions
7
8
 
8
- module Kernel
9
- unless defined?(pretty_inspect)
10
- # returns a pretty printed object as a string.
11
- def pretty_inspect
12
- PP.pp(self, '')
9
+ # Extensions for Kernel
10
+
11
+ module Kernel
12
+ unless defined?(pretty_inspect)
13
+ # returns a pretty printed object as a string.
14
+ def pretty_inspect
15
+ PP.pp(self, '')
16
+ end
17
+ end
13
18
  end
19
+
14
20
  end
15
21
  end
@@ -1,25 +1,32 @@
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
- class Numeric
5
- FILESIZE_FORMAT = [
6
- ['%.1fT', 1 << 40],
7
- ['%.1fG', 1 << 30],
8
- ['%.1fM', 1 << 20],
9
- ['%.1fK', 1 << 10],
10
- ]
4
+ module Ramaze
5
+ module CoreExtensions
11
6
 
12
- # Output this number as easily readable filesize.
13
- # Usage:
14
- # 100_000.filesize_format # => "97.7K"
15
- # 100_000_000.filesize_format # => "95.4M"
16
- # 100_000_000_000.filesize_format # => "93.1G"
17
- # 100_000_000_000_000.filesize_format # => "90.9T"
18
- def filesize_format
19
- FILESIZE_FORMAT.each do |format, size|
20
- return format % (self.to_f / size) if self >= size
7
+ # Extensions for Numeric
8
+ module Numeric
9
+ FILESIZE_FORMAT = [
10
+ ['%.1fT', 1 << 40],
11
+ ['%.1fG', 1 << 30],
12
+ ['%.1fM', 1 << 20],
13
+ ['%.1fK', 1 << 10],
14
+ ]
15
+
16
+ # Output this number as easily readable filesize.
17
+ # Usage:
18
+ # 100_000.filesize_format # => "97.7K"
19
+ # 100_000_000.filesize_format # => "95.4M"
20
+ # 100_000_000_000.filesize_format # => "93.1G"
21
+ # 100_000_000_000_000.filesize_format # => "90.9T"
22
+ def filesize_format
23
+ FILESIZE_FORMAT.each do |format, size|
24
+ return format % (self.to_f / size) if self >= size
25
+ end
26
+
27
+ self.to_s
28
+ end
21
29
  end
22
30
 
23
- self.to_s
24
31
  end
25
32
  end
@@ -1,56 +1,63 @@
1
- class Numeric
2
-
3
- def seconds
4
- self
5
- end
6
- alias second seconds
7
-
8
- # 60 seconds in a minute
9
- def minutes
10
- self * 60
11
- end
12
- alias minute minutes
13
-
14
- # 60 minutes in an hour
15
- def hours
16
- self * 3600
17
- end
18
- alias hour hours
19
-
20
- # 24 hours in a day
21
- def days
22
- self * 86400
23
- end
24
- alias day days
25
-
26
- # 7 days in a week
27
- def weeks
28
- self * 604800
29
- end
30
- alias week weeks
31
-
32
- # 30 days in a month
33
- def months
34
- self * 2592000
35
- end
36
- alias month months
37
-
38
- # 365.25 days in a year
39
- def years
40
- self * 883612800
41
- end
42
- alias year years
43
-
44
- # Time in the past, i.e. 3.days.ago
45
- def ago t = Time.now
46
- t - self
47
- end
48
- alias before ago
49
-
50
- # Time in the future, i.e. 3.days.from_now
51
- def from_now t = Time.now
52
- t + self
53
- end
54
- alias since from_now
55
-
56
- end unless 5.respond_to? :days
1
+ module Ramaze
2
+ module CoreExtensions
3
+
4
+ # Extensions for Numeric
5
+
6
+ module Numeric
7
+ def seconds
8
+ self
9
+ end
10
+ alias second seconds
11
+
12
+ # 60 seconds in a minute
13
+ def minutes
14
+ self * 60
15
+ end
16
+ alias minute minutes
17
+
18
+ # 60 minutes in an hour
19
+ def hours
20
+ self * 3600
21
+ end
22
+ alias hour hours
23
+
24
+ # 24 hours in a day
25
+ def days
26
+ self * 86400
27
+ end
28
+ alias day days
29
+
30
+ # 7 days in a week
31
+ def weeks
32
+ self * 604800
33
+ end
34
+ alias week weeks
35
+
36
+ # 30 days in a month
37
+ def months
38
+ self * 2592000
39
+ end
40
+ alias month months
41
+
42
+ # 365.25 days in a year
43
+ def years
44
+ self * 883612800
45
+ end
46
+ alias year years
47
+
48
+ # Time in the past, i.e. 3.days.ago
49
+ def ago t = Time.now
50
+ t - self
51
+ end
52
+ alias before ago
53
+
54
+ # Time in the future, i.e. 3.days.from_now
55
+ def from_now t = Time.now
56
+ t + self
57
+ end
58
+ alias since from_now
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,29 @@
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 Object
8
+
9
+ module Object
10
+ unless defined?(__DIR__)
11
+
12
+ # This is similar to +__FILE__+ and +__LINE__+, and returns a String
13
+ # representing the directory of the current file is.
14
+ # Unlike +__FILE__+ the path returned is absolute.
15
+ #
16
+ # This method is convenience for the
17
+ # File.expand_path(File.dirname(__FILE__))
18
+ # idiom.
19
+ #
20
+
21
+ def __DIR__()
22
+ filename = caller[0][/^(.*):/, 1]
23
+ File.expand_path(File.dirname(filename))
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+ end