ramaze 2010.06.18 → 2011.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/.gitignore +1 -0
  2. data/MANIFEST +9 -16
  3. data/README.md +37 -30
  4. data/Rakefile +5 -1
  5. data/TODO.md +19 -0
  6. data/doc/AUTHORS +5 -1
  7. data/doc/CHANGELOG +3553 -3272
  8. data/doc/tutorial/todolist.html +1512 -1512
  9. data/examples/app/blog/app.rb +2 -0
  10. data/examples/app/todolist/controller/init.rb +1 -2
  11. data/examples/app/wiktacular/mkd/main/2007-07-20_19-21-12.mkd +1 -1
  12. data/examples/app/wiktacular/mkd/main/2007-07-20_19-23-10.mkd +1 -1
  13. data/examples/app/wiktacular/mkd/main/2007-07-20_19-45-07.mkd +1 -1
  14. data/examples/app/wiktacular/mkd/main/current.mkd +1 -1
  15. data/examples/app/wiktacular/mkd/testing/2007-07-20_16-43-46.mkd +1 -1
  16. data/examples/app/wiktacular/mkd/testing/2007-07-20_19-43-50.mkd +2 -2
  17. data/examples/app/wiktacular/mkd/testing/2007-07-21_18-47-08.mkd +16 -16
  18. data/examples/app/wiktacular/mkd/testing/2007-07-21_18-47-54.mkd +16 -16
  19. data/examples/app/wiktacular/mkd/testing/current.mkd +16 -16
  20. data/lib/proto/model/init.rb +1 -1
  21. data/lib/proto/public/js/jquery.js +2034 -1095
  22. data/lib/proto/start.rb +2 -0
  23. data/lib/proto/view/index.xhtml +3 -3
  24. data/lib/ramaze.rb +1 -2
  25. data/lib/ramaze/cache.rb +1 -0
  26. data/lib/ramaze/cache/sequel.rb +131 -37
  27. data/lib/ramaze/controller.rb +1 -0
  28. data/lib/ramaze/gestalt.rb +75 -46
  29. data/lib/ramaze/helper.rb +1 -0
  30. data/lib/ramaze/helper/auth.rb +38 -4
  31. data/lib/ramaze/helper/blue_form.rb +498 -78
  32. data/lib/ramaze/helper/cache.rb +2 -2
  33. data/lib/ramaze/helper/csrf.rb +225 -0
  34. data/lib/ramaze/helper/erector.rb +67 -9
  35. data/lib/ramaze/helper/flash.rb +4 -2
  36. data/lib/ramaze/helper/gestalt.rb +2 -0
  37. data/lib/ramaze/helper/gravatar.rb +1 -1
  38. data/lib/ramaze/helper/localize.rb +4 -0
  39. data/lib/ramaze/helper/send_file.rb +30 -0
  40. data/lib/ramaze/helper/thread.rb +5 -0
  41. data/lib/ramaze/helper/user.rb +4 -3
  42. data/lib/ramaze/helper/xhtml.rb +87 -8
  43. data/lib/ramaze/log.rb +13 -0
  44. data/lib/ramaze/log/analogger.rb +15 -5
  45. data/lib/ramaze/log/growl.rb +28 -13
  46. data/lib/ramaze/log/hub.rb +12 -4
  47. data/lib/ramaze/log/informer.rb +28 -11
  48. data/lib/ramaze/log/knotify.rb +7 -2
  49. data/lib/ramaze/log/logger.rb +12 -4
  50. data/lib/ramaze/log/logging.rb +40 -14
  51. data/lib/ramaze/log/rotatinginformer.rb +47 -23
  52. data/lib/ramaze/log/syslog.rb +37 -31
  53. data/lib/ramaze/log/xosd.rb +7 -4
  54. data/lib/ramaze/middleware_compiler.rb +2 -2
  55. data/lib/ramaze/snippets/fiber.rb +63 -63
  56. data/lib/ramaze/snippets/ramaze/lru_hash.rb +1 -1
  57. data/lib/ramaze/tool/bin.rb +1 -1
  58. data/lib/ramaze/version.rb +1 -1
  59. data/lib/ramaze/view.rb +4 -4
  60. data/lib/ramaze/view/erector.rb +88 -13
  61. data/ramaze.gemspec +65 -65
  62. data/spec/ramaze/bin/ramaze.rb +1 -1
  63. data/spec/ramaze/cache/localmemcache.rb +20 -12
  64. data/spec/ramaze/cache/sequel.rb +19 -19
  65. data/spec/ramaze/helper/blue_form.rb +549 -257
  66. data/spec/ramaze/helper/csrf.rb +109 -0
  67. data/spec/ramaze/helper/httpdigest.rb +31 -29
  68. data/spec/ramaze/helper/user.rb +1 -1
  69. data/spec/ramaze/helper/xhtml.rb +17 -0
  70. data/spec/ramaze/log/growl.rb +34 -0
  71. data/spec/ramaze/log/informer.rb +1 -0
  72. data/spec/ramaze/view/erector.rb +49 -71
  73. data/spec/ramaze/view/erector/external_view.erector +5 -0
  74. data/spec/ramaze/view/erector/index.erector +5 -0
  75. data/spec/ramaze/view/erector/layout.erector +13 -3
  76. data/spec/ramaze/view/erector/tables.erector +23 -0
  77. data/spec/ramaze/view/erector/view.erector +6 -0
  78. data/tasks/git.rake +2 -2
  79. metadata +133 -176
  80. data/examples/helpers/form_with_sequel.rb +0 -24
  81. data/examples/helpers/nitro_form.rb +0 -23
  82. data/lib/ramaze/helper/form.rb +0 -133
  83. data/lib/ramaze/helper/nitroform.rb +0 -14
  84. data/lib/ramaze/helper/pager.rb +0 -367
  85. data/lib/ramaze/helper/partial.rb +0 -100
  86. data/lib/ramaze/helper/sequel.rb +0 -55
  87. data/lib/ramaze/helper/sequel_form.rb +0 -284
  88. data/lib/vendor/etag.rb +0 -22
  89. data/spec/ramaze/helper/form.rb +0 -360
  90. data/spec/ramaze/helper/pager.rb +0 -96
  91. data/spec/ramaze/helper/sequel_form.rb +0 -94
  92. data/spec/ramaze/view/erector/external.erector +0 -1
  93. data/spec/ramaze/view/erector/invoke_helper_method.erector +0 -1
  94. data/spec/ramaze/view/erector/strict_xhtml.erector +0 -3
  95. data/spec/ramaze/view/erector/sum.erector +0 -1
