ramaze 0.0.8 → 0.0.9

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 (49) hide show
  1. data/Rakefile +42 -0
  2. data/doc/allison/LICENSE +184 -0
  3. data/doc/allison/README +37 -0
  4. data/doc/allison/allison.css +300 -0
  5. data/doc/allison/allison.gif +0 -0
  6. data/doc/allison/allison.js +307 -0
  7. data/doc/allison/allison.rb +287 -0
  8. data/doc/allison/cache/BODY +588 -0
  9. data/doc/allison/cache/CLASS_INDEX +4 -0
  10. data/doc/allison/cache/CLASS_PAGE +1 -0
  11. data/doc/allison/cache/FILE_INDEX +4 -0
  12. data/doc/allison/cache/FILE_PAGE +1 -0
  13. data/doc/allison/cache/FONTS +1 -0
  14. data/doc/allison/cache/FR_INDEX_BODY +1 -0
  15. data/doc/allison/cache/IMGPATH +1 -0
  16. data/doc/allison/cache/INDEX +1 -0
  17. data/doc/allison/cache/JAVASCRIPT +307 -0
  18. data/doc/allison/cache/METHOD_INDEX +4 -0
  19. data/doc/allison/cache/METHOD_LIST +1 -0
  20. data/doc/allison/cache/SRC_PAGE +1 -0
  21. data/doc/allison/cache/STYLE +322 -0
  22. data/doc/allison/cache/URL +1 -0
  23. data/doc/readme_chunks/principles.txt +33 -18
  24. data/doc/tutorial/todolist.html +599 -0
  25. data/doc/tutorial/todolist.txt +230 -230
  26. data/examples/identity.rb +21 -0
  27. data/examples/nitro_form.rb +22 -0
  28. data/lib/ramaze/controller.rb +1 -1
  29. data/lib/ramaze/dispatcher.rb +10 -4
  30. data/lib/ramaze/helper/{openid.rb → identity.rb} +15 -6
  31. data/lib/ramaze/helper/nitroform.rb +10 -0
  32. data/lib/ramaze/helper/stack.rb +1 -1
  33. data/lib/ramaze/inform.rb +18 -8
  34. data/lib/ramaze/snippets/kernel/aquire.rb +3 -3
  35. data/lib/ramaze/snippets/object/traits.rb +1 -1
  36. data/lib/ramaze/snippets/ramaze/caller_info.rb +17 -1
  37. data/lib/ramaze/snippets/ramaze/caller_lines.rb +1 -1
  38. data/lib/ramaze/store/yaml.rb +10 -1
  39. data/lib/ramaze/template/ezamar.rb +10 -5
  40. data/lib/ramaze/trinity/request.rb +12 -2
  41. data/lib/ramaze/version.rb +1 -1
  42. data/lib/ramaze.rb +5 -3
  43. data/spec/public/error404.xhtml +1 -0
  44. data/spec/spec_all.rb +21 -19
  45. data/spec/spec_helper.rb +1 -1
  46. data/spec/tc_error.rb +18 -4
  47. data/spec/tc_helper_cache.rb +1 -1
  48. data/spec/tc_helper_flash.rb +1 -2
  49. metadata +32 -4
@@ -0,0 +1,21 @@
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 'ramaze'
5
+
6
+ class MainController < Ramaze::Controller
7
+ helper :identity
8
+
9
+ def index
10
+ if session[:openid_identity]
11
+ %{
12
+ <h1>#{flash[:success]}</h1>
13
+ <p>You are logged in as #{session[:openid_identity]}</p>
14
+ }
15
+ else
16
+ openid_login_form
17
+ end
18
+ end
19
+ end
20
+
21
+ Ramaze.start
@@ -0,0 +1,22 @@
1
+ require 'ramaze'
2
+
3
+ gem 'facets', '=1.4.5'
4
+ require '/home/manveru/prog/projects/nitroproject/glycerin'
5
+ require 'nitro'
6
+ require 'og'
7
+
8
+ class Article
9
+ attr_accessor :title, String
10
+ end
11
+
12
+ Og.setup :store => :sqlite, :destroy => true
13
+
14
+ class MainController < Ramaze::Controller
15
+ helper :nitroform
16
+
17
+ def index
18
+ form(Article.new).to_s
19
+ end
20
+ end
21
+
22
+ Ramaze.start
@@ -273,7 +273,7 @@ module Ramaze
273
273
  end
274
274
 
275
275
  backtrace.map! do |line|
276
- file, lineno, meth = *Ramaze.caller_info
276
+ file, lineno, meth = *Ramaze.parse_backtrace(line)
277
277
  backtrace_size = Ramaze::Global.inform_backtrace_size
