ramaze 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/Rakefile +1 -1
  2. data/doc/AUTHORS +2 -0
  3. data/doc/CHANGELOG +173 -0
  4. data/doc/changes.txt +4184 -0
  5. data/doc/changes.xml +4186 -0
  6. data/doc/meta/announcement.txt +22 -25
  7. data/doc/meta/internals.txt +146 -9
  8. data/examples/blog/template/index.xhtml +5 -2
  9. data/examples/fcgi.rb +13 -0
  10. data/examples/wiktacular/main.rb +8 -0
  11. data/examples/wiktacular/mkd/link/2007-07-20_19-45-51.mkd +1 -0
  12. data/examples/wiktacular/mkd/link/current.mkd +1 -0
  13. data/examples/wiktacular/mkd/main/2007-07-20_16-31-33.mkd +1 -0
  14. data/examples/wiktacular/mkd/main/2007-07-20_19-21-12.mkd +1 -0
  15. data/examples/wiktacular/mkd/main/2007-07-20_19-23-10.mkd +2 -0
  16. data/examples/wiktacular/mkd/main/2007-07-20_19-45-07.mkd +2 -0
  17. data/examples/wiktacular/mkd/main/current.mkd +2 -0
  18. data/examples/wiktacular/mkd/markdown/current.mkd +3 -0
  19. data/examples/wiktacular/mkd/testing/2007-07-20_16-43-46.mkd +2 -0
  20. data/examples/wiktacular/mkd/testing/2007-07-20_19-43-50.mkd +3 -0
  21. data/examples/wiktacular/mkd/testing/2007-07-21_18-46-01.mkd +11 -0
  22. data/examples/wiktacular/mkd/testing/2007-07-21_18-46-32.mkd +13 -0
  23. data/examples/wiktacular/mkd/testing/2007-07-21_18-47-08.mkd +17 -0
  24. data/examples/wiktacular/mkd/testing/2007-07-21_18-47-54.mkd +17 -0
  25. data/examples/wiktacular/mkd/testing/current.mkd +17 -0
  26. data/examples/wiktacular/public/favicon.ico +0 -0
  27. data/examples/wiktacular/public/screen.css +72 -0
  28. data/examples/wiktacular/src/controller.rb +44 -0
  29. data/examples/wiktacular/src/model.rb +92 -0
  30. data/examples/wiktacular/src/page.rb +66 -0
  31. data/examples/wiktacular/template/edit.xhtml +7 -0
  32. data/examples/wiktacular/template/index.xhtml +11 -0
  33. data/examples/wiktacular/template/new.xhtml +7 -0
  34. data/lib/proto/main.rb +2 -0
  35. data/lib/proto/public/error.zmr +3 -0
  36. data/lib/proto/public/js/jquery.js +1755 -1334
  37. data/lib/proto/template/index.xhtml +2 -2
  38. data/lib/ramaze.rb +8 -3
  39. data/lib/ramaze/action/render.rb +11 -0
  40. data/lib/ramaze/adapter/base.rb +11 -7
  41. data/lib/ramaze/cache.rb +25 -10
  42. data/lib/ramaze/cache/memcached.rb +16 -1
  43. data/lib/ramaze/cache/yaml_store.rb +10 -0
  44. data/lib/ramaze/controller.rb +12 -2
  45. data/lib/ramaze/controller/error.rb +9 -3
  46. data/lib/ramaze/controller/resolve.rb +20 -18
  47. data/lib/ramaze/dispatcher.rb +13 -4
  48. data/lib/ramaze/dispatcher/action.rb +7 -3
  49. data/lib/ramaze/dispatcher/error.rb +24 -2
  50. data/lib/ramaze/dispatcher/file.rb +12 -6
  51. data/lib/ramaze/global.rb +0 -3
  52. data/lib/ramaze/global/dsl.rb +9 -0
  53. data/lib/ramaze/global/globalstruct.rb +7 -1
  54. data/lib/ramaze/helper/aspect.rb +4 -2
  55. data/lib/ramaze/helper/cgi.rb +2 -2
  56. data/lib/ramaze/helper/file.rb +3 -0
  57. data/lib/ramaze/helper/link.rb +20 -0
  58. data/lib/ramaze/helper/markaby.rb +3 -0
  59. data/lib/ramaze/helper/pager.rb +10 -17
  60. data/lib/ramaze/helper/partial.rb +9 -3
  61. data/lib/ramaze/inform/analogger.rb +14 -0
  62. data/lib/ramaze/inform/growl.rb +7 -0
  63. data/lib/ramaze/inform/hub.rb +9 -0
  64. data/lib/ramaze/inform/informer.rb +9 -3
  65. data/lib/ramaze/inform/informing.rb +9 -3
  66. data/lib/ramaze/inform/knotify.rb +5 -1
  67. data/lib/ramaze/inform/syslog.rb +3 -0
  68. data/lib/ramaze/inform/xosd.rb +12 -0
  69. data/lib/ramaze/template.rb +3 -0
  70. data/lib/ramaze/template/amrita2.rb +2 -0
  71. data/lib/ramaze/template/erubis.rb +1 -0
  72. data/lib/ramaze/template/ezamar.rb +1 -0
  73. data/lib/ramaze/template/ezamar/element.rb +17 -11
  74. data/lib/ramaze/template/ezamar/engine.rb +5 -0
  75. data/lib/ramaze/template/ezamar/render_partial.rb +4 -2
  76. data/lib/ramaze/template/haml.rb +4 -0
  77. data/lib/ramaze/template/liquid.rb +4 -0
  78. data/lib/ramaze/template/markaby.rb +4 -0
  79. data/lib/ramaze/template/remarkably.rb +4 -0
  80. data/lib/ramaze/tool.rb +10 -0
  81. data/lib/ramaze/tool/localize.rb +1 -1
  82. data/lib/ramaze/trinity/session.rb +8 -1
  83. data/lib/ramaze/version.rb +1 -1
  84. data/rake_tasks/maintaince.rake +2 -2
  85. data/spec/ramaze/action/basics.rb +1 -1
  86. data/spec/ramaze/cache.rb +11 -0
  87. data/spec/ramaze/controller.rb +0 -14
  88. data/spec/ramaze/dispatcher/file.rb +5 -5
  89. data/spec/ramaze/dispatcher/public/favicon.ico +0 -0
  90. data/spec/ramaze/dispatcher/public/test_download.css +141 -0
  91. data/spec/ramaze/error.rb +21 -7
  92. data/spec/ramaze/helper/link.rb +15 -0
  93. data/spec/ramaze/helper/pager.rb +26 -3
  94. data/spec/ramaze/helper/partial.rb +2 -2
  95. metadata +43 -4
  96. data/doc/COPYING.ja +0 -51