@@ -4,7 +4,7 @@ module Ramaze
4
4
  # This helper provides a convenience wrapper for handling authentication
5
5
  # and persistence of users.
6
6
  #
7
- # On every request, when you use the {User#user} method for the first time,
7
+ # On every request, when you use the {UserHelper#user} method for the first time,
8
8
  # we confirm the authentication and store the returned object in the
9
9
  # request.env, usually this will involve a request to your database.
10
10
  #
@@ -94,8 +94,8 @@ module Ramaze
94
94
  # end
95
95
  #
96
96
  # @author manveru
97
- # @todo convert the examples into real examples with specs
98
- module User
97
+ # TODO: convert the examples into real examples with specs
98
+ module UserHelper
99
99
  # Using this as key in request.env
100
100
  RAMAZE_HELPER_USER = 'ramaze.helper.user'.freeze
101
101
 
@@ -173,6 +173,7 @@ module Ramaze
173
173
  # @author manveru
174
174
  def _login(creds = _persistence)
175
175
  if @_user = _would_login?(creds)
176
+ Current.session.resid!
176
177
  self._persistence = creds
177
178
  end
178
179
  end
@@ -2,34 +2,113 @@ module Ramaze
2
2
  module Helper
3
3
 
4
4
  # Provides shortcuts to the link/script tags.
