Pistos-ramaze 2009.04.08 → 2009.06.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/MANIFEST +37 -22
- data/{README.markdown → README.md} +5 -24
- data/Rakefile +33 -26
- data/benchmark/bench_templates/bench.rb +67 -0
- data/benchmark/bench_templates/view/large.erb +79 -0
- data/benchmark/bench_templates/view/large.haml +41 -0
- data/benchmark/bench_templates/view/large.xhtml +79 -0
- data/benchmark/bench_templates/view/small.erb +21 -0
- data/benchmark/bench_templates/view/small.haml +12 -0
- data/benchmark/bench_templates/view/small.xhtml +21 -0
- data/benchmark/run.rb +14 -21
- data/benchmark/suite/minimal.rb +3 -5
- data/benchmark/suite/no_informer.rb +0 -2
- data/benchmark/suite/no_sessions.rb +3 -4
- data/benchmark/suite/no_template.rb +1 -3
- data/benchmark/suite/simple.rb +1 -3
- data/benchmark/suite/template_erubis.rb +0 -2
- data/benchmark/suite/template_etanni.rb +8 -0
- data/benchmark/suite/template_ezamar.rb +1 -3
- data/benchmark/suite/template_haml.rb +0 -2
- data/benchmark/suite/template_liquid.rb +0 -2
- data/benchmark/suite/template_markaby.rb +0 -2
- data/benchmark/suite/template_nagoro.rb +1 -3
- data/benchmark/suite/template_redcloth.rb +0 -2
- data/benchmark/suite/template_tenjin.rb +0 -2
- data/bin/ramaze +11 -163
- data/doc/AUTHORS +15 -8
- data/doc/CHANGELOG +10094 -12262
- data/doc/meta/announcement.txt +93 -46
- data/doc/tutorial/todolist.html +22 -58
- data/doc/tutorial/todolist.txt +20 -39
- data/examples/app/auth/layout/{auth.nag → auth.xhtml} +0 -0
- data/examples/app/auth/view/{index.nag → index.xhtml} +0 -0
- data/examples/app/auth/view/{login.nag → login.xhtml} +0 -0
- data/examples/app/auth/view/{secret.nag → secret.xhtml} +0 -0
- data/examples/app/blog/app.rb +1 -1
- data/examples/app/blog/controller/comment.rb +1 -1
- data/examples/app/blog/controller/entry.rb +12 -3
- data/examples/app/blog/model/init.rb +5 -0
- data/examples/app/blog/model/tag.rb +2 -2
- data/examples/app/blog/view/entry/index.nag +3 -3
- data/examples/app/blog/view/feed.atom.nag +1 -1
- data/examples/app/blog/view/feed.rss.nag +1 -1
- data/examples/app/blog/view/index.nag +1 -1
- data/examples/app/blog/view/tag/index.nag +1 -1
- data/examples/app/chat/layout/{default.nag → default.xhtml} +0 -0
- data/examples/app/chat/view/{chat.nag → chat.xhtml} +0 -0
- data/examples/app/chat/view/{index.nag → index.xhtml} +0 -0
- data/examples/app/localization/locale/de.yaml +5 -0
- data/examples/app/localization/locale/en.yaml +5 -0
- data/examples/app/localization/locale/ja.yaml +5 -0
- data/examples/app/localization/start.rb +33 -20
- data/examples/app/wikore/spec/wikore.rb +4 -6
- data/examples/app/wikore/src/controller.rb +9 -11
- data/examples/app/wikore/src/model.rb +7 -10
- data/examples/app/wikore/start.rb +1 -1
- data/examples/app/wikore/{template → view}/index.xhtml +0 -0
- data/examples/helpers/cache.rb +6 -4
- data/examples/misc/css.rb +6 -12
- data/examples/misc/rapp.rb +28 -17
- data/lib/proto/app.rb +14 -0
- data/lib/proto/config.ru +8 -5
- data/lib/proto/controller/init.rb +3 -3
- data/lib/proto/spec/main.rb +9 -11
- data/lib/proto/start.rb +6 -10
- data/lib/ramaze.rb +8 -9
- data/lib/ramaze/app.rb +4 -3
- data/lib/ramaze/cache/localmemcache.rb +2 -2
- data/lib/ramaze/cache/memcache.rb +26 -1
- data/lib/ramaze/cache/sequel.rb +24 -9
- data/lib/ramaze/contrib/addressable_route.rb +56 -0
- data/lib/ramaze/contrib/email.rb +2 -0
- data/lib/ramaze/contrib/facebook/facebook.rb +4 -4
- data/lib/ramaze/contrib/sequel/create_join.rb +1 -0
- data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
- data/lib/ramaze/contrib/sequel/image.rb +9 -11
- data/lib/ramaze/contrib/sequel/relation.rb +17 -3
- data/lib/ramaze/controller.rb +26 -18
- data/lib/ramaze/gestalt.rb +4 -1
- data/lib/ramaze/helper.rb +1 -0
- data/lib/ramaze/helper/auth.rb +0 -5
- data/lib/ramaze/helper/cache.rb +65 -25
- data/lib/ramaze/helper/form.rb +14 -2
- data/lib/ramaze/helper/formatting.rb +3 -1
- data/lib/ramaze/helper/gestalt.rb +32 -0
- data/lib/ramaze/helper/identity.rb +3 -3
- data/lib/ramaze/helper/layout.rb +97 -0
- data/lib/ramaze/helper/link.rb +6 -25
- data/lib/ramaze/helper/localize.rb +13 -3
- data/lib/ramaze/helper/paginate.rb +4 -2
- data/lib/ramaze/helper/ultraviolet.rb +2 -0
- data/lib/ramaze/helper/user.rb +3 -3
- data/lib/ramaze/log/rotatinginformer.rb +10 -10
- data/lib/ramaze/request.rb +3 -5
- data/lib/ramaze/setup.rb +22 -9
- data/lib/ramaze/spec.rb +8 -12
- data/lib/ramaze/spec/bacon.rb +34 -0
- data/lib/ramaze/spec/helper/template_examples.rb +15 -22
- data/lib/ramaze/tool/bin.rb +340 -0
- data/lib/ramaze/tool/project_creator.rb +1 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +6 -11
- data/lib/ramaze/view/erubis.rb +2 -2
- data/lib/ramaze/view/ezamar.rb +2 -2
- data/lib/ramaze/view/gestalt.rb +14 -0
- data/lib/ramaze/view/haml.rb +2 -1
- data/lib/ramaze/view/liquid.rb +45 -11
- data/lib/ramaze/view/maruku.rb +2 -1
- data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/tenjin.rb +7 -4
- data/lib/vendor/etag.rb +4 -2
- data/lib/vendor/route_exceptions.rb +9 -15
- data/ramaze.gemspec +56 -9
- data/spec/contrib/addressable_route.rb +30 -0
- data/spec/contrib/rest.rb +2 -2
- data/spec/examples/caching.rb +5 -7
- data/spec/examples/css.rb +3 -3
- data/spec/examples/element.rb +4 -3
- data/spec/examples/hello.rb +3 -3
- data/spec/examples/helpers/httpdigest.rb +44 -69
- data/spec/examples/linking.rb +3 -3
- data/spec/examples/simple.rb +3 -3
- data/spec/examples/templates/template_erubis.rb +8 -4
- data/spec/examples/templates/template_ezamar.rb +9 -4
- data/spec/examples/templates/template_haml.rb +8 -4
- data/spec/examples/templates/template_liquid.rb +8 -4
- data/spec/examples/templates/template_markaby.rb +9 -5
- data/spec/examples/templates/template_nagoro.rb +9 -5
- data/spec/examples/templates/template_redcloth.rb +8 -4
- data/spec/examples/templates/template_remarkably.rb +8 -4
- data/spec/examples/templates/template_tenjin.rb +8 -4
- data/spec/helper.rb +1 -2
- data/spec/ramaze/action/render.rb +4 -1
- data/spec/ramaze/app.rb +5 -2
- data/spec/ramaze/bin/ramaze.rb +96 -0
- data/spec/ramaze/cache/localmemcache.rb +1 -1
- data/spec/ramaze/cache/memcache.rb +7 -1
- data/spec/ramaze/cache/sequel.rb +1 -1
- data/spec/ramaze/controller/actionless_templates.rb +2 -2
- data/spec/ramaze/controller/lonely_mapping.rb +18 -0
- data/spec/ramaze/controller/mapping.rb +4 -15
- data/spec/ramaze/controller/provide_inheritance.rb +5 -2
- data/spec/ramaze/controller/resolve.rb +2 -2
- data/spec/ramaze/controller/subclass.rb +2 -2
- data/spec/ramaze/controller/template_resolving.rb +2 -2
- data/spec/ramaze/dispatcher/directory.rb +5 -2
- data/spec/ramaze/dispatcher/file.rb +28 -26
- data/spec/ramaze/error.rb +3 -3
- data/spec/ramaze/files.rb +5 -2
- data/spec/ramaze/gestalt.rb +26 -17
- data/spec/ramaze/helper/auth.rb +30 -41
- data/spec/ramaze/helper/bench.rb +6 -2
- data/spec/ramaze/helper/cache.rb +45 -5
- data/spec/ramaze/helper/flash.rb +11 -15
- data/spec/ramaze/helper/form.rb +6 -3
- data/spec/ramaze/helper/formatting.rb +4 -1
- data/spec/ramaze/helper/gestalt.rb +4 -1
- data/spec/ramaze/helper/gravatar.rb +4 -1
- data/spec/ramaze/helper/httpdigest.rb +51 -66
- data/spec/ramaze/helper/layout.rb +79 -0
- data/spec/ramaze/helper/layout/default.xhtml +5 -0
- data/spec/ramaze/helper/link.rb +33 -12
- data/spec/ramaze/helper/localize.rb +9 -4
- data/spec/ramaze/helper/maruku.rb +5 -2
- data/spec/ramaze/helper/pager.rb +2 -2
- data/spec/ramaze/helper/paginate.rb +5 -2
- data/spec/ramaze/helper/request_accessor.rb +5 -2
- data/spec/ramaze/helper/sequel_form.rb +7 -2
- data/spec/ramaze/helper/simple_captcha.rb +10 -14
- data/spec/ramaze/helper/stack.rb +32 -40
- data/spec/ramaze/helper/user.rb +19 -14
- data/spec/ramaze/helper/xhtml.rb +4 -1
- data/spec/ramaze/log/informer.rb +1 -1
- data/spec/ramaze/log/logging.rb +4 -1
- data/spec/ramaze/log/syslog.rb +6 -6
- data/spec/ramaze/params.rb +5 -6
- data/spec/ramaze/request.rb +16 -1
- data/spec/ramaze/session/memcache.rb +66 -0
- data/spec/ramaze/struct.rb +4 -1
- data/spec/ramaze/view.rb +2 -2
- data/spec/ramaze/view/erubis.rb +2 -2
- data/spec/ramaze/view/ezamar.rb +2 -2
- data/spec/ramaze/view/gestalt.rb +94 -0
- data/spec/ramaze/view/gestalt/external.ges +8 -0
- data/spec/ramaze/view/haml.rb +2 -2
- data/spec/ramaze/view/liquid.rb +2 -2
- data/spec/ramaze/view/nagoro.rb +2 -2
- data/spec/ramaze/view/redcloth.rb +2 -2
- data/spec/ramaze/view/remarkably.rb +2 -2
- data/spec/ramaze/view/sass.rb +2 -2
- data/spec/ramaze/view/tagz.rb +2 -2
- data/spec/ramaze/view/tenjin.rb +2 -2
- data/spec/snippets/array/put_within.rb +30 -25
- data/spec/snippets/binding/locals.rb +4 -1
- data/spec/snippets/numeric/filesize_format.rb +4 -1
- data/spec/snippets/numeric/time.rb +5 -2
- data/spec/snippets/object/__dir__.rb +4 -1
- data/spec/snippets/ordered_set.rb +4 -1
- data/spec/snippets/ramaze/acquire.rb +4 -1
- data/spec/snippets/ramaze/dictionary.rb +4 -1
- data/spec/snippets/ramaze/struct.rb +4 -1
- data/spec/snippets/string/camel_case.rb +4 -1
- data/spec/snippets/string/color.rb +4 -1
- data/spec/snippets/string/snake_case.rb +4 -1
- data/spec/snippets/string/unindent.rb +4 -1
- data/spec/snippets/thread/into.rb +4 -1
- data/tasks/bacon.rake +5 -3
- data/tasks/changelog.rake +3 -1
- data/tasks/{gem_installer.rake → gem_setup.rake} +45 -22
- data/tasks/release.rake +12 -27
- data/tasks/setup.rake +6 -0
- data/tasks/todo.rake +2 -4
- metadata +205 -31
- data/CHANGELOG +0 -16546
- data/benchmark/suite/template_builder.rb +0 -12
- data/doc/tutorial/todolist.mkd +0 -787
- data/examples/helpers/provide.rb +0 -23
- data/lib/proto/view/page.xhtml +0 -27
- data/lib/ramaze/snippets/divide.rb +0 -22
- data/lib/ramaze/snippets/kernel/constant.rb +0 -41
- data/lib/ramaze/snippets/object/acquire.rb +0 -37
- data/lib/ramaze/snippets/string/each.rb +0 -19
- data/spec/ramaze/helper/partial.rb +0 -40
- data/spec/snippets/kernel/constant.rb +0 -23
- data/tasks/install_dependencies.rake +0 -6
data/lib/proto/app.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file contains your application, it requires dependencies and necessary
|
2
|
+
# parts of the application.
|
3
|
+
#
|
4
|
+
# It will be required from either `config.ru` or `start.rb`
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'ramaze'
|
8
|
+
|
9
|
+
# Make sure that Ramaze knows where you are
|
10
|
+
Ramaze.options.roots = [__DIR__]
|
11
|
+
|
12
|
+
# Initialize controllers and models
|
13
|
+
require __DIR__('model/init')
|
14
|
+
require __DIR__('controller/init')
|
data/lib/proto/config.ru
CHANGED
@@ -8,10 +8,13 @@
|
|
8
8
|
# Rack::Builder DSL to configure middleware and build up applications easily.
|
9
9
|
#
|
10
10
|
# rackup automatically figures out the environment it is run in, and runs your
|
11
|
-
# application as FastCGI, CGI, or standalone with Mongrel or WEBrick
|
11
|
+
# application as FastCGI, CGI, or standalone with Mongrel or WEBrick -- all from
|
12
12
|
# the same configuration.
|
13
|
+
#
|
14
|
+
# Do not set the adapter.handler in here, it will be ignored.
|
15
|
+
# You can choose the adapter like `ramaze start -s mongrel` or set it in the
|
16
|
+
# 'start.rb' and use `ruby start.rb` instead.
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
Ramaze
|
17
|
-
run Innate
|
18
|
+
require ::File.expand_path('../app', __FILE__)
|
19
|
+
Ramaze.start(:root => __DIR__, :started => true)
|
20
|
+
run Ramaze
|
@@ -2,10 +2,10 @@
|
|
2
2
|
# controllers
|
3
3
|
|
4
4
|
class Controller < Ramaze::Controller
|
5
|
-
layout
|
5
|
+
layout :default
|
6
6
|
helper :xhtml
|
7
|
-
engine :
|
7
|
+
engine :Etanni
|
8
8
|
end
|
9
9
|
|
10
10
|
# Here go your requires for subclasses of Controller:
|
11
|
-
require '
|
11
|
+
require __DIR__('main')
|
data/lib/proto/spec/main.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
require 'ramaze'
|
2
|
-
require 'ramaze/spec'
|
2
|
+
require 'ramaze/spec/bacon'
|
3
3
|
|
4
|
-
require __DIR__('../
|
4
|
+
require __DIR__('../app')
|
5
5
|
|
6
6
|
describe MainController do
|
7
|
-
behaves_like :
|
7
|
+
behaves_like :rack_test
|
8
8
|
|
9
9
|
should 'show start page' do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
got.body.should =~ /<h1>Welcome to Ramaze!<\/h1>/
|
10
|
+
get('/').status.should == 200
|
11
|
+
last_response['Content-Type'].should == 'text/html'
|
12
|
+
last_response.should =~ /<h1>Welcome to Ramaze!<\/h1>/
|
14
13
|
end
|
15
14
|
|
16
15
|
should 'show /notemplate' do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
got.body.should =~ /there is no 'notemplate.xhtml' associated with this action/
|
16
|
+
get('/notemplate').status.should == 200
|
17
|
+
last_response['Content-Type'].should == 'text/html'
|
18
|
+
last_response.should =~ /there is no 'notemplate\.xhtml' associated with this action/
|
21
19
|
end
|
22
20
|
end
|
data/lib/proto/start.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Use this file directly like `ruby start.rb` if you don't want to use the
|
2
|
+
# `ramaze start` command.
|
3
|
+
# All application related things should go into `app.rb`, this file is simply
|
4
|
+
# for options related to running the application locally.
|
3
5
|
|
4
|
-
|
5
|
-
# app from any other working directory
|
6
|
-
$LOAD_PATH.unshift(__DIR__)
|
6
|
+
require File.expand_path('app', File.dirname(__FILE__))
|
7
7
|
|
8
|
-
|
9
|
-
require 'controller/init'
|
10
|
-
require 'model/init'
|
11
|
-
|
12
|
-
Ramaze.start(:adapter => :webrick, :port => 7000) if __FILE__ == $0
|
8
|
+
Ramaze.start(:adapter => :webrick, :port => 7000, :file => __FILE__)
|
data/lib/ramaze.rb
CHANGED
@@ -62,25 +62,24 @@ module Ramaze
|
|
62
62
|
|
63
63
|
middleware! :dev do |m|
|
64
64
|
m.use Rack::Lint
|
65
|
-
m.use Rack::CommonLogger
|
66
|
-
m.use
|
65
|
+
m.use Rack::CommonLogger, Ramaze::Log
|
66
|
+
m.use Rack::ShowExceptions
|
67
67
|
m.use Rack::ShowStatus
|
68
68
|
m.use Rack::RouteExceptions
|
69
|
-
m.use Rack::ShowExceptions
|
70
|
-
m.use Rack::Head
|
71
|
-
m.use Rack::ETag
|
72
69
|
m.use Rack::ConditionalGet
|
70
|
+
m.use Rack::ETag
|
71
|
+
m.use Rack::Head
|
72
|
+
m.use Ramaze::Reloader
|
73
73
|
m.run Ramaze::AppMap
|
74
74
|
end
|
75
75
|
|
76
76
|
middleware! :live do |m|
|
77
|
-
m.use Rack::CommonLogger
|
77
|
+
m.use Rack::CommonLogger, Ramaze::Log
|
78
78
|
m.use Rack::RouteExceptions
|
79
79
|
m.use Rack::ShowStatus
|
80
|
-
m.use Rack::ShowExceptions
|
81
|
-
m.use Rack::Head
|
82
|
-
m.use Rack::ETag
|
83
80
|
m.use Rack::ConditionalGet
|
81
|
+
m.use Rack::ETag
|
82
|
+
m.use Rack::Head
|
84
83
|
m.run Ramaze::AppMap
|
85
84
|
end
|
86
85
|
end
|
data/lib/ramaze/app.rb
CHANGED
@@ -70,10 +70,10 @@ module Ramaze
|
|
70
70
|
|
71
71
|
attr_reader :name, :location, :url_map, :options
|
72
72
|
|
73
|
-
def initialize(name, location)
|
73
|
+
def initialize(name, location = nil)
|
74
74
|
@name = name.to_sym
|
75
75
|
@url_map = Innate::URLMap.new
|
76
|
-
self.location = location
|
76
|
+
self.location = location if location
|
77
77
|
|
78
78
|
APP_LIST[@name] = self
|
79
79
|
|
@@ -113,7 +113,8 @@ module Ramaze
|
|
113
113
|
roots.map{|root| publics.map{|public| ::File.join(root, public) }}.flatten
|
114
114
|
end
|
115
115
|
|
116
|
-
def self.find_or_create(name, location =
|
116
|
+
def self.find_or_create(name, location = nil)
|
117
|
+
location = '/' if location.nil? && name == :pristine
|
117
118
|
self[name] || new(name, location)
|
118
119
|
end
|
119
120
|
|
@@ -31,11 +31,11 @@ module Ramaze
|
|
31
31
|
|
32
32
|
# Wipe out _all_ data in localmemcached, use with care.
|
33
33
|
def cache_clear
|
34
|
-
|
34
|
+
@store.clear
|
35
35
|
end
|
36
36
|
|
37
37
|
def cache_delete(*args)
|
38
|
-
super{|key| @store.delete(key.to_s) }
|
38
|
+
super{|key| @store.delete(key.to_s); nil }
|
39
39
|
end
|
40
40
|
|
41
41
|
# NOTE:
|
@@ -13,7 +13,20 @@ module Ramaze
|
|
13
13
|
#
|
14
14
|
# It is highly recommended to install memcache-client_extensions for
|
15
15
|
# a bit of speedup and more functionality
|
16
|
+
#
|
17
|
+
# NOTE: There is a big issue with persisting sessions in memcache, not only
|
18
|
+
# can they be dropped at any time, essentially logging the user out
|
19
|
+
# without them noticing, but there is also a low limit to the maximum
|
20
|
+
# time-to-live. After 30 days, your session will be dropped, no
|
21
|
+
# matter what.
|
22
|
+
# Please remember that memcache is, first of all, a cache, not a
|
23
|
+
# persistence mechanism.
|
24
|
+
#
|
25
|
+
# NOTE: If you try to set a higher ttl than allowed, your stored key/value
|
26
|
+
# will be expired immediately.
|
16
27
|
class MemCache
|
28
|
+
MAX_TTL = 2592000
|
29
|
+
|
17
30
|
include Cache::API
|
18
31
|
|
19
32
|
# +:multithread+: May be turned off at your own risk.
|
@@ -34,6 +47,7 @@ module Ramaze
|
|
34
47
|
options = {:namespace => @namespace}.merge(OPTIONS)
|
35
48
|
servers = options.delete(:servers)
|
36
49
|
@store = ::MemCache.new(servers, options)
|
50
|
+
@warned = false
|
37
51
|
end
|
38
52
|
|
39
53
|
# Wipe out _all_ data in memcached, use with care.
|
@@ -46,7 +60,7 @@ module Ramaze
|
|
46
60
|
|
47
61
|
#
|
48
62
|
def cache_delete(*keys)
|
49
|
-
super{|key| @store.delete(key) }
|
63
|
+
super{|key| @store.delete(key); nil }
|
50
64
|
rescue ::MemCache::MemCacheError => e
|
51
65
|
Log.error(e)
|
52
66
|
nil
|
@@ -65,6 +79,17 @@ module Ramaze
|
|
65
79
|
|
66
80
|
def cache_store(key, value, options = {})
|
67
81
|
ttl = options[:ttl] || 0
|
82
|
+
|
83
|
+
if ttl > MAX_TTL
|
84
|
+
unless @warned
|
85
|
+
Log.warn('MemCache cannot set a ttl greater than 2592000 seconds.')
|
86
|
+
Log.warn('Modify Ramaze.options.session.ttl to a value <= of that.')
|
87
|
+
@warned = true
|
88
|
+
end
|
89
|
+
|
90
|
+
ttl = MAX_TTL
|
91
|
+
end
|
92
|
+
|
68
93
|
@store.set(key, value, ttl)
|
69
94
|
value
|
70
95
|
rescue ::MemCache::MemCacheError => e
|
data/lib/ramaze/cache/sequel.rb
CHANGED
@@ -1,38 +1,53 @@
|
|
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
|
+
require 'sequel'
|
5
|
+
|
4
6
|
module Ramaze
|
5
7
|
class Cache
|
6
8
|
|
7
9
|
# Cache based on a Sequel model using relational databases.
|
10
|
+
#
|
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.
|
8
14
|
class Sequel
|
9
15
|
include Cache::API
|
10
16
|
|
11
17
|
class Table < ::Sequel::Model(:ramaze_cache)
|
18
|
+
plugin :schema
|
19
|
+
plugin :serialization
|
20
|
+
|
21
|
+
serialize_attributes :marshal, :value
|
22
|
+
|
12
23
|
set_schema do
|
13
24
|
primary_key :id
|
14
|
-
string :key
|
15
|
-
string :value
|
16
|
-
time :expires
|
17
25
|
index :key, :unique => true
|
26
|
+
|
27
|
+
String :key
|
28
|
+
String :value
|
29
|
+
Time :expires
|
18
30
|
end
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
32
|
+
def [](column)
|
33
|
+
if column == :value
|
34
|
+
deserialized_values[column] = deserialize_value(column, @values[column])
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
24
39
|
end
|
25
40
|
|
26
41
|
# Setup the table, not suitable for multiple apps yet.
|
27
42
|
def cache_setup(host, user, app, name)
|
28
43
|
@namespace = [host, user, app, name].compact.join(':')
|
29
|
-
Table.create_table
|
44
|
+
Table.create_table?
|
30
45
|
@store = Table
|
31
46
|
end
|
32
47
|
|
33
48
|
# Wipe out _all_ data in the table, use with care.
|
34
49
|
def cache_clear
|
35
|
-
Table.
|
50
|
+
Table.delete
|
36
51
|
end
|
37
52
|
|
38
53
|
# Delete records for given +keys+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "addressable/template"
|
2
|
+
|
3
|
+
module Ramaze
|
4
|
+
# This is a simple prototype-implementation of how we could do routing
|
5
|
+
# supported by URI templates.
|
6
|
+
#
|
7
|
+
# Please see the spec for example usage as it's not integrated yet in any way.
|
8
|
+
#
|
9
|
+
# What it does is basically that you can give it any URI template and a final
|
10
|
+
# mapping, and it will extract the variables from the URI and merge them into
|
11
|
+
# the QUERY_STRING, which is parsed again in Ramaze if you issue
|
12
|
+
# Request#params.
|
13
|
+
#
|
14
|
+
# @example given mapping like:
|
15
|
+
#
|
16
|
+
# map('/customer/{customer_id}/order/{order_id}', '/order/show')
|
17
|
+
#
|
18
|
+
# @example output of request.params at '/order/show'
|
19
|
+
#
|
20
|
+
# {'customer_id => '12', 'order_id' => '15'}
|
21
|
+
#
|
22
|
+
# I haven't explored the full capabilities of the templates yet, but the
|
23
|
+
# specs of Addressable::Template suggest that there is a lot to be
|
24
|
+
# discovered.
|
25
|
+
class AddressableRoute
|
26
|
+
def initialize(app, routes = {})
|
27
|
+
@app = app
|
28
|
+
@routes = {}
|
29
|
+
|
30
|
+
routes.each{|from, to| map(from, to) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def call(env)
|
34
|
+
path_info = env['PATH_INFO']
|
35
|
+
|
36
|
+
@routes.each do |template, target|
|
37
|
+
extracted = template.extract(path_info)
|
38
|
+
return dispatch(env, target, extracted) if extracted
|
39
|
+
end
|
40
|
+
|
41
|
+
@app.call(env)
|
42
|
+
end
|
43
|
+
|
44
|
+
def map(from, to)
|
45
|
+
@routes[Addressable::Template.new(from)] = to
|
46
|
+
end
|
47
|
+
|
48
|
+
def dispatch(env, target, extracted)
|
49
|
+
env['PATH_INFO'] = target
|
50
|
+
original = Rack::Utils.parse_query(env['QUERY_STRING'])
|
51
|
+
env['QUERY_STRING'] = Rack::Utils.build_query(original.merge(extracted))
|
52
|
+
|
53
|
+
@app.call(env)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/ramaze/contrib/email.rb
CHANGED
@@ -59,9 +59,9 @@ module Facebook
|
|
59
59
|
end while ret.empty? and @server = connect
|
60
60
|
|
61
61
|
ret = case
|
62
|
-
when ret == 'true'
|
63
|
-
when ret == 'false'
|
64
|
-
when ret[0..0] == '"'
|
62
|
+
when ret == 'true'; true
|
63
|
+
when ret == 'false'; false
|
64
|
+
when ret[0..0] == '"'; ret[1..-2]
|
65
65
|
else
|
66
66
|
begin
|
67
67
|
JSON::parse(ret)
|
@@ -168,4 +168,4 @@ module Facebook
|
|
168
168
|
buf
|
169
169
|
end
|
170
170
|
end
|
171
|
-
end
|
171
|
+
end
|
@@ -94,14 +94,14 @@ class FormField
|
|
94
94
|
select(gestalt)
|
95
95
|
else
|
96
96
|
case db_type
|
97
|
-
when
|
97
|
+
when /varchar|integer/
|
98
98
|
input(gestalt)
|
99
|
-
when
|
99
|
+
when /boolean/
|
100
100
|
checkbox(gestalt)
|
101
|
-
when
|
101
|
+
when /string/
|
102
102
|
textarea(gestalt)
|
103
103
|
else
|
104
|
-
raise
|
104
|
+
raise("Unsupported type: (%p : %p)" % [db_type || hint, field])
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
# Usage:
|
8
8
|
# class Avatar < Sequel::Model
|
9
9
|
# IMAGE = {
|
10
|
-
# # specifies
|
10
|
+
# # specifies many_to_one, will create relation and foreign key
|
11
11
|
#
|
12
12
|
# :owner => :User,
|
13
13
|
#
|
@@ -51,8 +51,8 @@
|
|
51
51
|
module SequelImage
|
52
52
|
def self.included(model)
|
53
53
|
args = model::IMAGE
|
54
|
-
set_foreign_key = args[:foreign_key]
|
55
|
-
|
54
|
+
set_foreign_key = args[:foreign_key] || "#{args[:owner]}_id".downcase.to_sym
|
55
|
+
set_many_to_one = args[:many_to_one] || args[:owner].to_s.downcase.to_sym
|
56
56
|
|
57
57
|
# Define schema
|
58
58
|
model.set_schema do
|
@@ -68,21 +68,19 @@ module SequelImage
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Define Relations
|
71
|
-
model.
|
71
|
+
model.many_to_one set_many_to_one
|
72
72
|
|
73
73
|
# Define Hooks
|
74
|
-
model.
|
75
|
-
|
76
|
-
model.before_create do
|
74
|
+
model.before_create :generate_thumbnails do
|
77
75
|
generate_thumbnails
|
78
76
|
self.created_at = Time.now
|
79
77
|
end
|
80
78
|
|
81
|
-
model.before_save do
|
79
|
+
model.before_save :update_time do
|
82
80
|
self.updated_at = Time.now
|
83
81
|
end
|
84
82
|
|
85
|
-
model.before_destroy do
|
83
|
+
model.before_destroy :cleanup do
|
86
84
|
cleanup if conf[:cleanup]
|
87
85
|
end
|
88
86
|
|
@@ -110,7 +108,7 @@ module SequelImage
|
|
110
108
|
tempfile = file[:tempfile]
|
111
109
|
raise ArgumentError, 'Empty tempfile' if tempfile.size == 0
|
112
110
|
|
113
|
-
ext =
|
111
|
+
ext = Rack::Mime::MIME_TYPES.invert[type]
|
114
112
|
image.mime = type
|
115
113
|
target_name = image.next_name(File.basename(filename, File.extname(filename)), ext)
|
116
114
|
target_path = File.join(image.public_root, image.path, target_name)
|
@@ -150,7 +148,7 @@ module SequelImage
|
|
150
148
|
end
|
151
149
|
|
152
150
|
def public_root
|
153
|
-
Ramaze
|
151
|
+
Ramaze.options.roots.first
|
154
152
|
end
|
155
153
|
|
156
154
|
def filename(size)
|