ramaze 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/Rakefile +14 -259
  2. data/bin/ramaze +52 -25
  3. data/doc/AUTHORS +6 -0
  4. data/doc/CHANGELOG +1363 -42
  5. data/doc/INSTALL +1 -1
  6. data/doc/README +48 -35
  7. data/doc/README.html +637 -0
  8. data/doc/TODO +7 -16
  9. data/doc/allison/allison.css +6 -7
  10. data/doc/allison/allison.gif +0 -0
  11. data/doc/allison/cache/STYLE +1 -2
  12. data/doc/changes.txt +3375 -0
  13. data/doc/changes.xml +3378 -0
  14. data/doc/meta/announcement.txt +47 -0
  15. data/doc/meta/configuration.txt +179 -0
  16. data/doc/meta/internals.txt +111 -0
  17. data/doc/readme_chunks/features.txt +8 -16
  18. data/doc/readme_chunks/installing.txt +7 -1
  19. data/doc/tutorial/todolist.txt +2 -3
  20. data/examples/blog/main.rb +9 -8
  21. data/examples/blog/public/styles/blog.css +132 -0
  22. data/examples/blog/src/controller.rb +14 -41
  23. data/examples/blog/src/model.rb +12 -13
  24. data/examples/blog/src/view.rb +16 -0
  25. data/examples/blog/template/edit.xhtml +19 -8
  26. data/examples/blog/template/index.xhtml +14 -22
  27. data/examples/blog/template/new.xhtml +18 -5
  28. data/examples/caching.rb +5 -8
  29. data/examples/element.rb +3 -3
  30. data/examples/hello.rb +3 -5
  31. data/examples/simple.rb +4 -7
  32. data/examples/templates/template/external.haml +8 -7
  33. data/examples/templates/template/external.mab +11 -8
  34. data/examples/templates/template_amrita2.rb +4 -4
  35. data/examples/templates/template_erubis.rb +3 -3
  36. data/examples/templates/template_ezamar.rb +1 -2
  37. data/examples/templates/template_haml.rb +24 -23
  38. data/examples/templates/template_liquid.rb +3 -1
  39. data/examples/templates/template_markaby.rb +15 -9
  40. data/examples/todolist/src/element/page.rb +1 -1
  41. data/lib/proto/conf/benchmark.yaml +6 -20
  42. data/lib/proto/conf/debug.yaml +6 -19
  43. data/lib/proto/conf/live.yaml +7 -19
  44. data/lib/proto/conf/silent.yaml +6 -16
  45. data/lib/proto/conf/stage.yaml +6 -18
  46. data/lib/proto/public/error.zmr +2 -2
  47. data/lib/ramaze.rb +34 -72
  48. data/lib/ramaze/adapter.rb +21 -18
  49. data/lib/ramaze/adapter/mongrel.rb +0 -3
  50. data/lib/ramaze/adapter/webrick.rb +6 -6
  51. data/lib/ramaze/cache/memcached.rb +3 -0
  52. data/lib/ramaze/controller.rb +227 -183
  53. data/lib/ramaze/dispatcher.rb +34 -129
  54. data/lib/ramaze/dispatcher/action.rb +28 -0
  55. data/lib/ramaze/dispatcher/error.rb +43 -0
  56. data/lib/ramaze/dispatcher/file.rb +34 -0
  57. data/lib/ramaze/global.rb +89 -48
  58. data/lib/ramaze/helper/aspect.rb +8 -6
  59. data/lib/ramaze/helper/auth.rb +3 -3
  60. data/lib/ramaze/helper/cache.rb +2 -2
  61. data/lib/ramaze/helper/file.rb +14 -0
  62. data/lib/ramaze/helper/inform.rb +36 -0
  63. data/lib/ramaze/helper/link.rb +7 -3
  64. data/lib/ramaze/helper/markaby.rb +30 -0
  65. data/lib/ramaze/helper/redirect.rb +2 -0
  66. data/lib/ramaze/inform.rb +8 -182
  67. data/lib/ramaze/inform/analogger.rb +19 -0
  68. data/lib/ramaze/inform/growl.rb +28 -0
  69. data/lib/ramaze/inform/hub.rb +26 -0
  70. data/lib/ramaze/inform/informer.rb +92 -0
  71. data/lib/ramaze/inform/informing.rb +44 -0
  72. data/lib/ramaze/inform/syslog.rb +27 -0
  73. data/lib/ramaze/inform/xosd.rb +42 -0
  74. data/lib/ramaze/snippets.rb +6 -2
  75. data/lib/ramaze/snippets/object/traits.rb +13 -1
  76. data/lib/ramaze/snippets/ramaze/autoreload.rb +58 -2
  77. data/lib/ramaze/snippets/string/color.rb +27 -0
  78. data/lib/ramaze/snippets/string/each.rb +6 -0
  79. data/lib/ramaze/snippets/struct/fill.rb +15 -0
  80. data/lib/ramaze/template/ezamar.rb +13 -22
  81. data/lib/ramaze/template/ezamar/element.rb +12 -12
  82. data/lib/ramaze/template/liquid.rb +19 -18
  83. data/lib/ramaze/template/markaby.rb +37 -58
  84. data/lib/ramaze/tool/localize.rb +128 -0
  85. data/lib/ramaze/tool/tidy.rb +51 -21
  86. data/lib/ramaze/trinity.rb +3 -3
  87. data/lib/ramaze/trinity/request.rb +41 -23
  88. data/lib/ramaze/trinity/response.rb +10 -5
  89. data/lib/ramaze/trinity/session.rb +17 -3
  90. data/lib/ramaze/version.rb +2 -2
  91. data/rake_tasks/conf.rake +56 -0
  92. data/rake_tasks/gem.rake +44 -0
  93. data/rake_tasks/maintaince.rake +187 -0
  94. data/spec/all.rb +32 -0
  95. data/spec/examples/caching.rb +19 -0
  96. data/spec/examples/element.rb +15 -0
  97. data/spec/examples/hello.rb +11 -0
  98. data/spec/examples/simple.rb +51 -0
  99. data/spec/examples/templates/template_amrita2.rb +14 -0
  100. data/spec/examples/templates/template_erubis.rb +21 -0
  101. data/spec/examples/templates/template_ezamar.rb +22 -0
  102. data/spec/examples/templates/template_haml.rb +23 -0
  103. data/spec/examples/templates/template_liquid.rb +24 -0
  104. data/spec/examples/templates/template_markaby.rb +21 -0
  105. data/spec/helper.rb +81 -0
  106. data/spec/{spec_helper_context.rb → helper/context.rb} +1 -1
  107. data/spec/helper/layout.rb +55 -0
  108. data/spec/helper/mock_http.rb +66 -0
  109. data/spec/{spec_helper_requester.rb → helper/requester.rb} +0 -6
  110. data/spec/{spec_helper_simple_http.rb → helper/simple_http.rb} +57 -57
  111. data/spec/helper/wrap.rb +193 -0
  112. data/spec/{adapter_spec.rb → ramaze/adapter.rb} +7 -5
  113. data/spec/{tc_adapter_mongrel.rb → ramaze/adapter/mongrel.rb} +2 -2
  114. data/spec/{tc_adapter_webrick.rb → ramaze/adapter/webrick.rb} +2 -2
  115. data/spec/{tc_cache.rb → ramaze/cache.rb} +16 -16
  116. data/spec/ramaze/conf/locale_de.yaml +6 -0
  117. data/spec/ramaze/conf/locale_en.yaml +6 -0
  118. data/spec/ramaze/controller.rb +184 -0
  119. data/spec/ramaze/controller/template/greet.xhtml +1 -0
  120. data/spec/ramaze/controller/template_resolving.rb +54 -0
  121. data/spec/ramaze/dependencies.rb +16 -0
  122. data/spec/{tc_element.rb → ramaze/element.rb} +21 -19
  123. data/spec/ramaze/error.rb +64 -0
  124. data/spec/{tc_gestalt.rb → ramaze/gestalt.rb} +10 -10
  125. data/spec/{tc_global.rb → ramaze/global.rb} +7 -7
  126. data/spec/{tc_helper_aspect.rb → ramaze/helper/aspect.rb} +22 -14
  127. data/spec/{tc_helper_auth.rb → ramaze/helper/auth.rb} +9 -7
  128. data/spec/{tc_helper_cache.rb → ramaze/helper/cache.rb} +14 -24
  129. data/spec/{tc_helper_feed.rb → ramaze/helper/feed.rb} +12 -12
  130. data/spec/ramaze/helper/file.rb +17 -0
  131. data/spec/{tc_helper_flash.rb → ramaze/helper/flash.rb} +16 -17
  132. data/spec/{tc_helper_form.rb → ramaze/helper/form.rb} +25 -26
  133. data/spec/{tc_helper_link.rb → ramaze/helper/link.rb} +9 -9
  134. data/spec/{tc_helper_redirect.rb → ramaze/helper/redirect.rb} +11 -10
  135. data/spec/{tc_helper_stack.rb → ramaze/helper/stack.rb} +10 -11
  136. data/spec/ramaze/inform/informer.rb +40 -0
  137. data/spec/ramaze/inform/syslog.rb +10 -0
  138. data/spec/ramaze/localize.rb +40 -0
  139. data/spec/ramaze/morpher.rb +82 -0
  140. data/spec/ramaze/params.rb +124 -0
  141. data/spec/{public → ramaze/public}/error404.xhtml +0 -0
  142. data/spec/{public → ramaze/public}/favicon.ico +0 -0
  143. data/spec/{public → ramaze/public}/ramaze.png +0 -0
  144. data/spec/{public → ramaze/public}/test_download.css +0 -0
  145. data/spec/ramaze/request.rb +129 -0
  146. data/spec/{tc_request_mongrel.rb → ramaze/request/mongrel.rb} +2 -2
  147. data/spec/{tc_request_webrick.rb → ramaze/request/webrick.rb} +1 -1
  148. data/spec/{tc_session.rb → ramaze/session.rb} +18 -18
  149. data/spec/{tc_store.rb → ramaze/store/default.rb} +10 -10
  150. data/spec/{tc_store_yaml.rb → ramaze/store/yaml.rb} +9 -9
  151. data/spec/ramaze/template.rb +86 -0
  152. data/spec/{tc_template_amrita2.rb → ramaze/template/amrita2.rb} +5 -5
  153. data/spec/{template → ramaze/template}/amrita2/data.amrita +0 -0
  154. data/spec/{template → ramaze/template}/amrita2/index.amrita +0 -0
  155. data/spec/{template → ramaze/template}/amrita2/sum.amrita +0 -0
  156. data/spec/{tc_template_erubis.rb → ramaze/template/erubis.rb} +9 -9
  157. data/spec/{template → ramaze/template}/erubis/sum.rhtml +0 -0
  158. data/spec/ramaze/template/ezamar.rb +62 -0
  159. data/spec/{template → ramaze/template}/ezamar/another/long/action.zmr +0 -0
  160. data/spec/{template → ramaze/template}/ezamar/combined.zmr +0 -0
  161. data/spec/{template → ramaze/template}/ezamar/file_only.zmr +0 -0
  162. data/spec/{template → ramaze/template}/ezamar/index.zmr +0 -0
  163. data/spec/ramaze/template/ezamar/nested.zmr +1 -0
  164. data/spec/{template → ramaze/template}/ezamar/some__long__action.zmr +0 -0
  165. data/spec/{template → ramaze/template}/ezamar/sum.zmr +0 -0
  166. data/spec/{tc_template_haml.rb → ramaze/template/haml.rb} +7 -7
  167. data/spec/{template → ramaze/template}/haml/index.haml +0 -0
  168. data/spec/{template → ramaze/template}/haml/with_vars.haml +0 -0
  169. data/spec/{tc_template_liquid.rb → ramaze/template/liquid.rb} +7 -7
  170. data/spec/{template → ramaze/template}/liquid/index.liquid +0 -0
  171. data/spec/{template → ramaze/template}/liquid/products.liquid +0 -0
  172. data/spec/ramaze/template/markaby.rb +59 -0
  173. data/spec/{template → ramaze/template}/markaby/external.mab +0 -0
  174. data/spec/{template → ramaze/template}/markaby/sum.mab +0 -0
  175. data/spec/ramaze/template/ramaze/external.test +1 -0
  176. data/spec/{tc_tidy.rb → ramaze/tidy.rb} +3 -3
  177. metadata +145 -81
  178. data/examples/blog/public/screen.css +0 -106
  179. data/examples/blog/src/element.rb +0 -58
  180. data/examples/blog/template/view.xhtml +0 -15
  181. data/examples/blog/test/tc_entry.rb +0 -18
  182. data/lib/proto/public/404.jpg +0 -0
  183. data/spec/request_tc_helper.rb +0 -135
  184. data/spec/spec_all.rb +0 -118
  185. data/spec/spec_helper.rb +0 -66
  186. data/spec/tc_controller.rb +0 -49
  187. data/spec/tc_dependencies.rb +0 -13
  188. data/spec/tc_error.rb +0 -43
  189. data/spec/tc_morpher.rb +0 -88
  190. data/spec/tc_params.rb +0 -125
  191. data/spec/tc_template_ezamar.rb +0 -64
  192. data/spec/tc_template_markaby.rb +0 -72
  193. data/spec/template/ezamar/nested.zmr +0 -1