5
+ ##
6
+ # The XHTML helper can be used for generating CSS and Javascript tags.
7
+ # Generating a CSS tag can be done by calling the css() method:
8
+ #
9
+ # css 'reset', 'screen', :only => 'ie'
10
+ #
11
+ # This would result in a stylesheet named "reset.css" being loaded only when the user
12
+ # is using Internet Explorer.
13
+ #
5
14
  module XHTML
6
15
  LINK_TAG = '<link href=%p media=%p rel="stylesheet" type="text/css" />'
7
16
  SCRIPT_TAG = '<script src=%p type="text/javascript"></script>'
8
17
 
18
+ ##
19
+ # Generate a CSS tag based on the name, media type and a hash containing
20
+ # additional options. For example, if we want to load the stylesheet only when the user
21
+ # is using Internet Explorer we would have to add a key 'only' with a value of 'ie' to the hash.
22
+ #
23
+ # @param [String] name The name of the CSS file to load.
24
+ # @param [String] media The media type for which the stylesheet should be loaded.
25
+ # @param [Hash] options A hash containing additional options for the stylesheet tag.
26
+ # @example
27
+ #
28
+ # # A very basic example.
29
+ # css 'reset'
30
+ #
31
+ # # Oh shiny, IE only
32
+ # css 'reset', 'screen', :only => 'ie'
33
+ #
34
+ # @return [String] String containing the stylesheet tag.
35
+ #
9
36
  def css(name, media = 'screen', options = {})
10
- if options.empty?
11
- if name =~ /^http/ # consider it external full url
37
+ if media.respond_to?(:keys)
38
+ options = media
39
+ media = 'screen'
40
+ end
41
+
42
+ if only = options.delete(:only) and only.to_s == 'ie'
43
+ "<!--[if IE]>#{css(name, media, options)}<![endif]-->"
44
+ else
45
+ if name =~ /^http/
12
46
  LINK_TAG % [name, media]
13
47
  else
14
- LINK_TAG % ["#{Ramaze.options.prefix.chomp("/")}/css/#{name}.css", media]
48
+ prefix = options[:prefix] || 'css'
49
+ LINK_TAG % ["#{Ramaze.options.prefix.chomp("/")}/#{prefix}/#{name}.css", media]
15
50
  end
16
- elsif options[:only].to_s.downcase == 'ie'
17
- "<!--[if IE]>#{css(name, media)}<![endif]-->"
18
51
  end
19
52
  end
20
53
 
54
+ ##
55
+ # The css_for method can be used when you want to load multiple stylesheets and don't
56
+ # want to call the css() method over and over again.
57
+ #
58
+ # @example
59
+ #
60
+ # # This is pretty basic
61
+ # css_for 'reset', '960', 'style'
62
+ #
63
+ # # Loading multiple stylesheets with custom options
64
+ # css_for ['reset', 'print'], ['960', 'print']
65
+ #
66
+ # @see css()
67
+ # @param [Array] args An array containing either the names of all stylesheets to load or a collection of arrays
68
+ # of which each array defines the name, media and additional parameters.
69
+ # @return [String]
70
+ #
21
71
  def css_for(*args)
22
72
  args.map{|arg| css(*arg) }.join("\n")
23
73
  end
24
74
 
25
- def js(name)
75
+ ##
76
+ # Generates a Javascript tag that loads an external Javascript file. This tag can't be used for loading inline
77
+ # javascript files.
78
+ #
79
+ # @example
80
+ #
81
+ # # Simple isn't it?
82
+ # js 'jquery'
83
+ #
84
+ # # Let's change the directory to "some_other_directory"
85
+ # js 'jquery', :prefix => 'some_other_directory'
86
+ #
87
+ # @param [String] name The name of the Javascript file that should be loaded.
88
+ # @param [Hash] options Hash that can contain a :prefix key that defines the directory in which the JS file
89
+ # is located. By default this key is set to "js".
90
+ # @return [String]
91
+ # TODO: The js() method 2nd argument is a hash but only supports the :prefix key. Perhaps changing this hash into a string would be better - Yorick
92
+ #
93
+ def js(name, options={})
26
94
  if name =~ /^http/ # consider it external full url
