ramaze 2010.06.18 → 2011.01
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/MANIFEST +9 -16
- data/README.md +37 -30
- data/Rakefile +5 -1
- data/TODO.md +19 -0
- data/doc/AUTHORS +5 -1
- data/doc/CHANGELOG +3553 -3272
- data/doc/tutorial/todolist.html +1512 -1512
- data/examples/app/blog/app.rb +2 -0
- data/examples/app/todolist/controller/init.rb +1 -2
- data/examples/app/wiktacular/mkd/main/2007-07-20_19-21-12.mkd +1 -1
- data/examples/app/wiktacular/mkd/main/2007-07-20_19-23-10.mkd +1 -1
- data/examples/app/wiktacular/mkd/main/2007-07-20_19-45-07.mkd +1 -1
- data/examples/app/wiktacular/mkd/main/current.mkd +1 -1
- data/examples/app/wiktacular/mkd/testing/2007-07-20_16-43-46.mkd +1 -1
- data/examples/app/wiktacular/mkd/testing/2007-07-20_19-43-50.mkd +2 -2
- data/examples/app/wiktacular/mkd/testing/2007-07-21_18-47-08.mkd +16 -16
- data/examples/app/wiktacular/mkd/testing/2007-07-21_18-47-54.mkd +16 -16
- data/examples/app/wiktacular/mkd/testing/current.mkd +16 -16
- data/lib/proto/model/init.rb +1 -1
- data/lib/proto/public/js/jquery.js +2034 -1095
- data/lib/proto/start.rb +2 -0
- data/lib/proto/view/index.xhtml +3 -3
- data/lib/ramaze.rb +1 -2
- data/lib/ramaze/cache.rb +1 -0
- data/lib/ramaze/cache/sequel.rb +131 -37
- data/lib/ramaze/controller.rb +1 -0
- data/lib/ramaze/gestalt.rb +75 -46
- data/lib/ramaze/helper.rb +1 -0
- data/lib/ramaze/helper/auth.rb +38 -4
- data/lib/ramaze/helper/blue_form.rb +498 -78
- data/lib/ramaze/helper/cache.rb +2 -2
- data/lib/ramaze/helper/csrf.rb +225 -0
- data/lib/ramaze/helper/erector.rb +67 -9
- data/lib/ramaze/helper/flash.rb +4 -2
- data/lib/ramaze/helper/gestalt.rb +2 -0
- data/lib/ramaze/helper/gravatar.rb +1 -1
- data/lib/ramaze/helper/localize.rb +4 -0
- data/lib/ramaze/helper/send_file.rb +30 -0
- data/lib/ramaze/helper/thread.rb +5 -0
- data/lib/ramaze/helper/user.rb +4 -3
- data/lib/ramaze/helper/xhtml.rb +87 -8
- data/lib/ramaze/log.rb +13 -0
- data/lib/ramaze/log/analogger.rb +15 -5
- data/lib/ramaze/log/growl.rb +28 -13
- data/lib/ramaze/log/hub.rb +12 -4
- data/lib/ramaze/log/informer.rb +28 -11
- data/lib/ramaze/log/knotify.rb +7 -2
- data/lib/ramaze/log/logger.rb +12 -4
- data/lib/ramaze/log/logging.rb +40 -14
- data/lib/ramaze/log/rotatinginformer.rb +47 -23
- data/lib/ramaze/log/syslog.rb +37 -31
- data/lib/ramaze/log/xosd.rb +7 -4
- data/lib/ramaze/middleware_compiler.rb +2 -2
- data/lib/ramaze/snippets/fiber.rb +63 -63
- data/lib/ramaze/snippets/ramaze/lru_hash.rb +1 -1
- data/lib/ramaze/tool/bin.rb +1 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +4 -4
- data/lib/ramaze/view/erector.rb +88 -13
- data/ramaze.gemspec +65 -65
- data/spec/ramaze/bin/ramaze.rb +1 -1
- data/spec/ramaze/cache/localmemcache.rb +20 -12
- data/spec/ramaze/cache/sequel.rb +19 -19
- data/spec/ramaze/helper/blue_form.rb +549 -257
- data/spec/ramaze/helper/csrf.rb +109 -0
- data/spec/ramaze/helper/httpdigest.rb +31 -29
- data/spec/ramaze/helper/user.rb +1 -1
- data/spec/ramaze/helper/xhtml.rb +17 -0
- data/spec/ramaze/log/growl.rb +34 -0
- data/spec/ramaze/log/informer.rb +1 -0
- data/spec/ramaze/view/erector.rb +49 -71
- data/spec/ramaze/view/erector/external_view.erector +5 -0
- data/spec/ramaze/view/erector/index.erector +5 -0
- data/spec/ramaze/view/erector/layout.erector +13 -3
- data/spec/ramaze/view/erector/tables.erector +23 -0
- data/spec/ramaze/view/erector/view.erector +6 -0
- data/tasks/git.rake +2 -2
- metadata +133 -176
- data/examples/helpers/form_with_sequel.rb +0 -24
- data/examples/helpers/nitro_form.rb +0 -23
- data/lib/ramaze/helper/form.rb +0 -133
- data/lib/ramaze/helper/nitroform.rb +0 -14
- data/lib/ramaze/helper/pager.rb +0 -367
- data/lib/ramaze/helper/partial.rb +0 -100
- data/lib/ramaze/helper/sequel.rb +0 -55
- data/lib/ramaze/helper/sequel_form.rb +0 -284
- data/lib/vendor/etag.rb +0 -22
- data/spec/ramaze/helper/form.rb +0 -360
- data/spec/ramaze/helper/pager.rb +0 -96
- data/spec/ramaze/helper/sequel_form.rb +0 -94
- data/spec/ramaze/view/erector/external.erector +0 -1
- data/spec/ramaze/view/erector/invoke_helper_method.erector +0 -1
- data/spec/ramaze/view/erector/strict_xhtml.erector +0 -3
- data/spec/ramaze/view/erector/sum.erector +0 -1
data/lib/proto/start.rb
CHANGED
data/lib/proto/view/index.xhtml
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
<code>view/index.xhtml</code>, this page.
|
10
10
|
</li>
|
11
11
|
<li>
|
12
|
-
<code>
|
12
|
+
<code>layout/default.xhtml</code>, the layout for this page.
|
13
13
|
</li>
|
14
14
|
<li>
|
15
15
|
<code>controller/main.rb</code>, where you can change the header of this
|
@@ -27,8 +27,8 @@
|
|
27
27
|
</p>
|
28
28
|
|
29
29
|
<p>
|
30
|
-
You can also read the
|
31
|
-
<a href="http://
|
30
|
+
You can also read the
|
31
|
+
<a href="http://doc.rubyists.com/ramaze%2binnate/">rdocs</a>
|
32
32
|
or browse around the
|
33
33
|
<a href="http://source.ramaze.net">Ramaze source code</a>.
|
34
34
|
</p>
|
data/lib/ramaze.rb
CHANGED
@@ -23,7 +23,6 @@ module Ramaze
|
|
23
23
|
class << self; attr_accessor :options; end
|
24
24
|
|
25
25
|
# vendored, will go into rack-contrib
|
26
|
-
require 'vendor/etag'
|
27
26
|
require 'vendor/route_exceptions'
|
28
27
|
|
29
28
|
# Ramaze itself
|
@@ -67,7 +66,7 @@ module Ramaze
|
|
67
66
|
m.use Rack::ShowStatus
|
68
67
|
m.use Rack::RouteExceptions
|
69
68
|
m.use Rack::ConditionalGet
|
70
|
-
m.use Rack::ETag
|
69
|
+
m.use Rack::ETag, 'public'
|
71
70
|
m.use Rack::Head
|
72
71
|
m.use Ramaze::Reloader
|
73
72
|
m.run Ramaze::AppMap
|
data/lib/ramaze/cache.rb
CHANGED
data/lib/ramaze/cache/sequel.rb
CHANGED
@@ -1,79 +1,173 @@
|
|
1
1
|
# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
-
|
4
3
|
require 'sequel'
|
5
4
|
|
6
5
|
module Ramaze
|
7
6
|
class Cache
|
8
|
-
|
9
|
-
# Cache
|
7
|
+
##
|
8
|
+
# Cache system that uses Sequel to store data in a database table named
|
9
|
+
# "ramaze_cache". Values stored in the database will be automatically serialized/
|
10
|
+
# unserialized using Marshal. Originally this cache system didn't work with Sequel 3
|
11
|
+
# but this has been fixed by Yorick Peterse.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# # Define that we want to use the Sequel cache for sessions
|
15
|
+
# Ramaze.options.cache.session = Ramaze::Cache::Sequel
|
16
|
+
#
|
17
|
+
# # Store some data in the session
|
18
|
+
# session["framework"] = "Ramaze"
|
19
|
+
#
|
20
|
+
# # Do something with the data
|
21
|
+
# session["framework"] += ", simply (r)amazing"
|
22
|
+
#
|
23
|
+
# @author Unknown, Yorick Peterse
|
10
24
|
#
|
11
|
-
# Please note that this cache might not work perfectly with Sequel 3.0.0,
|
12
|
-
# as the #[] and #[]= methods do not respect serialization.
|
13
|
-
# I'll lobby for a change in that direction.
|
14
25
|
class Sequel
|
26
|
+
# I can haz API?
|
15
27
|
include Cache::API
|
16
28
|
|
29
|
+
##
|
30
|
+
# Model used for managing the data in the database.
|
31
|
+
# All data stored in the "value" column will be serialized/unserialized by Sequel itself.
|
32
|
+
# The structure of the table that belongs to this model looks like the following:
|
33
|
+
#
|
34
|
+
# _________________________________________________________________
|
35
|
+
# | | | | |
|
36
|
+
# | (integer) ID | (string) key | (string) value | (date) expires |
|
37
|
+
# |______________|______________|________________|__________________|
|
38
|
+
#
|
39
|
+
#
|
40
|
+
# Note that "key" is a unique field so double check to see if your application might try
|
41
|
+
# to insert an already existing key as this will cause Sequel errors.
|
42
|
+
#
|
43
|
+
# @author Unknown, Yorick Peterse
|
44
|
+
#
|
17
45
|
class Table < ::Sequel::Model(:ramaze_cache)
|
18
46
|
plugin :schema
|
19
|
-
plugin :serialization
|
20
|
-
|
21
|
-
serialize_attributes :marshal, :value
|
47
|
+
plugin :serialization, :marshal, :value
|
22
48
|
|
49
|
+
# Define the schema for this model
|
23
50
|
set_schema do
|
24
51
|
primary_key :id
|
25
|
-
|
26
|
-
|
27
|
-
String :
|
28
|
-
|
52
|
+
|
53
|
+
String :key, :null => false, :unique => true
|
54
|
+
String :value, :text => true
|
55
|
+
|
29
56
|
Time :expires
|
30
57
|
end
|
31
|
-
|
32
|
-
def [](column)
|
33
|
-
if column == :value
|
34
|
-
deserialized_values[column] = deserialize_value(column, @values[column])
|
35
|
-
else
|
36
|
-
super
|
37
|
-
end
|
38
|
-
end
|
39
58
|
end
|
40
59
|
|
41
|
-
|
60
|
+
##
|
61
|
+
# Create the cache table if it doesn't exist yet.
|
62
|
+
# This cache does not yet support multiple applications unless you
|
63
|
+
# give "app" an unique name.
|
64
|
+
#
|
65
|
+
# @author Unknown, Yorick Peterse
|
66
|
+
# @example
|
67
|
+
# cache = Ramaze::Cache::Sequel.new
|
68
|
+
# cache.cache_setup 'my_server', 'chuck_norris', 'blog', 'articles'
|
69
|
+
#
|
70
|
+
# @param [String] host The hostname of the machine on which the application is running.
|
71
|
+
# @param [String] user The user under which the application is running.
|
72
|
+
# @param [String] app The name of the "application". For example, when using this cache
|
73
|
+
# for session "app" will be set to "session".
|
74
|
+
# @param [String] name The name for the row. When using sessions this will be set to the
|
75
|
+
# user's session ID.
|
76
|
+
#
|
42
77
|
def cache_setup(host, user, app, name)
|
43
78
|
@namespace = [host, user, app, name].compact.join(':')
|
44
79
|
Table.create_table?
|
45
80
|
@store = Table
|
46
81
|
end
|
47
82
|
|
48
|
-
|
83
|
+
##
|
84
|
+
# Wipe out _all_ data in the table, use with care!
|
85
|
+
#
|
86
|
+
# @author Unknown, Yorick Peterse
|
87
|
+
# @example
|
88
|
+
# cache = Ramaze::Cache::Sequel.new
|
89
|
+
# cache.cache_clear
|
90
|
+
#
|
49
91
|
def cache_clear
|
50
|
-
|
92
|
+
@store.delete
|
51
93
|
end
|
52
94
|
|
53
|
-
|
95
|
+
##
|
96
|
+
# Deletes a specific set of records based on the provided keys.
|
97
|
+
#
|
98
|
+
# @author Unknown, Yorick Peterse
|
99
|
+
# @example
|
100
|
+
# # Delete everything where "key" is set to "chunky_bacon"
|
101
|
+
# cache = Ramaze::Cache::Sequel.new
|
102
|
+
# cache.cache_delete 'chunky_bacon'
|
103
|
+
#
|
104
|
+
# @param [String] *keys A set of keys that define which row has to be deleted.
|
105
|
+
#
|
54
106
|
def cache_delete(*keys)
|
55
|
-
|
56
|
-
|
57
|
-
|
107
|
+
if keys
|
108
|
+
keys.each do |key|
|
109
|
+
record = @store[:key => namespaced(key)]
|
110
|
+
record.delete if record
|
111
|
+
end
|
58
112
|
end
|
59
113
|
end
|
60
114
|
|
115
|
+
##
|
116
|
+
# Retrieve the cache that belongs to the specified key.
|
117
|
+
#
|
118
|
+
# @author Unknown, Yorick Peterse
|
119
|
+
# @example
|
120
|
+
# cache = Ramaze::Cache::Sequel.new
|
121
|
+
# data = cache.cache_fetch 'chunky_bacon'
|
122
|
+
#
|
123
|
+
# @param [String] key The key that defines what record to retrieve.
|
124
|
+
# @param [String] default The value to return in case no data could be found.
|
125
|
+
# @return [String] The unserialized data from the "value" column.
|
126
|
+
# @return [String]
|
127
|
+
#
|
61
128
|
def cache_fetch(key, default = nil)
|
62
|
-
|
129
|
+
# Retrieve the data and return it
|
130
|
+
record = @store[:key => namespaced(key)]
|
131
|
+
record.value rescue default
|
63
132
|
end
|
64
133
|
|
134
|
+
##
|
135
|
+
# Store the specified key/value variables in the cache.
|
136
|
+
#
|
137
|
+
# @author Unknown, Yorick Peterse
|
138
|
+
# @example
|
139
|
+
# cache = Ramaze::Cache::Sequel.new
|
140
|
+
# cache.cache_store 'name', 'Yorick Peterse', :ttl => 3600
|
141
|
+
#
|
142
|
+
# @param [String] key The name of the cache to store.
|
143
|
+
# @param [String] value The actual data to cache.
|
144
|
+
# @param [Hash] options Additional options such as the TTL.
|
145
|
+
# @return [String]
|
146
|
+
#
|
65
147
|
def cache_store(key, value, options = {})
|
66
|
-
key
|
67
|
-
ttl
|
68
|
-
expires = Time.now + ttl if ttl
|
148
|
+
key = namespaced(key)
|
149
|
+
ttl = options[:ttl] rescue nil
|
150
|
+
expires = Time.now + ttl if !ttl.nil?
|
151
|
+
record = @store[:key => key]
|
69
152
|
|
70
|
-
|
71
|
-
record
|
72
|
-
|
73
|
-
|
74
|
-
|
153
|
+
# Figure out if the record is new or already exists
|
154
|
+
if !record
|
155
|
+
record = @store.create(:key => key, :value => value, :expires => expires)
|
156
|
+
record.value
|
157
|
+
else
|
158
|
+
record = record.update(:value => value, :expires => expires)
|
159
|
+
record.value
|
160
|
+
end
|
75
161
|
end
|
76
162
|
|
163
|
+
##
|
164
|
+
# Generate the namespace for the cache.
|
165
|
+
# Namespaces have the format of host:user:app:name:key.
|
166
|
+
#
|
167
|
+
# @author Unknown
|
168
|
+
# @param [String] key The name of the cache key.
|
169
|
+
# @return [String]
|
170
|
+
#
|
77
171
|
def namespaced(key)
|
78
172
|
[@namespace, key].join(':')
|
79
173
|
end
|
data/lib/ramaze/controller.rb
CHANGED
data/lib/ramaze/gestalt.rb
CHANGED
@@ -1,85 +1,91 @@
|
|
1
1
|
# Copyright (c) 2009 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
|
-
=begin rdoc
|
5
|
-
Example:
|
6
|
-
|
7
|
-
require 'ramaze'
|
8
|
-
require 'ramaze/gestalt'
|
9
|
-
|
10
|
-
page = Ramaze::Gestalt.build{
|
11
|
-
title = 'Hello, World!'
|
12
|
-
|
13
|
-
html do
|
14
|
-
head{ title(title) }
|
15
|
-
body do
|
16
|
-
h1(title)
|
17
|
-
p 'I count to 10'
|
18
|
-
('1'..'10').each do |count|
|
19
|
-
div(:style => 'width: 25px; height: 25px'){ count }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
}
|
24
|
-
=end
|
25
|
-
|
26
4
|
module Ramaze
|
27
5
|
|
6
|
+
##
|
28
7
|
# Gestalt is the custom HTML/XML builder for Ramaze, based on a very simple
|
29
8
|
# DSL it will build your markup.
|
30
|
-
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# html =
|
13
|
+
# Gestalt.build do
|
14
|
+
# html do
|
15
|
+
# head do
|
16
|
+
# title "Hello, World!"
|
17
|
+
# end
|
18
|
+
# body do
|
19
|
+
# h1 "Hello, World!"
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
31
24
|
class Gestalt
|
32
25
|
attr_accessor :out
|
33
26
|
|
27
|
+
##
|
34
28
|
# The default way to start building your markup.
|
35
29
|
# Takes a block and returns the markup.
|
36
30
|
#
|
37
|
-
#
|
38
|
-
# html =
|
39
|
-
# Gestalt.build do
|
40
|
-
# html do
|
41
|
-
# head do
|
42
|
-
# title "Hello, World!"
|
43
|
-
# end
|
44
|
-
# body do
|
45
|
-
# h1 "Hello, World!"
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
# end
|
31
|
+
# @param [Block] block
|
49
32
|
#
|
50
|
-
|
51
33
|
def self.build(&block)
|
52
34
|
self.new(&block).to_s
|
53
35
|
end
|
54
36
|
|
37
|
+
##
|
55
38
|
# Gestalt.new is like ::build but will return itself.
|
56
39
|
# you can either access #out or .to_s it, which will
|
57
40
|
# return the actual markup.
|
58
41
|
#
|
59
42
|
# Useful for distributed building of one page.
|
60
|
-
|
43
|
+
#
|
44
|
+
# @param [Block] block
|
45
|
+
#
|
61
46
|
def initialize(&block)
|
62
47
|
@out = []
|
63
48
|
instance_eval(&block) if block_given?
|
64
49
|
end
|
65
50
|
|
66
|
-
|
67
|
-
|
51
|
+
##
|
52
|
+
# Catching all the tags. passing it to _gestalt_build_tag
|
53
|
+
#
|
54
|
+
# @param [String] method The method that was called.
|
55
|
+
# @param [Hash] args Additional arguments passed to the called method.
|
56
|
+
# @param [Block] block
|
57
|
+
#
|
68
58
|
def method_missing(meth, *args, &block)
|
69
59
|
_gestalt_call_tag meth, args, &block
|
70
60
|
end
|
71
61
|
|
72
|
-
|
73
|
-
|
62
|
+
##
|
63
|
+
# Workaround for Kernel#p to make <p /> tags possible.
|
64
|
+
#
|
65
|
+
# @param [Hash] args Extra arguments that should be processed before creating the paragraph tag.
|
66
|
+
# @param [Block] block
|
67
|
+
#
|
74
68
|
def p(*args, &block)
|
75
69
|
_gestalt_call_tag :p, args, &block
|
76
70
|
end
|
77
|
-
|
78
|
-
|
71
|
+
|
72
|
+
##
|
73
|
+
# Workaround for Kernel#select to make <select></select> work.
|
74
|
+
#
|
75
|
+
# @param [Hash] args Extra arguments that should be processed before creating the select tag.
|
76
|
+
# @param [Block] block
|
77
|
+
#
|
79
78
|
def select(*args, &block)
|
80
79
|
_gestalt_call_tag(:select, args, &block)
|
81
80
|
end
|
82
81
|
|
82
|
+
##
|
83
|
+
# TODO: Describe this method, I'm not exactly sure what it does - Yorick
|
84
|
+
#
|
85
|
+
# @param [String] name
|
86
|
+
# @param [Hash] args
|
87
|
+
# @param [Block] block
|
88
|
+
#
|
83
89
|
def _gestalt_call_tag(name, args, &block)
|
84
90
|
if args.size == 1 and args[0].kind_of? Hash
|
85
91
|
# args are just attributes, children in block...
|
@@ -93,9 +99,16 @@ module Ramaze
|
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
96
|
-
|
97
|
-
#
|
98
|
-
|
102
|
+
##
|
103
|
+
# Build a tag for `name`, using `args` and an optional block that
|
104
|
+
# will be yielded.
|
105
|
+
#
|
106
|
+
# TODO: Describe this method since I'm not exactly sure what it does - Yorick
|
107
|
+
#
|
108
|
+
# @param [String] name
|
109
|
+
# @param [Hash] attr
|
110
|
+
# @param [Hash] text
|
111
|
+
#
|
99
112
|
def _gestalt_build_tag(name, attr = {}, text = [])
|
100
113
|
@out << "<#{name}"
|
101
114
|
@out << attr.map{|(k,v)| %[ #{k}="#{_gestalt_escape_entities(v)}"] }.join
|
@@ -112,6 +125,11 @@ module Ramaze
|
|
112
125
|
end
|
113
126
|
end
|
114
127
|
|
128
|
+
##
|
129
|
+
# Replace common HTML characters such as " and < with their entities.
|
130
|
+
#
|
131
|
+
# @param [String] s The HTML string that needs to be escaped.
|
132
|
+
#
|
115
133
|
def _gestalt_escape_entities(s)
|
116
134
|
s.to_s.gsub(/&/, '&').
|
117
135
|
gsub(/"/, '"').
|
@@ -120,10 +138,21 @@ module Ramaze
|
|
120
138
|
gsub(/>/, '>')
|
121
139
|
end
|
122
140
|
|
141
|
+
##
|
142
|
+
# TODO: Describe this method since I'm not exactly sure what it does - Yorick
|
143
|
+
#
|
144
|
+
# @param [String] name
|
145
|
+
# @param [Hash] args
|
146
|
+
# @param [Block] block
|
147
|
+
#
|
123
148
|
def tag(name, *args, &block)
|
124
149
|
_gestalt_call_tag(name.to_s, args, &block)
|
125
150
|
end
|
126
151
|
|
152
|
+
##
|
153
|
+
# Convert the final output of Gestalt to a string.
|
154
|
+
# This method has the following alias: "to_str".
|
155
|
+
#
|
127
156
|
def to_s
|
128
157
|
@out.join
|
129
158
|
end
|