@@ -0,0 +1,26 @@
1
+ # Copyright (c) 2006 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
+ class LogHub
6
+ include Informing
7
+
8
+ attr_accessor :loggers
9
+
10
+ def initialize(*loggers)
11
+ @loggers = loggers
12
+ @loggers.map! do |logger|
13
+ logger.is_a?(Class) ? logger.new : logger
14
+ end
15
+ @loggers.delete_if {|x| x == self }
16
+ @loggers.uniq!
17
+ @loggers.compact!
18
+ end
19
+
20
+ def inform(tag, *args)
21
+ @loggers.each do |logger|
22
+ logger.inform(tag, *args)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,92 @@
1
+ # Copyright (c) 2006 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
+ class Informer
6
+ include Informing
7
+
8
+ attr_accessor :colorize, :out
9
+
10
+ # parameter for Time.now.strftime
11
+ trait :timestamp => "%Y-%m-%d %H:%M:%S"
12
+
13
+ # This is how the final output is arranged.
14
+ trait :format => "[%time] %prefix %text"
15
+
16
+ # Which tag should be in what color
17
+ trait :colors => {
18
+ :info => :green,
19
+ :debug => :yellow,
20
+ :warn => :red,
21
+ :error => :red,
22
+ }
23
+
24
+ def initialize(out = $stdout, colorize = nil)
25
+ @out =
26
+ case out
27
+ when STDOUT, :stdout, 'stdout'
28
+ $stdout
29
+ when STDERR, :stderr, 'stderr'
30
+ $stderr
31
+ when IO
32
+ out
33
+ else
34
+ if out.respond_to?(:puts)
35
+ out
36
+ else
37
+ colorize = false
38
+ File.open(out.to_s, 'ab+')
39
+ end
40
+ end
41
+
42
+ @colorize = @out.tty? rescue false if colorize.nil?
43
+ end
44
+
45
+ def shutdown
46
+ if @out.respond_to?(:close)
47
+ Inform.debug("close, #{@out.inspect}")
48
+ @out.close
49
+ end
50
+ end
51
+
52
+ def inform tag, *messages
53
+ return if closed?
54
+ messages.flatten!
55
+
56
+ prefix = tag.to_s.upcase.ljust(5)
57
+
58
+ if @colorize
59
+ color = class_trait[:colors][tag] ||= :white
60
+ prefix.replace prefix.send(color)
61
+ end
62
+
63
+ messages.each do |message|
64
+ @out.puts(log_interpolate(prefix, message))
65
+ end
66
+
67
+ @out.flush if @out.respond_to?(:flush)
68
+ end
69
+
70
+ def log_interpolate prefix, text, time = timestamp
71
+ message = class_trait[:format].dup
72
+
73
+ vars = { '%time' => time, '%prefix' => prefix, '%text' => text }
74
+ vars.each{|from, to| message.gsub!(from, to) }
75
+
76
+ message
77
+ end
78
+
79
+ # This uses Global.inform_timestamp or a date in the format of
80
+ # %Y-%m-%d %H:%M:%S
81
+ # # => "2007-01-19 21:09:32"
82
+
83
+ def timestamp
84
+ mask = class_trait[:timestamp]
85
+ Time.now.strftime(mask || "%Y-%m-%d %H:%M:%S")
86
+ end
87
+
88
+ def closed?
89
+ @out.respond_to?(:closed?) and @out.closed?
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2006 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 Informing
6
+ def tag_inform(tag, meth, *strings)
7
+ strings.each do |string|
8
+ string = (string.respond_to?(:to_str) ? string : string.send(meth))
9
+ inform(tag, string)
10
+ end
11
+ end
12
+
13
+ def info(*strings)
14
+ tag_inform(:info, :to_s, *strings)
15
+ end
16
+
17
+ def warn(*strings)
18
+ tag_inform(:warn, :to_s, *strings)
19
+ end
20
+
21
+ def debug(*strings)
22
+ tag_inform(:debug, :inspect, *strings)
23
+ end
24
+
25
+ alias << debug
26
+
27
+ def error(ex)
28
+ if ex.respond_to?(:exception)
29
+ message = ex.backtrace[0..Global.backtrace_size]
30
+ message.unshift(ex.inspect)
31
+ else
32
+ message = ex.to_s
33
+ end
34
+ tag_inform(:error, :to_s, *message)
35
+ end
36
+
37
+ def inform(*args)
38
+ raise "#inform should be implemented by an instance including this module (#{self})"
39
+ end
40
+
41
+ def shutdown
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,27 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'syslog'
5
+
6
+ module Ramaze
7
+ class Syslog
8
+ include ::Syslog
9
+
10
+ def initialize
11
+ open unless ::Syslog.opened?
12
+ end
13
+
14
+ alias error err
15
+ alias warn warning
16
+
17
+ def inform(tag, *args)
18
+ self.__send__(tag, *args)
19
+ end
20
+
21
+ public :error, :warn
22
+
23
+ def inspect
24
+ ::Syslog.inspect
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'xosd'
5
+
6
+ module Ramaze
7
+
8
+ class Xosd < ::Xosd
9
+ include Informing
10
+
11
+ trait :timeout => 3
12
+ trait :lines => 3
13
+
14
+ trait :colors => {
15
+ :error => "#FF0000",
16
+ :info => "#00FF00",
17
+ :warn => "#EAA61E",
18
+ :debug => "#FFFFFF"
19
+ }
20
+
21
+ def initialize
22
+ super(class_trait[:lines])
23
+
24
+ self.font = "-*-*-*-*-*-*-24-*-*-*-*-*-*-*"
25
+ self.align = 'center'
26
+ self.color = '#FFFFFF'
27
+ self.valign = 'top'
28
+ self.timeout = class_trait[:timeout]
29
+ self.outline_color = "#000000"
30
+ self.outline_width = 1
31
+ self.vertical_offset = 20
32
+ end
33
+
34
+ def inform(tag, *args)
35
+ self.color = class_trait[:colors][tag.to_sym]
36
+
37
+ args.each_with_index do |arg, i|
38
+ display(arg, i)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,9 @@
1
1
  # Copyright (c) 2006 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 'ramaze/snippets/kernel/aquire'