27
95
  SCRIPT_TAG % name
28
96
  else
29
- SCRIPT_TAG % "#{Ramaze.options.prefix.chomp("/")}/js/#{name}.js"
97
+ SCRIPT_TAG % "#{Ramaze.options.prefix.chomp("/")}/#{options[:prefix] || 'js'}/#{name}.js"
30
98
  end
31
99
  end
32
-
100
+
101
+ ##
102
+ # Generate multiple Javascript tags using the js() method.
103
+ #
104
+ # @example
105
+ #
106
+ # # Pretty simple isn't it?
107
+ # js_for 'jquery', 'application', 'jquery.gritter'
108
+ #
109
+ # @param [Array] args Array containing the Javascript files to load.
110
+ # @return [String]
111
+ #
33
112
  def js_for(*args)
34
113
  args.map{|arg| js(*arg) }.join("\n")
35
114
  end
data/lib/ramaze/log.rb CHANGED
@@ -15,6 +15,19 @@ end
15
15
  module Ramaze
16
16
  Log = Innate::Log
17
17
 
18
+ ##
19
+ # Logger module that will autoload a certain logging helper if it's needed.
20
+ # Ramaze ships with the following logging helpers:
21
+ #
22
+ # * Analogger
23
+ # * Knotify
24
+ # * Syslog
25
+ # * Growl
26
+ # * Xosd
27
+ # * Logger
28
+ # * Informer
29
+ # * RotatingInformer
30
+ #
18
31
  module Logger
19
32
  autoload :Analogger, 'ramaze/log/analogger'
20
33
  autoload :Knotify, "ramaze/log/knotify"
@@ -5,12 +5,13 @@ require 'swiftcore/Analogger/Client'
5
5
 
6
6
  module Ramaze
7
7
  module Logger
8
-
8
+
9
+ ##
9
10
  # Informer for the Swiftcore Analogger logging system.
10
11
  #
11
12
  # You can find it at http://analogger.swiftcore.org and install with
12
13
  # gem install analogger
13
-
14
+ #
14
15
  class Analogger < ::Swiftcore::Analogger::Client
15
16
  include Logging
16
17
 
@@ -23,14 +24,23 @@ module Ramaze
23
24
  # Port analogger runs on
24
25
  trait :port => 6766
25
26
 
27
+ ##
26
28
  # Create a new instance, parameters default to the traits.
27
-
29
+ #
30
+ # @param [String] name The name of the logging system (can be anything you like).
31
+ # @param [String] host The IP/hostname on which the logging system is running.
32
+ # @param [Integer] port The port of the logging system.
33
+ #
28
34
  def initialize(name = class_trait[:name], host = class_trait[:host], port = class_trait[:port])
29
35
  super
30
36
  end
31
37
 
32
- # integration to Logging
33
-
38
+ ##
39
+ # Integration to Logging
40
+ #
41
+ # @param [String] tag
42
+ # @param [Hash] args
43
+ #
34
44
  def log(tag, *args)
35
45
  super(tag, args.join("\n"))
36
46
  end
@@ -6,31 +6,46 @@ require 'ruby-growl'
6
6
  module Ramaze
7
7
  module Logger
8
8
 
9
- # Informer for the growl notification system on OSX.
10
-
9
+ ##
10
+ # Informer for the Growl notification system
11
+ # Growl lets Mac OS X applications unintrusively tell you when things happen.
12
+ #
13
+ # Growl can be downloaded from the following website: http://growl.info/
14
+ #
11
15
  class Growl < ::Growl
