ramaze 0.0.9 → 0.1.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.
- data/Rakefile +14 -259
- data/bin/ramaze +52 -25
- data/doc/AUTHORS +6 -0
- data/doc/CHANGELOG +1363 -42
- data/doc/INSTALL +1 -1
- data/doc/README +48 -35
- data/doc/README.html +637 -0
- data/doc/TODO +7 -16
- data/doc/allison/allison.css +6 -7
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/cache/STYLE +1 -2
- data/doc/changes.txt +3375 -0
- data/doc/changes.xml +3378 -0
- data/doc/meta/announcement.txt +47 -0
- data/doc/meta/configuration.txt +179 -0
- data/doc/meta/internals.txt +111 -0
- data/doc/readme_chunks/features.txt +8 -16
- data/doc/readme_chunks/installing.txt +7 -1
- data/doc/tutorial/todolist.txt +2 -3
- data/examples/blog/main.rb +9 -8
- data/examples/blog/public/styles/blog.css +132 -0
- data/examples/blog/src/controller.rb +14 -41
- data/examples/blog/src/model.rb +12 -13
- data/examples/blog/src/view.rb +16 -0
- data/examples/blog/template/edit.xhtml +19 -8
- data/examples/blog/template/index.xhtml +14 -22
- data/examples/blog/template/new.xhtml +18 -5
- data/examples/caching.rb +5 -8
- data/examples/element.rb +3 -3
- data/examples/hello.rb +3 -5
- data/examples/simple.rb +4 -7
- data/examples/templates/template/external.haml +8 -7
- data/examples/templates/template/external.mab +11 -8
- data/examples/templates/template_amrita2.rb +4 -4
- data/examples/templates/template_erubis.rb +3 -3
- data/examples/templates/template_ezamar.rb +1 -2
- data/examples/templates/template_haml.rb +24 -23
- data/examples/templates/template_liquid.rb +3 -1
- data/examples/templates/template_markaby.rb +15 -9
- data/examples/todolist/src/element/page.rb +1 -1
- data/lib/proto/conf/benchmark.yaml +6 -20
- data/lib/proto/conf/debug.yaml +6 -19
- data/lib/proto/conf/live.yaml +7 -19
- data/lib/proto/conf/silent.yaml +6 -16
- data/lib/proto/conf/stage.yaml +6 -18
- data/lib/proto/public/error.zmr +2 -2
- data/lib/ramaze.rb +34 -72
- data/lib/ramaze/adapter.rb +21 -18
- data/lib/ramaze/adapter/mongrel.rb +0 -3
- data/lib/ramaze/adapter/webrick.rb +6 -6
- data/lib/ramaze/cache/memcached.rb +3 -0
- data/lib/ramaze/controller.rb +227 -183
- data/lib/ramaze/dispatcher.rb +34 -129
- data/lib/ramaze/dispatcher/action.rb +28 -0
- data/lib/ramaze/dispatcher/error.rb +43 -0
- data/lib/ramaze/dispatcher/file.rb +34 -0
- data/lib/ramaze/global.rb +89 -48
- data/lib/ramaze/helper/aspect.rb +8 -6
- data/lib/ramaze/helper/auth.rb +3 -3
- data/lib/ramaze/helper/cache.rb +2 -2
- data/lib/ramaze/helper/file.rb +14 -0
- data/lib/ramaze/helper/inform.rb +36 -0
- data/lib/ramaze/helper/link.rb +7 -3
- data/lib/ramaze/helper/markaby.rb +30 -0
- data/lib/ramaze/helper/redirect.rb +2 -0
- data/lib/ramaze/inform.rb +8 -182
- data/lib/ramaze/inform/analogger.rb +19 -0
- data/lib/ramaze/inform/growl.rb +28 -0
- data/lib/ramaze/inform/hub.rb +26 -0
- data/lib/ramaze/inform/informer.rb +92 -0
- data/lib/ramaze/inform/informing.rb +44 -0
- data/lib/ramaze/inform/syslog.rb +27 -0
- data/lib/ramaze/inform/xosd.rb +42 -0
- data/lib/ramaze/snippets.rb +6 -2
- data/lib/ramaze/snippets/object/traits.rb +13 -1
- data/lib/ramaze/snippets/ramaze/autoreload.rb +58 -2
- data/lib/ramaze/snippets/string/color.rb +27 -0
- data/lib/ramaze/snippets/string/each.rb +6 -0
- data/lib/ramaze/snippets/struct/fill.rb +15 -0
- data/lib/ramaze/template/ezamar.rb +13 -22
- data/lib/ramaze/template/ezamar/element.rb +12 -12
- data/lib/ramaze/template/liquid.rb +19 -18
- data/lib/ramaze/template/markaby.rb +37 -58
- data/lib/ramaze/tool/localize.rb +128 -0
- data/lib/ramaze/tool/tidy.rb +51 -21
- data/lib/ramaze/trinity.rb +3 -3
- data/lib/ramaze/trinity/request.rb +41 -23
- data/lib/ramaze/trinity/response.rb +10 -5
- data/lib/ramaze/trinity/session.rb +17 -3
- data/lib/ramaze/version.rb +2 -2
- data/rake_tasks/conf.rake +56 -0
- data/rake_tasks/gem.rake +44 -0
- data/rake_tasks/maintaince.rake +187 -0
- data/spec/all.rb +32 -0
- data/spec/examples/caching.rb +19 -0
- data/spec/examples/element.rb +15 -0
- data/spec/examples/hello.rb +11 -0
- data/spec/examples/simple.rb +51 -0
- data/spec/examples/templates/template_amrita2.rb +14 -0
- data/spec/examples/templates/template_erubis.rb +21 -0
- data/spec/examples/templates/template_ezamar.rb +22 -0
- data/spec/examples/templates/template_haml.rb +23 -0
- data/spec/examples/templates/template_liquid.rb +24 -0
- data/spec/examples/templates/template_markaby.rb +21 -0
- data/spec/helper.rb +81 -0
- data/spec/{spec_helper_context.rb → helper/context.rb} +1 -1
- data/spec/helper/layout.rb +55 -0
- data/spec/helper/mock_http.rb +66 -0
- data/spec/{spec_helper_requester.rb → helper/requester.rb} +0 -6
- data/spec/{spec_helper_simple_http.rb → helper/simple_http.rb} +57 -57
- data/spec/helper/wrap.rb +193 -0
- data/spec/{adapter_spec.rb → ramaze/adapter.rb} +7 -5
- data/spec/{tc_adapter_mongrel.rb → ramaze/adapter/mongrel.rb} +2 -2
- data/spec/{tc_adapter_webrick.rb → ramaze/adapter/webrick.rb} +2 -2
- data/spec/{tc_cache.rb → ramaze/cache.rb} +16 -16
- data/spec/ramaze/conf/locale_de.yaml +6 -0
- data/spec/ramaze/conf/locale_en.yaml +6 -0
- data/spec/ramaze/controller.rb +184 -0
- data/spec/ramaze/controller/template/greet.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +54 -0
- data/spec/ramaze/dependencies.rb +16 -0
- data/spec/{tc_element.rb → ramaze/element.rb} +21 -19
- data/spec/ramaze/error.rb +64 -0
- data/spec/{tc_gestalt.rb → ramaze/gestalt.rb} +10 -10
- data/spec/{tc_global.rb → ramaze/global.rb} +7 -7
- data/spec/{tc_helper_aspect.rb → ramaze/helper/aspect.rb} +22 -14
- data/spec/{tc_helper_auth.rb → ramaze/helper/auth.rb} +9 -7
- data/spec/{tc_helper_cache.rb → ramaze/helper/cache.rb} +14 -24
- data/spec/{tc_helper_feed.rb → ramaze/helper/feed.rb} +12 -12
- data/spec/ramaze/helper/file.rb +17 -0
- data/spec/{tc_helper_flash.rb → ramaze/helper/flash.rb} +16 -17
- data/spec/{tc_helper_form.rb → ramaze/helper/form.rb} +25 -26
- data/spec/{tc_helper_link.rb → ramaze/helper/link.rb} +9 -9
- data/spec/{tc_helper_redirect.rb → ramaze/helper/redirect.rb} +11 -10
- data/spec/{tc_helper_stack.rb → ramaze/helper/stack.rb} +10 -11
- data/spec/ramaze/inform/informer.rb +40 -0
- data/spec/ramaze/inform/syslog.rb +10 -0
- data/spec/ramaze/localize.rb +40 -0
- data/spec/ramaze/morpher.rb +82 -0
- data/spec/ramaze/params.rb +124 -0
- data/spec/{public → ramaze/public}/error404.xhtml +0 -0
- data/spec/{public → ramaze/public}/favicon.ico +0 -0
- data/spec/{public → ramaze/public}/ramaze.png +0 -0
- data/spec/{public → ramaze/public}/test_download.css +0 -0
- data/spec/ramaze/request.rb +129 -0
- data/spec/{tc_request_mongrel.rb → ramaze/request/mongrel.rb} +2 -2
- data/spec/{tc_request_webrick.rb → ramaze/request/webrick.rb} +1 -1
- data/spec/{tc_session.rb → ramaze/session.rb} +18 -18
- data/spec/{tc_store.rb → ramaze/store/default.rb} +10 -10
- data/spec/{tc_store_yaml.rb → ramaze/store/yaml.rb} +9 -9
- data/spec/ramaze/template.rb +86 -0
- data/spec/{tc_template_amrita2.rb → ramaze/template/amrita2.rb} +5 -5
- data/spec/{template → ramaze/template}/amrita2/data.amrita +0 -0
- data/spec/{template → ramaze/template}/amrita2/index.amrita +0 -0
- data/spec/{template → ramaze/template}/amrita2/sum.amrita +0 -0
- data/spec/{tc_template_erubis.rb → ramaze/template/erubis.rb} +9 -9
- data/spec/{template → ramaze/template}/erubis/sum.rhtml +0 -0
- data/spec/ramaze/template/ezamar.rb +62 -0
- data/spec/{template → ramaze/template}/ezamar/another/long/action.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/combined.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/file_only.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/index.zmr +0 -0
- data/spec/ramaze/template/ezamar/nested.zmr +1 -0
- data/spec/{template → ramaze/template}/ezamar/some__long__action.zmr +0 -0
- data/spec/{template → ramaze/template}/ezamar/sum.zmr +0 -0
- data/spec/{tc_template_haml.rb → ramaze/template/haml.rb} +7 -7
- data/spec/{template → ramaze/template}/haml/index.haml +0 -0
- data/spec/{template → ramaze/template}/haml/with_vars.haml +0 -0
- data/spec/{tc_template_liquid.rb → ramaze/template/liquid.rb} +7 -7
- data/spec/{template → ramaze/template}/liquid/index.liquid +0 -0
- data/spec/{template → ramaze/template}/liquid/products.liquid +0 -0
- data/spec/ramaze/template/markaby.rb +59 -0
- data/spec/{template → ramaze/template}/markaby/external.mab +0 -0
- data/spec/{template → ramaze/template}/markaby/sum.mab +0 -0
- data/spec/ramaze/template/ramaze/external.test +1 -0
- data/spec/{tc_tidy.rb → ramaze/tidy.rb} +3 -3
- metadata +145 -81
- data/examples/blog/public/screen.css +0 -106
- data/examples/blog/src/element.rb +0 -58
- data/examples/blog/template/view.xhtml +0 -15
- data/examples/blog/test/tc_entry.rb +0 -18
- data/lib/proto/public/404.jpg +0 -0
- data/spec/request_tc_helper.rb +0 -135
- data/spec/spec_all.rb +0 -118
- data/spec/spec_helper.rb +0 -66
- data/spec/tc_controller.rb +0 -49
- data/spec/tc_dependencies.rb +0 -13
- data/spec/tc_error.rb +0 -43
- data/spec/tc_morpher.rb +0 -88
- data/spec/tc_params.rb +0 -125
- data/spec/tc_template_ezamar.rb +0 -64
- data/spec/tc_template_markaby.rb +0 -72
- 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
|
data/lib/ramaze/snippets.rb
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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,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
|
-
|
|
43
|
-
|
|
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
|
|
47
|
-
|
|
45
|
+
if ctrl_template.respond_to?(:exception) and not file_template
|
|
46
|
+
raise ctrl_template
|
|
48
47
|
else
|
|
49
|
-
|
|
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
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
74
|
-
rescue
|
|
75
|
-
|
|
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)
|