5
- aquire 'ramaze/snippets/*'
4
+ dir = File.join(File.expand_path(File.dirname(__FILE__)), 'snippets')
5
+ glob = File.join(dir, '**', '*.rb')
6
+
7
+ Dir[glob].each do |snippet|
8
+ require(snippet)
9
+ end
@@ -54,7 +54,19 @@ class Object
54
54
  # {:three=>:drei, :two=>:zwei, :one=>:eins, :first=>:overwritten}
55
55
 
56
56
  def ancestral_trait
57
- ancs = (ancestors rescue self.class.ancestors)
57
+ if respond_to?(:ancestors)
58
+ ancs = ancestors
59
+ else
60
+ ancs = self.class.ancestors
61
+ end
58
62
  ancs.reverse.inject({}){|s,v| s.merge(v.trait)}.merge(trait)
59
63
  end
64
+
65
+ def class_trait
66
+ if respond_to?(:ancestors)
67
+ trait
68
+ else
69
+ self.class.trait
70
+ end
71
+ end
60
72
  end
@@ -5,6 +5,62 @@ require 'set'
5
5
 
6
6
  module Ramaze
7
7
 
8
+ RELOAD_ENV = {
9
+ :glob => /#{Dir.pwd}|ramaze/
10
+ }
11
+
12
+ class << self
13
+ def reload interval = 1
14
+ Inform.debug("initialize automatic file reload every #{interval} seconds")
15
+
16
+ Thread.new do
17
+ this = Thread.current
18
+ this[:task] = :autoreload
19
+
20
+ mtimes = {}
21
+
22
+ loop do
23
+ to_reload = all_reload_files.reject do |file|
24
+ mtime = File.mtime(file)
25
+ mtimes[file] ||= mtime
26
+ mtimes[file] == mtime
27
+ end
28
+
29
+ to_reload.each do |file|
30
+ sleep(interval / files.size.to_f)
31
+ Inform.debug("reload #{file}")
32
+ mtimes[file] = mtime if safe_load(file)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def all_reload_files
39
+ env = RELOAD_ENV
40
+
41
+ files, paths = $LOADED_FEATURES, $LOAD_PATH
42
+
43
+ unless env[:files] == files and env[:paths] == paths
44
+ env[:files], env[:paths] = files.dup, paths.dup
45
+ env[:map] = files.map do |file|
46
+ possible = paths.map{|pa| File.join(pa.to_s, file.to_s) }
47
+ possible.find{|po| File.exists?(po) }
48
+ end
49
+ env[:map] = env[:map].compact.sort
50
+ end
51
+
52
+ env[:map].select{|f| f =~ env[:glob] }
53
+ end
54
+
55
+ def safe_load(file)
56
+ load(file)
57
+ true
58
+ rescue Object => ex
59
+ Inform.error(ex)
60
+ false
61
+ end
62
+ end
63
+
8
64
  # this method loops through all loaded/required files