12
-
16
+ include Innate::Traited
17
+ include Logging
18
+
13
19
  trait :defaults => {
14
- :name => 'walrus',
15
- :host => 'localhost',
16
- :password => 'walrus',
17
- :all_notifies => %w[error warn debug info dev],
20
+ :name => 'walrus' ,
21
+ :host => 'localhost',
22
+ :password => 'walrus' ,
23
+ :all_notifies => %w[error warn debug info dev],
18
24
  :default_notifies => %w[error warn info]
19
25
  }
20
26
 
27
+ ##
21
28
  # Takes the options from the default trait for merging.
22
-
29
+ #
30
+ # @param [Hash] options A hash containing extra options to use when initializing the Growl logger.
31
+ #
23
32
  def initialize(options = {})
24
33
  options = class_trait[:defaults].merge(options).values_at(:host, :name, :all_notifies, :default_notifies, :password)
25
34
  super(*options)
26
35
  end
27
36
 
28
- # integration to Logging
29
-
37
+ ##
38
+ # Integration to Logging
39
+ #
40
+ # @param [String] tag
41
+ # @param [Hash] args
42
+ #
30
43
  def log(tag, *args)
31
- notify(tag.to_s, Time.now.strftime("%X"), args.join("\n")[0..100])
32
- rescue Errno::EMSGSIZE
33
- # Send size was to big (not really), ignore
44
+ begin
45
+ notify(tag.to_s, Time.now.strftime("%X"), args.join("\n")[0..100])
46
+ rescue Errno::EMSGSIZE
47
+ # Send size was to big (not really), ignore
48
+ end
34
49
  end
35
50
  end
36
51
 
@@ -4,18 +4,22 @@
4
4
  module Ramaze
5
5
  module Logger
6
6
 
7
+ ##
7
8
  # Bundles different informer instances and sends incoming messages to each.
8
9
  # This is the default with Informer as only member.
9
-
10
+ #
10
11
  class LogHub
11
12
  include Logging
12
13
 
13
14
  attr_accessor :loggers
14
15
  attr_accessor :ignored_tags
15
16
 
17
+ ##
16
18
  # Takes a list of instances or classes (which will be initialized) and that
17
19
  # are added to @loggers. All messages are then sent to each member.
18
-
20
+ #
21
+ # @param [Array] loggers
22
+ #
19
23
  def initialize(*loggers)
20
24
  @loggers = loggers
21
25
  @ignored_tags = Set.new
@@ -27,8 +31,12 @@ module Ramaze
27
31
  @loggers.compact!
28
32
  end
29
33
 
30
- # integration to Logging
31
-
34
+ ##
35
+ # Integration to Logging
36
+ #
37
+ # @param [String] tag
38
+ # @param [Hash] args
39
+ #
32
40
  def log(tag, *args)
33
41
  return if @ignored_tags.include?(tag)
34
42
  @loggers.each do |logger|
@@ -4,9 +4,10 @@
4
4
  module Ramaze
5
5
  module Logger
6
6
 
7
+ ##
7
8
  # A minimal logger for Ramaze, supports files, CLI, colors and some
8
9
  # customization.
9
-
10
+ #
10
11
  class Informer
11
12
  include Logging
12
13
  include Innate::Traited
@@ -31,17 +32,21 @@ module Ramaze
31
32
  :error => :red,
32
33
  }
33
34
 
35
+ ##
34
36
  # Create a new instance of Informer.
35
- # You can spcify
36
37
  #
37
- # Examples:
38
+ # @example
39
+ #
38
40
  # Informer.new #=> logs to stdout with all levels being
39
41
  # shown.
40
42
  # Informer.new($stderr) #=> same, but to stderr
41
43
  # Informer.new("foo.log") #=> same, but logs to the file foo.log
42
44
  # (or creates it if it doesn't exist yet)
43
45
  # Informer.new($stdout, [:info]) #=> show only #info messages to stdout.