@@ -1,9 +1,6 @@
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/tool/tidy'
5
- # require 'ramaze/tool/localize'
6
-
7
4
  module Ramaze
8
5
  module Dispatcher
9
6
  class Action
@@ -16,10 +13,17 @@ module Ramaze
16
13
  ]
17
14
 
18
15
  class << self
16
+
17
+ # Takes path, asks Controller to handle it and builds a response on
18
+ # success. The response is then passed to each member of FILTER for
19
+ # post-processing.
20
+
19
21
  def process(path)
20
22
  body = Controller.handle(path)
21
23
  response = Dispatcher.build_response(body)
22
24
  FILTER.inject(response){|r,f| f.call(r) }
25
+ rescue Ramaze::Error => ex
26
+ ex
23
27
  end
24
28
  end
25
29
  end
@@ -3,6 +3,13 @@
3
3
 
4
4
  module Ramaze
5
5
  module Dispatcher
6
+
7
+ # Last resort dispatcher, tries to recover as much information as possible
8
+ # from the past request and takes the appropiate actions.
9
+ #
10
+ # You can configure it over the HANDLE_ERROR constant or by defining error
11
+ # actions in your controllers.
12
+
6
13
  class Error
7
14
  HANDLE_ERROR = {
8
15
  Exception => [ 500, '/error' ],
@@ -13,13 +20,23 @@ module Ramaze
13
20
  class << self
14
21
  trait :last_error => nil
15
22
 
16
- def process error
23
+ def process(error, metainfo = {})
17
24
  log_error(error)
18
25
 
19
26
  Thread.current[:exception] = error
20
27
 
21
28
  key = error.class.ancestors.find{|a| HANDLE_ERROR[a]}
22
29
  status, path = *HANDLE_ERROR[key || Exception]
30
+ status ||= 500
31
+
32
+ if controller = metainfo[:controller]
33
+ begin
34
+ action = Controller.resolve(controller.mapping + path)
35
+ return Dispatcher.build_response(action.render, status)
36
+ rescue Ramaze::Error
37
+ Inform.debug("No custom error page found on #{controller}, going to #{path}")
38
+ end
39
+ end
23
40
 
24
41
  unless error.message =~ %r(`#{path.split('/').last}')
25
42
  Response.current.status = status
@@ -29,7 +46,7 @@ module Ramaze
29
46
  Dispatcher.build_response(error.message, status)
30
47
  rescue Object => ex
31
48
  Inform.error(ex)
32
- Dispatcher.build_response(ex.message, status || 500)
49
+ Dispatcher.build_response(ex.message, status)
33
50
  end
34
51
 
35
52
  def log_error error
@@ -42,6 +59,11 @@ module Ramaze
42
59
  Inform.error(error)
43
60
  end
44
61
  end
62
+
63
+ def current
64
+ Thread.current[:exception]
65
+ end
66
+
45
67
  end
46
68
  end
47
69
  end
@@ -3,22 +3,28 @@
3
3
 
4
4
  module Ramaze
5
5
  module Dispatcher
6
+
7
+ # First of the dispatchers, looks up the public path and serves the
8
+ # file if found.
9
+
6
10
  class File
7
11
  class << self
12
+
13
+ # Entry point from Dispatcher::filter.
14
+ # searches for the file and builds a response with status 200 if found.
15
+
8
16
  def process(path)
9
17
  return unless file = open_file(path)
10
18
  Dispatcher.build_response(file, Ramaze::STATUS_CODE['OK'])
11
19
  end
12
20
 
13
- def lookup_paths
14
- [ Global.public_proto, Global.public_root ].flatten
15
- end
21
+ # returns file-handle with the open file on success, setting the
22
+ # Content-Type as found in Tool::MIME
16
23
 
17
24
  def open_file(path)
18
- paths = lookup_paths.map{|pa| pa/path}
19
- file = paths.find{|way| ::File.file?(way)}
25
+ file = Global.public_root/path
20
26
 
21
- if file
27
+ if ::File.file?(file)
22
28
  response = Response.current
23
29
  response['Content-Type'] = Tool::MIME.type_for(file)
24
30
  Inform.debug("Serving static: #{file}")
data/lib/ramaze/global.rb CHANGED
@@ -53,9 +53,6 @@ module Ramaze
53
53
  o "Specify port",
54
54
  :port => 7000, :cli => 7000
55
55
 
56
- o "Specify the shadowing public directory (default in proto)",
57
- :public_proto => ( BASEDIR / 'proto' / 'public' )
58
-
59
56
  o "Specify the public directory of your application serving static files",
60
57
  :public_root => File.expand_path('./public')
61
58
 
@@ -6,12 +6,21 @@ module Ramaze
6
6
  OPTIONS = {}
7
7
  CLI_OPTIONS = []
8
8
 
9
+ # DSL for specifying Globap options before initializing Global
10
+
9
11
  module GlobalDSL
10
12
  class << self
13
+
14
+ # The method that takes the block containing the DSL, used like in
15
+ # lib/ramaze/global.rb
16
+
11
17
  def option_dsl(&block)
12
18
  instance_eval(&block)
13
19
  end
14
20
 
21
+ # Takes a doc-string and then the option as hash, another :cli key can
22
+ # be given that will expose this option via the bin/ramaze.
23
+
15
24
  def o(doc, options = {})
16
25
  cli_given = options.has_key?(:cli)
17
26
  cli = options.delete(:cli)
@@ -2,7 +2,13 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
- class GlobalStruct < Struct.new('Global', *OPTIONS.keys)
5
+ unless defined?(GlobalStruct) # prevent problems for SourceReload
6
+ class GlobalStruct < Struct.new('Global', *OPTIONS.keys)
7
+ end
8
+ end
9
+
10
+ class GlobalStruct
11
+
6
12
  ADAPTER_ALIAS = {
7
13
  :webrick => :WEBrick,
8
14
  :mongrel => :Mongrel,
@@ -60,12 +60,14 @@ module Ramaze
60
60
 
61
61
  class Action
62
62
  def before_process
63
- block = controller.ancestral_trait[:aspects][:before][method]
63
+ return unless aspects = controller.ancestral_trait[:aspects]
64
+ block = aspects[:before][method]
64
65
  instance.instance_eval(&block) if block
65
66
  end
66
67
 
67
68
  def after_process
68
- block = controller.ancestral_trait[:aspects][:after][method]
69
+ return unless aspects = controller.ancestral_trait[:aspects]
70
+ block = aspects[:after][method]
69
71
  instance.instance_eval(&block) if block
70
72
  end
71
73
  end
@@ -27,13 +27,13 @@ module Ramaze
27
27
  end
28
28
 
29
29
  # shortcut for GCI.unescapeHTML
30
-
30
+
31
31
  def html_unescape(string)
32
32
  CGI.unescapeHTML(string)
33
33
  end
34
34
 
35
35
  # one-letter versions help in case like #{h foo.inspect}
36
- # ERb/ERuby/Rails compatible
36
+ # ERb/ERuby/Rails compatible
37
37
  alias h html_escape
38
38
  alias u url_encode
39
39
 
@@ -2,6 +2,9 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
+
6
+ # Helper for quickly push out files with the proper mimetype.
7
+
5
8
  module FileHelper
6
9
  private
7
10
 
@@ -79,5 +79,25 @@ module Ramaze
79
79
  def Rs(*atoms)
80
80
  R(Controller.current, *atoms)
81
81
  end
82
+
83
+ # Give it a path with character to split at and one to join the crumbs with.
84
+ # It will generate a list of links that act as pointers to previous pages on
85
+ # this path.
86
+ #
87
+ # Example:
88
+ # breadcrumbs('/path/to/somewhere')
89
+ #
90
+ # # results in this, newlines added for readability:
91
+ #
92
+ # <a href="/path">path</a>/
93
+ # <a href="/path/to">to</a>/
94
+ # <a href="/path/to/somewhere">somewhere</a>
95
+
96
+ def breadcrumbs(path, split = '/', join = '/')
97
+ atoms = path.split(split).reject{|a| a.empty?}
98
+ crumbs = atoms.inject([]){|s,v| s << [s.last,v]}
99
+ bread = crumbs.map{|a| A(a[-1], :href=>(a*'/'))}
100
+ bread.join(join)
101
+ end
82
102
  end
83
103
  end
@@ -2,6 +2,9 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
+
6
+ # Allows you to use some shortcuts for markaby in your Controller.
7
+
5
8
  module MarkabyHelper
6
9
  private
7
10
 
@@ -111,7 +111,7 @@ class Pager
111
111
 
112
112
  # Return the index of the previous page.
113
113
 
114
- def previous_page
114
+ def prev_page
115
115
  [@page - 1, 1].max
116
116
  end
117
117
 
@@ -121,17 +121,10 @@ class Pager
121
121
  [@page + 1, @page_count].min
122
122
  end
123
123
 
124
- # A set of helpers to create links to common pages.
125
-
126
- for target in [:first, :last, :previous, :next]
127
- eval %{
128
- def link_#{target}_page
129
- target_uri(#{target}_page)
130
- end
131
- alias_method :#{target}_page_uri, :link_#{target}_page
132
- alias_method :#{target}_page_href, :link_#{target}_page
133
- }
134
- end
124
+ def link_first_page; target_uri(first_page); end
125
+ def link_last_page; target_uri(last_page); end
126
+ def link_prev_page; target_uri(prev_page); end
127
+ def link_next_page; target_uri(next_page); end
135
128
 
136
129
  # Iterator
137
130
 
@@ -208,15 +201,15 @@ class Pager
208
201
 
209
202
  unless first_page?
210
203
  nav << %{
211
- <div class="first"><a href="#{first_page_href}">First</a></div>
212
- <div class="previous"><a href="#{previous_page_href}">Previous</a></div>
204
+ <div class="first"><a href="#{link_first_page}">First</a></div>
205
+ <div class="previous"><a href="#{link_prev_page}">Previous</a></div>
213
206
  }
214
207
  end
215
208
 
216
209
  unless last_page?
217
210
  nav << %{
218
- <div class="last"><a href="#{last_page_href}">Last</a></div>
219
- <div class="next"><a href="#{next_page_href}">Next</a></div>
211
+ <div class="last"><a href="#{link_last_page}">Last</a></div>
212
+ <div class="next"><a href="#{link_next_page}">Next</a></div>
220
213
  }
221
214
  end
222
215
 
@@ -249,7 +242,7 @@ private
249
242
 
250
243
  def target_uri(page)
251
244
  params = Request.current.params.dup.update(@key => page)
252
- Rs(Controller.current.action.method, params)
245
+ Rs(Action.current.method, params)
253
246
  end
254
247
 
255
248
  end
@@ -14,15 +14,21 @@ module Ramaze
14
14
 
15
15
  def render_partial(url, options = {})
16
16
  saved = {}
17
- options.keys.each {|x| saved[x] = request.params[x] }
17
+ options.keys.each {|x| saved[x] = Request.current.params[x] }
18
+ saved_action = Thread.current[:action]
18
19
 
19
- request.params.update(options)
20
+ Request.current.params.update(options)
20
21
 
21
22
  Controller.handle(url)
22
23
  ensure
23
- options.keys.each {|x| request.params[x] = saved[x] }
24
+ Thread.current[:action] = saved_action
25
+ options.keys.each {|x| Request.current.params[x] = saved[x] }
24
26
  end
25
27
 
28
+ # Generate from a filename in template_root of the given (or current)
29
+ # controller a new action.
30
+ # Any option you don't pass is instead taken from Action.current
31
+
26
32
  def render_template(file, options = {})
27
33
  current = Action.current
28
34
  options[:binding] ||= current.binding
@@ -5,17 +5,31 @@ require 'swiftcore/Analogger/Client'
5
5
 
6
6
  module Ramaze
7
7
 
8
+ # Informer for the Swiftcore Analogger logging system.
9
+ #
10
+ # You can find it at http://analogger.swiftcore.org and install with
11
+ # gem install analogger
12
+
8
13
  class Analogger < ::Swiftcore::Analogger::Client
9
14
  include Informing
10
15
 
16
+ # identifier for your application
11
17
  trait :name => 'walrus'
18
+
19
+ # Host analogger runs on
12
20
  trait :host => '127.0.0.1'
21
+
22
+ # Port analogger runs on
13
23
  trait :port => 6766
14
24
 
25
+ # Create a new instance, parameters default to the traits.
26
+
15
27
  def initialize(name = class_trait[:name], host = class_trait[:host], port = class_trait[:port])
16
28
  super
17
29
  end
18
30
 
31
+ # integration to Informing
32
+
19
33
  def inform(tag, *args)
20
34
  log(tag, args.join("\n"))
21
35
  end
@@ -4,6 +4,9 @@
4
4
  require 'ruby-growl'
5
5
 
6
6
  module Ramaze
7
+
8
+ # Informer for the growl notification system on OSX.
9
+
7
10
  class Growl < ::Growl
8
11
 
9
12
  trait :defaults => {
@@ -14,11 +17,15 @@ module Ramaze
14
17
  :default_notifies => %w[error warn info]
15
18
  }
16
19
 
20
+ # Takes the options from the default trait for merging.
21
+
17
22
  def initialize(options = {})
18
23
  options = class_trait[:defaults].merge(options).values_at(:host, :name, :all_notifies, :default_notifies, :password)
19
24
  super(*options)
20
25
  end
21
26
 
27
+ # integration to Informing
28
+
22
29
  def inform(tag, *args)
23
30
  notify(tag.to_s, Time.now.strftime("%X"), args.join("\n")[0..100])
24
31
  rescue Errno::EMSGSIZE
@@ -4,12 +4,19 @@
4
4
  require 'set'
5
5
 
6
6
  module Ramaze
7
+
8
+ # Bundles different informer instances and sends incoming messages to each.
9
+ # This is the default with Informer as only member.
10
+
7
11
  class LogHub
8
12
  include Informing
9
13
 
10
14
  attr_accessor :loggers
11
15
  attr_accessor :ignored_tags
12
16
 
17
+ # Takes a list of instances or classes (which will be initialized) and that
18
+ # are added to @loggers. All messages are then sent to each member.
19
+
13
20
  def initialize(*loggers)
14
21
  @loggers = loggers
15
22
  @ignored_tags = Set.new
@@ -21,6 +28,8 @@ module Ramaze
21
28
  @loggers.compact!
22
29
  end
23
30
 
31
+ # integration to Informing
32
+
24
33
  def inform(tag, *args)
25
34
  return if @ignored_tags.include?(tag)
26
35
  @loggers.each do |logger|
@@ -2,10 +2,14 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  module Ramaze
5
+
6
+ # A minimal logger for Ramaze, supports files, CLI, colors and some
7
+ # customization.
8
+
5
9
  class Informer
6
10
  include Informing
7
11
 
8
- attr_accessor :out, :colorize
12
+ attr_accessor :out, :colorize, :log_levels
9
13
 
10
14
  # Should Ramaze try to use colors?
11
15
  trait :colorize => true
@@ -24,7 +28,7 @@ module Ramaze
24
28
  :error => :red,
25
29
  }
26
30
 
27
- def initialize(out = $stdout)
31
+ def initialize(out = $stdout, log_levels = [:debug, :error, :info, :warn])
28
32
  @colorize = false
29
33
 
30
34
  @out =
@@ -46,6 +50,8 @@ module Ramaze
46
50
  if @out.respond_to?(:tty?) and class_trait[:colorize]
47
51
  @colorize = @out.tty?
48
52
  end
53
+
54
+ @log_levels = log_levels
49
55
  end
50
56
 
51
57
  def shutdown
@@ -56,7 +62,7 @@ module Ramaze
56
62
  end
57
63
 
58
64
  def inform tag, *messages
59
- return if closed?
65
+ return if closed? || !@log_levels.include?(tag)
60
66
  messages.flatten!
61
67
 
62
68
  prefix = tag.to_s.upcase.ljust(5)