278
278
  lines = Ramaze.caller_lines(file, lineno, backtrace_size)
279
279
 
@@ -57,6 +57,8 @@ module Ramaze
57
57
  # This feature is only available if your Global.error is true, which is
58
58
  # the default.
59
59
  #
60
+ #--
61
+ #
60
62
  # Yes, again, webrick _has_ to be really obscure, I searched for half an hour
61
63
  # and still have not the faintest idea how request_path is related to
62
64
  # request_uri...
@@ -74,8 +76,12 @@ module Ramaze
74
76
  error_path = handle_error[exception.class]
75
77
  error_path ||= handle_error.find{|k,v| k === exception}.last
76
78
 
77
- request.path_info = error_path
78
- respond
79
+ if exception.message =~ /`#{error_path.split('/').last}'/
80
+ build_response(exception.message, STATUS_CODE[:internal_server_error])
81
+ else
82
+ request.path_info = error_path
83
+ respond
84
+ end
79
85
  else
80
86
  if Global.error_page
81
87
  request.path_info = '/error'
@@ -85,7 +91,7 @@ module Ramaze
85
91
  end
86
92
  end
87
93
 
88
- respond
94
+ response
89
95
  rescue Object => ex
90
96
  Informer.error ex
91
97
  build_response(ex.message, STATUS_CODE[:internal_server_error])
@@ -145,7 +151,7 @@ module Ramaze
145
151
  if file
146
152
  response['Content-Type'] = Tool::MIME.type_for(file)
147
153
  Informer.debug("Serving static: #{file}")
148
- File.open(file)
154
+ File.open(file, 'rb')
149
155
  end
150
156
  end
151
157
 
@@ -2,11 +2,17 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  require 'tmpdir'
5
-
6
5
  require 'openid'
7
6
 
8
7
  module Ramaze
9
- module OpenidHelper
8
+
9
+ # This is called Identity to avoid collisions with the original openid.rb
10
+
11
+ module IdentityHelper
12
+ def self.included(klass)
13
+ klass.send(:helper, :flash)
14
+ end
15
+
10
16
  def openid_login_form
11
17
  %{
12
18
  <form method="GET" action="#{R(self, :openid_begin)}">
@@ -19,7 +25,7 @@ module Ramaze
19
25
  def openid_begin
20
26
  url = request['url']
21
27
  redirect_referrer if url.nil? or url.empty?
22
- session[:openid_entry] = referrer
28
+ session[:openid_entry] = request.referrer
23
29
 
24
30
  openid_request = openid_consumer.begin(url)
25
31
  case openid_request.status
@@ -28,8 +34,7 @@ module Ramaze
28
34
 
29
35
  redirect_referrer
30
36
  when OpenID::SUCCESS
31
- host, port = Ramaze::Global.host, Ramaze::Global.port
32
- root = "http://#{host}:#{port}/"
37
+ root = "http://#{request.http_host}/"
33
38
  return_to = root[0..-2] + R(self, :openid_complete)
34
39
  redirect_url = openid_request.redirect_url(root, return_to)
35
40
 
@@ -44,9 +49,12 @@ module Ramaze
44
49
  when OpenID::FAILURE
45
50
  flash[:error] = 'OpenID - Verification failed.'
46
51
  when OpenID::SUCCESS
52
+ session[:openid_identity] = openid_response.identity_url
47
53
  flash[:success] = 'OpenID - Verification done.'
48
54
  end
49
55
 
56
+ session.delete(:_openid_consumer_service)
57
+
50
58
  redirect session[:openid_entry]
51
59
  end
52
60
 
@@ -58,6 +66,7 @@ module Ramaze
58
66
  end
59
67
  end
60
68
 
69
+
61
70
  openid_store_file = File.join(Dir.tmpdir, 'openid-store')
62
71
 
63
- Global.openid_store ||= OpenID::FilesystemStore.new(openid_store_file)
72
+ Ramaze::Global.openid_store ||= OpenID::FilesystemStore.new(openid_store_file)
@@ -0,0 +1,10 @@
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 'nitro/helper/form'
5
+
6
+ module Ramaze
7
+ module NitroformHelper
8
+ include ::Nitro::FormHelper
9
+ end
10
+ end
@@ -46,7 +46,7 @@ module Ramaze
46
46
  # on the session[:STACK]
47
47
 
48
48
  def call this
49
- (session[:STACK] ||= []) << request.request_uri
49
+ (session[:STACK] ||= []) << request.fullpath
50
50
  redirect(R(this))
51
51
  end
52
52
 
data/lib/ramaze/inform.rb CHANGED
@@ -140,14 +140,24 @@ module Ramaze
140
140
  def log prefix, *messages
141
141
  [messages].flatten.each do |message|
142
142
  compiled = %{[#{timestamp}] #{prefix} #{message}}
143
- out =
144
- case Global.inform_to
145
- when $stdout, :stderr, 'stdout' : $stdout
146
- when $stdout, :stderr, 'stderr' : $stderr
147
- else
148
- File.open(Global.inform_to, 'ab+')
149
- end
150
- out.puts(*compiled) unless (out.respond_to?(:closed?) and out.closed?)
143
+
144
+ pipes = Global.inform_pipes = pipify(Global.inform_to)
145
+
146
+ pipes.each do |pipe|
147
+ pipe.puts(*compiled) unless (pipe.respond_to?(:closed?) and pipe.closed?)
148
+ end
149
+ end
150
+ end
151
+
152
+ def pipify *ios
153
+ ios.flatten.map do |io|
154
+ case io
155
+ when :stdout, 'stdout' : $stdout
156
+ when :stderr, 'stderr' : $stderr
157
+ when IO : io
158
+ else
159
+ File.open(io.to_s, 'ab+')
160
+ end
151
161
  end
152
162
  end
153
163
 
@@ -12,9 +12,9 @@ module Kernel
12
12
  def aquire *files
13
13
  files.each do |file|
14
14
  require file if %w(rb so).any?{|f| File.file?("#{file}.#{f}")}
15
- $:.each do |path|
16
- Dir[File.join(path, file, '*.rb')].each do |file|
17
- require file unless file == File.expand_path(__FILE__)
15
+ $:.each do |dir|
16
+ Dir[File.join(dir, file, '*.rb')].each do |path|
17
+ require path unless path == File.expand_path(__FILE__)
18
18
  end
19
19
  end
20
20
  end
@@ -1,7 +1,7 @@
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
- Traits = Hash.new{|h,k| h[k] = {}}
4
+ Traits = Hash.new{|h,k| h[k] = {}} unless defined?(Traits)
5
5
 
6
6
  class Object
7
7
 
@@ -9,6 +9,22 @@ module Ramaze
9
9
  # # => ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']
10
10
 
11
11
  def self.caller_info(i = 1)
12
- file, line, meth = caller[i].scan(/(.*?):(\d+):in `(.*?)'/).first
12
+ file, line, meth = *parse_backtrace(caller[i])
13
+ end
14
+
15
+ # Parses one line of backtrace and tries to extract as much information
16
+ # as possible.
17
+ #
18
+ # Example:
19
+ # line = "/web/repo/ramaze/lib/ramaze/dispatcher.rb:105:in `respond'"
20
+ # Ramaze.parse_backtrace(line)
21
+ # #=> ["/web/repo/ramaze/lib/ramaze/dispatcher.rb", "105", "respond"]
22
+
23
+ def self.parse_backtrace(line = '')
24
+ full = line.scan(/(.*?):(\d+):in `(.*?)'/).first
25
+ return full if full and full.all?
26
+ partial = line.scan(/(.*?):(\d+)/).first
27
+ return partial if partial and partial.all?
28
+ line
13
29
  end
14
30
  end
@@ -28,7 +28,7 @@ module Ramaze
28
28
 
29
29
  def self.caller_lines(file, line, size = 4)
30
30
  return [[0, file, true]] if file == '(eval)'
31
- lines = File.readlines(file)
31
+ lines = File.readlines(File.expand_path(file)) rescue []
32
32
  current = line.to_i - 1
33
33
 
34
34
  first = current - size
@@ -119,7 +119,16 @@ module Ramaze::Store
119
119
 
120
120
  def new
121
121
  entity = Entity.new
122
- entity.instance_variable_set('@manager', self)
122
+ entity.manager = self
123
+ entity
124
+ end
125
+
126
+ def create_with hash = {}
127
+ entity = new
128
+ hash.each do |key, value|
129
+ entity.send("#{key}=", value)
130
+ end
131
+ entity.save
123
132
  entity
124
133
  end
125
134
 
@@ -43,10 +43,10 @@ module Ramaze
43
43
  file_template, path = file_template(file, controller)
44
44
  ctrl_template = render_action(controller, action, *params)
45
45
 
46
- if chosen = to_transform = alternate || file_template || ctrl_template
46
+ if chosen = alternate || file_template || ctrl_template
47
47
  pipeline(chosen, :binding => bound, :path => path)
48
48
  else
49
- raise Ramaze::Error::NoAction, "No Action found for `#{action}' on #{controller.class}"
49
+ raise_no_action(controller, action)
50
50
  end
51
51
  end
52
52
 
@@ -70,12 +70,17 @@ module Ramaze
70
70
  # Render an action, on a given controller with parameter
71
71
 
72
72
  def render_action(controller, action, *params)
73
- ctrl_template = controller.send(action, *params).to_s
74
- rescue => ex
75
- Informer.error(ex)
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
76
77
  nil
77
78
  end
78
79
 
80
+ def raise_no_action(controller, action)
81
+ raise Ramaze::Error::NoAction, "No Action found for `#{action}' on #{controller.class}"
82
+ end
83
+
79
84
  # go through the pipeline and call #transform on every object found there,
80
85
  # passing the template at that point.
81
86
  # the order and contents of the pipeline are determined by an array
@@ -50,11 +50,21 @@ module Ramaze
50
50
  # the referer of the client or '/'
51
51
 
52
52
  def referer
53
- @request.env['HTTP_REFERER'] || '/'
53
+ env['HTTP_REFERER'] || '/'
54
54
  end
55
55
 
56
56
  alias referrer referer
57
57
 
58
+ def fullpath
59
+ path = script_name + path_info
60
+ path << "?" << query_string unless query_string.empty?
61
+ path
62
+ end
63
+
64
+ def env
65
+ @request.env
66
+ end
67
+
58
68
  # you can access the original @request via this method_missing,
59
69
  # first it tries to match your method with any of the HTTP parameters
60
70
  # then, in case that fails, it will relay to @request
@@ -62,7 +72,7 @@ module Ramaze
62
72
  def method_missing meth, *args, &block
63
73
  @request.send(meth, *args, &block)
64
74
  rescue
65
- @request.env[meth.to_s.upcase]
75
+ env[meth.to_s.upcase]
66
76
  end
67
77
  end
68
78
  end
@@ -5,7 +5,7 @@ module Ramaze #:nodoc:
5
5
  module Version #:nodoc:
6
6
  MAJOR = 0
7
7
  MINOR = 0
8
- TINY = 8
8
+ TINY = 9
9
9
 
10
10
  STRING = [MAJOR, MINOR, TINY].join('.')
11
11
  end
data/lib/ramaze.rb CHANGED
@@ -138,9 +138,11 @@ module Ramaze
138
138
  # closes the IO that Global.inform_to points to.
139
139
 
140
140
  def close_inform
141
- if to = Global.inform_to and to.respond_to?(:close)
142
- debug "close #{to.inspect}"
143
- to.close until to.closed?
141
+ [Global.inform_to].flatten.each do |io|
142
+ if io = Global.inform_to and io.respond_to?(:close)
143
+ debug "close #{io.inspect}"
144
+ io.close until io.closed?
145
+ end
144
146
  end
145
147
  end
146
148
 
@@ -0,0 +1 @@
1
+ 404 - not found
data/spec/spec_all.rb CHANGED
@@ -3,6 +3,11 @@
3
3
 
4
4
  require 'pp'
5
5
 
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ end
10
+
6
11
  begin
7
12
  require 'systemu'
8
13
  rescue LoadError
@@ -17,25 +22,16 @@ rescue LoadError
17
22
  end
18
23
  end
19
24
 
20
- begin
21
- require 'term/ansicolor'
22
- class String
23
- include Term::ANSIColor
24
- end
25
- rescue LoadError
26
- puts "Please install term-ansicolor for better-looking results"
27
-
28
- class String
29
-
30
- # this will be set in case term/ansicolor cannot be
31
- # required, just makes colorless output
32
-
33
- def red() self end
34
-
35
- # this will be set in case term/ansicolor cannot be
36
- # required, just makes colorless output
25
+ class String
37
26
 
38
- def green() self end
27
+ {
28
+ :red => 31,
29
+ :green => 32,
30
+ :yellow => 33,
31
+ }.each do |key, value|
32
+ define_method key do
33
+ "\e[#{value}m" + self + "\e[0m"
34
+ end
39
35
  end
40
36
  end
41
37
 
@@ -68,8 +64,10 @@ specs.each do |spec|
68
64
  print result_format['failed'].red
69
65
 
70
66
  else
67
+ found = false
71
68
  stdout.each do |line|
72
69
  if line =~ /(\d+) specifications?, (\d+) failures?/
70
+ found = true
73
71
  s, f = $1.to_i, $2.to_i
74
72
  ss, sf = s.to_s.rjust(3), f.to_s.rjust(3)
75
73
 
@@ -80,12 +78,16 @@ specs.each do |spec|
80
78
 
81
79
  if f.nonzero?
82
80
  failed[spec] = hash
83
- print((message << "#{f} failed ]").red)
81
+ print((message << "#{sf} failed ]").red)
84
82
  else
85
83
  print((message << "all passed ]").green)
86
84
  end
87
85
  end
88
86
  end
87
+
88
+ unless found
89
+ print("[ please test standalone ]".red)
90
+ end
89
91
  end
90
92
  puts
91
93
  end