44
-
46
+ #
47
+ # @param [String] out Specifies where the output should go. By default this is set to STDOUT.
48
+ # @param [Array] log_leves Array containing the levels that should be logged.
49
+ #
45
50
  def initialize(out = $stdout, log_levels = [:debug, :error, :info, :warn])
46
51
  @colorize = false
47
52
 
@@ -68,8 +73,9 @@ module Ramaze
68
73
  @log_levels = log_levels
69
74
  end
70
75
 
76
+ ##
71
77
  # Close the file we log to if it isn't closed already.
72
-
78
+ #
73
79
  def shutdown
74
80
  if @out.respond_to?(:close)
75
81
  Log.debug("close, #{@out.inspect}")
@@ -77,8 +83,12 @@ module Ramaze
77
83
  end
78
84
  end
79
85
 
80
- # Integration to Logging.
81
-
86
+ ##
87
+ # Integration to Logging
88
+ #
89
+ # @param [String] tag The log level for the current message(s).
90
+ # @param [Array] messages Array containing the data that should be logged.
91
+ #
82
92
  def log tag, *messages
83
93
  return if closed? || !@log_levels.include?(tag)
84
94
  messages.flatten!
@@ -97,9 +107,14 @@ module Ramaze
97
107
  @out.flush if @out.respond_to?(:flush)
98
108
  end
99
109
 
110
+ ##
100
111
  # Takes the prefix (tag), text and timestamp and applies it to
101
112
  # the :format trait.
102
-
113
+ #
114
+ # @param [String] prefix
115
+ # @param [String] text
116
+ # @param [Integer] time
117
+ #
103
118
  def log_interpolate prefix, text, time = timestamp
104
119
  message = class_trait[:format].dup
105
120
 
@@ -109,17 +124,19 @@ module Ramaze
109
124
  message
110
125
  end
111
126
 
127
+ ##
112
128
  # This uses timestamp trait or a date in the format of
113
129
  # %Y-%m-%d %H:%M:%S
114
130
  # # => "2007-01-19 21:09:32"
115
-
131
+ #
116
132
  def timestamp
117
133
  mask = class_trait[:timestamp]
118
134
  Time.now.strftime(mask || "%Y-%m-%d %H:%M:%S")
119
135
  end
120
136
 
121
- # is @out closed?
122
-
137
+ ##
138
+ # Is @out closed?
139
+ #
123
140
  def closed?
124
141
  @out.respond_to?(:closed?) and @out.closed?
125
142
  end
@@ -4,17 +4,22 @@
4
4
  module Ramaze
5
5
  module Logger
6
6
 
7
+ ##
7
8
  # Informer for the Knotify notfication system used on KDE.
8
9
  # Doesn't need any special libraries.
9
-
10
+ #
10
11
  class Knotify
11
12
  include Logging
12
13
 
13
14
  trait :present => 16
14
15
 
16
+ ##
15
17
  # Please see for more information on the API used here:
16
18
  # http://lukeplant.me.uk/articles.php?id=3
17
-
19
+ #
20
+ # @param [String] tag
21
+ # @param [Hash] args
22
+ #
18
23
  def log(tag, *messages)
19
24
  present = class_trait[:present]
20
25
  tag = tag.to_s.capitalize
@@ -6,17 +6,25 @@ require 'logger'
6
6
  module Ramaze
7
7
  module Logger
8
8
 
9
- # Informer for the Stdlib Logger
10
-
9
+ ##
10
+ # Informer for the Stdlib Logger.
11
+ #
11
12
  class Logger < ::Logger
12
13
 
13
- # integration to Logging
14
-
14
+ ##
15
+ # Integration to Logging
16
+ #
17
+ # @param [String] tag
18
+ # @param [Hash] args
19
+ #
15
20
  def log(tag, *args)
16
21
  __send__(tag, args.join("\n"))
17
22
  end
18
23
 
24
+ ##
19
25
  # Stub for compatibility
26
+ #
27
+ # @param [Hash] args
20
28
  def dev(*args)
21
29
  debug(*args)
22
30
  end