9
65
  # and re-loads them when they are updated.
10
66
  # It takes one parameter, which is the interval in seconds
@@ -13,7 +69,7 @@ module Ramaze
13
69
  # and it will just restart the autoreloader.
14
70
 
15
71
  def self.autoreload interval = 10
16
- debug "initialize autoreload with an interval of #{interval} seconds"
72
+ Inform.debug("initialize autoreload with an interval of #{interval} seconds")
17
73
 
18
74
  gatherer = Thread.new do
19
75
  this = Thread.current
@@ -54,7 +110,7 @@ module Ramaze
54
110
  current_time = File.mtime(file)
55
111
  if last_time = cache[file]
56
112
  unless last_time == current_time
57
- Ramaze::Informer.info "autoreload #{file}"
113
+ Inform.info("autoreload #{file}")
58
114
  load(file)
59
115
  cache[file] = current_time
60
116
  end
@@ -0,0 +1,27 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ class String
5
+
6
+ {
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"
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,6 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ class String
5
+ alias each each_line unless ''.respond_to?(:each)
6
+ end
@@ -0,0 +1,15 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ class Struct
5
+
6
+ # Action = Struct.new('Action', :template, :method, :params)
7
+ #
8
+ # a = Action.fill(:template => nil, :method => :meth, :params => [1])
9
+ # # => #<struct Struct::Action template=nil, method=:meth, params=[1]>
10
+
11
+ def self.fill(hash = {})
12
+ values = hash.values_at(*members.map{|m| m.to_sym})
13
+ new(*values)
14
+ end
15
+ end
@@ -39,14 +39,14 @@ module Ramaze
39
39
  # #pipeline
40
40
 
41
41
  def real_transform(controller, bound, file, action, *params)
42
- alternate, path = file_template(params.last, controller) if params.size == 1 and action == 'index'
43
- file_template, path = file_template(file, controller)
44
- ctrl_template = render_action(controller, action, *params)
42
+ file_template = file_template(file)
43
+ ctrl_template = render_action(controller, action, *params)
45
44
 
46
- if chosen = alternate || file_template || ctrl_template
47
- pipeline(chosen, :binding => bound, :path => path)
45
+ if ctrl_template.respond_to?(:exception) and not file_template
46
+ raise ctrl_template
48
47
  else
49
- raise_no_action(controller, action)
48
+ template = file_template || ctrl_template
49
+ pipeline(template, :binding => bound, :path => file)
50
50
  end
51
51
  end
52
52
 
@@ -54,27 +54,18 @@ module Ramaze
54
54
  #
55
55
  # Answers with the contents and otherwise nil
56
56
 
57
- def file_template action_or_file, controller
58
- path =
59
- if File.file?(action_or_file)
60
- action_or_file
61
- else
62
- Controller.find_template(action_or_file, controller)
63
- end
64
-
65
- return File.read(path), path
66
- rescue
67
- nil
57
+ def file_template file
58
+ return File.read(file) if file
59
+ rescue Errno::ENOENT => ex
60
+ Inform.error(ex)
68
61
  end
69
62
 
70
63
  # Render an action, on a given controller with parameter
71
64
 
72
65
  def render_action(controller, action, *params)
73
- return controller.send(action, *params).to_s
74
- rescue NoMethodError => ex
75
- ourself = /undefined method `#{action}' for #<TCErrorController:/
76
- raise_no_action(controller, action) unless ex.message =~ ourself
77
- nil
66
+ controller.__send__(action, *params).to_s unless action.empty?
67
+ rescue => ex
68
+ ex
78
69
  end
79
70
 
80
71
  def raise_no_action(controller, action)