ramaze 2011.01.30 → 2011.07.25
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/.mailmap +2 -0
- data/.rvmrc +1 -0
- data/README.md +119 -197
- data/Rakefile +14 -97
- data/bin/ramaze +6 -14
- data/doc/AUTHORS +8 -4
- data/doc/CHANGELOG +3784 -3339
- data/examples/app/chat/start.rb +2 -2
- data/lib/proto/app.rb +2 -3
- data/lib/proto/config.ru +4 -5
- data/lib/proto/controller/init.rb +11 -4
- data/lib/proto/controller/main.rb +12 -7
- data/lib/proto/layout/default.xhtml +56 -23
- data/lib/proto/model/init.rb +3 -1
- data/lib/proto/public/css/grid.css +107 -0
- data/lib/proto/public/css/layout.css +81 -0
- data/lib/proto/public/css/reset.css +123 -0
- data/lib/proto/public/css/text.css +109 -0
- data/lib/proto/public/images/bg.png +0 -0
- data/lib/proto/spec/main.rb +2 -2
- data/lib/proto/start.rb +11 -1
- data/lib/proto/view/index.xhtml +27 -23
- data/lib/ramaze.rb +0 -1
- data/lib/ramaze/app.rb +85 -12
- data/lib/ramaze/app_graph.rb +107 -0
- data/lib/ramaze/bin/console.rb +87 -0
- data/lib/ramaze/bin/create.rb +94 -0
- data/lib/ramaze/bin/helper.rb +107 -0
- data/lib/ramaze/bin/restart.rb +95 -0
- data/lib/ramaze/bin/runner.rb +141 -0
- data/lib/ramaze/bin/start.rb +206 -0
- data/lib/ramaze/bin/status.rb +152 -0
- data/lib/ramaze/bin/stop.rb +112 -0
- data/lib/ramaze/cache.rb +9 -4
- data/lib/ramaze/cache/localmemcache.rb +10 -13
- data/lib/ramaze/cache/lru.rb +49 -7
- data/lib/ramaze/cache/memcache.rb +170 -92
- data/lib/ramaze/cache/sequel.rb +301 -118
- data/lib/ramaze/controller.rb +108 -9
- data/lib/ramaze/controller/default.rb +15 -2
- data/lib/ramaze/current.rb +14 -2
- data/lib/ramaze/dependencies.rb +46 -0
- data/lib/ramaze/files.rb +38 -3
- data/lib/ramaze/gestalt.rb +12 -12
- data/lib/ramaze/helper.rb +0 -2
- data/lib/ramaze/helper/auth.rb +30 -23
- data/lib/ramaze/helper/blue_form.rb +175 -126
- data/lib/ramaze/helper/csrf.rb +76 -91
- data/lib/ramaze/helper/email.rb +105 -0
- data/lib/ramaze/helper/erector.rb +16 -15
- data/lib/ramaze/helper/gestalt.rb +2 -2
- data/lib/ramaze/helper/layout.rb +89 -73
- data/lib/ramaze/helper/link.rb +7 -6
- data/lib/ramaze/helper/localize.rb +6 -5
- data/lib/ramaze/helper/markaby.rb +25 -23
- data/lib/ramaze/helper/maruku.rb +3 -3
- data/lib/ramaze/helper/paginate.rb +19 -27
- data/lib/ramaze/helper/remarkably.rb +3 -3
- data/lib/ramaze/helper/request_accessor.rb +3 -3
- data/lib/ramaze/helper/send_file.rb +12 -8
- data/lib/ramaze/helper/simple_captcha.rb +5 -6
- data/lib/ramaze/helper/stack.rb +7 -4
- data/lib/ramaze/helper/tagz.rb +10 -11
- data/lib/ramaze/helper/thread.rb +19 -16
- data/lib/ramaze/helper/ultraviolet.rb +7 -4
- data/lib/ramaze/helper/user.rb +40 -21
- data/lib/ramaze/helper/xhtml.rb +29 -20
- data/lib/ramaze/log.rb +3 -11
- data/lib/ramaze/log/analogger.rb +5 -4
- data/lib/ramaze/log/growl.rb +9 -7
- data/lib/ramaze/log/hub.rb +3 -5
- data/lib/ramaze/log/informer.rb +15 -12
- data/lib/ramaze/log/knotify.rb +3 -5
- data/lib/ramaze/log/logger.rb +3 -5
- data/lib/ramaze/log/logging.rb +6 -8
- data/lib/ramaze/log/rotatinginformer.rb +27 -17
- data/lib/ramaze/log/syslog.rb +7 -7
- data/lib/ramaze/log/xosd.rb +3 -5
- data/lib/ramaze/middleware_compiler.rb +27 -4
- data/lib/ramaze/reloader.rb +50 -12
- data/lib/ramaze/reloader/watch_inotify.rb +4 -5
- data/lib/ramaze/reloader/watch_stat.rb +3 -3
- data/lib/ramaze/request.rb +18 -8
- data/lib/ramaze/response.rb +38 -7
- data/lib/ramaze/rest.rb +36 -0
- data/lib/ramaze/setup.rb +101 -31
- data/lib/ramaze/spec.rb +1 -1
- data/lib/ramaze/spec/bacon.rb +6 -3
- data/lib/ramaze/spec/helper/bacon.rb +0 -1
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view.rb +2 -11
- data/lib/ramaze/view/erector.rb +46 -31
- data/lib/ramaze/view/erubis.rb +7 -3
- data/lib/ramaze/view/ezamar.rb +7 -3
- data/lib/ramaze/view/gestalt.rb +9 -3
- data/lib/ramaze/view/haml.rb +7 -3
- data/lib/ramaze/view/liquid.rb +3 -3
- data/lib/ramaze/view/lokar.rb +7 -3
- data/lib/ramaze/view/mustache.rb +11 -5
- data/lib/ramaze/view/nagoro.rb +3 -3
- data/lib/ramaze/view/sass.rb +1 -1
- data/lib/ramaze/view/slippers.rb +40 -13
- data/lib/ramaze/view/tagz.rb +9 -5
- data/ramaze.gemspec +23 -128
- data/spec/helper.rb +5 -0
- data/spec/ramaze/bin/app/config.ru +11 -0
- data/spec/ramaze/bin/create.rb +28 -0
- data/spec/ramaze/bin/runner.rb +30 -0
- data/spec/ramaze/bin/start.rb +38 -0
- data/spec/ramaze/cache/memcache.rb +10 -3
- data/spec/ramaze/cache/sequel.rb +7 -0
- data/spec/ramaze/controller/provide_inheritance.rb +0 -10
- data/spec/ramaze/dispatcher/file.rb +19 -15
- data/spec/ramaze/helper/auth.rb +10 -9
- data/spec/ramaze/helper/blue_form.rb +121 -68
- data/spec/ramaze/helper/email.rb +69 -0
- data/spec/ramaze/helper/layout.rb +12 -15
- data/spec/ramaze/helper/layout/alternative.xhtml +5 -0
- data/spec/ramaze/helper/user.rb +2 -0
- data/spec/ramaze/log/growl.rb +14 -1
- data/spec/{contrib → ramaze}/rest.rb +1 -1
- data/spec/ramaze/session/memcache.rb +2 -2
- data/spec/ramaze/view/sass.rb +1 -1
- data/tasks/bacon.rake +3 -3
- data/tasks/gem.rake +17 -18
- data/tasks/rcov.rake +2 -3
- data/tasks/release.rake +8 -65
- data/tasks/setup.rake +10 -8
- data/tasks/todo.rake +9 -5
- data/tasks/yard.rake +3 -2
- metadata +105 -397
- data/MANIFEST +0 -532
- data/TODO.md +0 -19
- data/benchmark/bench_templates/bench.rb +0 -67
- data/benchmark/bench_templates/view/large.erb +0 -79
- data/benchmark/bench_templates/view/large.haml +0 -41
- data/benchmark/bench_templates/view/large.lok +0 -79
- data/benchmark/bench_templates/view/large.xhtml +0 -79
- data/benchmark/bench_templates/view/small.erb +0 -21
- data/benchmark/bench_templates/view/small.haml +0 -12
- data/benchmark/bench_templates/view/small.lok +0 -21
- data/benchmark/bench_templates/view/small.xhtml +0 -21
- data/benchmark/results.txt +0 -131
- data/benchmark/run.rb +0 -355
- data/benchmark/suite/minimal.rb +0 -11
- data/benchmark/suite/no_informer.rb +0 -7
- data/benchmark/suite/no_sessions.rb +0 -9
- data/benchmark/suite/no_template.rb +0 -7
- data/benchmark/suite/simple.rb +0 -5
- data/benchmark/suite/template_erubis.rb +0 -8
- data/benchmark/suite/template_etanni.rb +0 -8
- data/benchmark/suite/template_ezamar.rb +0 -8
- data/benchmark/suite/template_haml.rb +0 -13
- data/benchmark/suite/template_liquid.rb +0 -11
- data/benchmark/suite/template_markaby.rb +0 -9
- data/benchmark/suite/template_nagoro.rb +0 -8
- data/benchmark/suite/template_redcloth.rb +0 -13
- data/benchmark/suite/template_tenjin.rb +0 -8
- data/benchmark/test.rb +0 -35
- data/doc/FAQ +0 -92
- data/doc/INSTALL +0 -92
- data/doc/TODO +0 -29
- data/doc/meta/announcement.txt +0 -119
- data/doc/meta/configuration.txt +0 -163
- data/doc/meta/internals.txt +0 -278
- data/doc/meta/users.kml +0 -64
- data/doc/tutorial/todolist.html +0 -1512
- data/doc/tutorial/todolist.txt +0 -920
- data/examples/app/sourceview/public/coderay.css +0 -104
- data/examples/app/sourceview/public/images/file.gif +0 -0
- data/examples/app/sourceview/public/images/folder.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/app/sourceview/public/images/tv-item.gif +0 -0
- data/examples/app/sourceview/public/jquery.js +0 -11
- data/examples/app/sourceview/public/jquery.treeview.css +0 -48
- data/examples/app/sourceview/public/jquery.treeview.js +0 -223
- data/examples/app/sourceview/public/sourceview.js +0 -52
- data/examples/app/sourceview/start.rb +0 -79
- data/examples/app/sourceview/view/index.haml +0 -59
- data/examples/helpers/httpdigest.rb +0 -107
- data/lib/proto/public/css/screen.css +0 -30
- data/lib/proto/public/js/jquery.js +0 -7179
- data/lib/ramaze/contrib/addressable_route.rb +0 -56
- data/lib/ramaze/contrib/app_graph.rb +0 -64
- data/lib/ramaze/contrib/email.rb +0 -88
- data/lib/ramaze/contrib/facebook.rb +0 -23
- data/lib/ramaze/contrib/facebook/facebook.rb +0 -171
- data/lib/ramaze/contrib/gettext.rb +0 -113
- data/lib/ramaze/contrib/gettext/mo.rb +0 -155
- data/lib/ramaze/contrib/gettext/parser.rb +0 -46
- data/lib/ramaze/contrib/gettext/po.rb +0 -109
- data/lib/ramaze/contrib/gzip_filter.rb +0 -1
- data/lib/ramaze/contrib/maruku_uv.rb +0 -59
- data/lib/ramaze/contrib/profiling.rb +0 -36
- data/lib/ramaze/contrib/rest.rb +0 -23
- data/lib/ramaze/contrib/sequel/create_join.rb +0 -26
- data/lib/ramaze/contrib/sequel/form_field.rb +0 -129
- data/lib/ramaze/contrib/sequel/image.rb +0 -196
- data/lib/ramaze/contrib/sequel/relation.rb +0 -98
- data/lib/ramaze/helper/httpdigest.rb +0 -96
- data/lib/ramaze/tool/bin.rb +0 -340
- data/lib/ramaze/tool/create.rb +0 -48
- data/lib/ramaze/tool/project_creator.rb +0 -120
- data/lib/ramaze/view/less.rb +0 -12
- data/lib/ramaze/view/maruku.rb +0 -15
- data/lib/ramaze/view/redcloth.rb +0 -21
- data/spec/contrib/addressable_route.rb +0 -30
- data/spec/examples/helpers/httpdigest.rb +0 -64
- data/spec/examples/templates/template_redcloth.rb +0 -13
- data/spec/ramaze/bin/ramaze.rb +0 -96
- data/spec/ramaze/helper/httpdigest.rb +0 -176
- data/spec/ramaze/view/less.rb +0 -60
- data/spec/ramaze/view/less/file.css.less +0 -8
- data/spec/ramaze/view/redcloth.rb +0 -66
- data/spec/ramaze/view/redcloth/external.redcloth +0 -8
- data/tasks/copyright.rake +0 -21
- data/tasks/gem_setup.rake +0 -112
- data/tasks/git.rake +0 -46
- data/tasks/grancher.rake +0 -12
- data/tasks/jquery.rake +0 -15
- data/tasks/manifest.rake +0 -4
- data/tasks/metric_changes.rake +0 -24
- data/tasks/reversion.rake +0 -8
- data/tasks/traits.rake +0 -21
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'ramaze/gestalt'
|
2
|
-
|
3
|
-
# job = Job[4]
|
4
|
-
# puts CGI::pretty(FormField.new(job, :contract, show_errors = true, Job::CONTRACTS).to_s)
|
5
|
-
|
6
|
-
class FormField
|
7
|
-
attr_accessor :this, :field, :show_errors, :hint, :db_type, :id, :value
|
8
|
-
|
9
|
-
# show_errors may be a number indicating how many errors it should display at
|
10
|
-
# maximum, 0 displays none, -1 all
|
11
|
-
|
12
|
-
def initialize(this, field, show_errors = true, hint = nil)
|
13
|
-
@this, @field, @show_errors, @hint =
|
14
|
-
this, field.to_sym, show_errors, hint
|
15
|
-
@db_type = db_type
|
16
|
-
@id = "form_#{@field}"
|
17
|
-
@value = this.send(@field)
|
18
|
-
end
|
19
|
-
|
20
|
-
def db_type
|
21
|
-
if field_schema = this.class.db_schema[field]
|
22
|
-
field_schema[:db_type]
|
23
|
-
else
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_s
|
29
|
-
unless label = @this.class::FORM_LABEL[field]
|
30
|
-
raise("No FORM_LABEL for %p on %p" % [field, @this.class])
|
31
|
-
end
|
32
|
-
|
33
|
-
label += ':'
|
34
|
-
id = @id
|
35
|
-
_self = self
|
36
|
-
|
37
|
-
Ramaze::Gestalt.build{
|
38
|
-
div(:class => :pair){
|
39
|
-
label(:for => id){ label }
|
40
|
-
_self.build_tag(self)
|
41
|
-
_self.build_errors(self)
|
42
|
-
}
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
def password(gestalt)
|
47
|
-
gestalt.input(@args.merge :type => :password, :value => value)
|
48
|
-
end
|
49
|
-
|
50
|
-
def checkbox(gestalt)
|
51
|
-
@args[:checked] = :checked if value
|
52
|
-
gestalt.input(@args.merge :type => :checkbox)
|
53
|
-
end
|
54
|
-
|
55
|
-
def select(gestalt)
|
56
|
-
gestalt.select @args do
|
57
|
-
v = value.to_s
|
58
|
-
hint.each do |h|
|
59
|
-
h = h.to_s
|
60
|
-
if h == v
|
61
|
-
gestalt.option(:value => h, :selected => :selected){ h }
|
62
|
-
else
|
63
|
-
gestalt.option(:value => h){ h }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def input(gestalt)
|
70
|
-
gestalt.input(@args.merge :type => :text, :value => value)
|
71
|
-
end
|
72
|
-
|
73
|
-
def file(gestalt)
|
74
|
-
gestalt.input(@args.merge :type => :file)
|
75
|
-
end
|
76
|
-
|
77
|
-
def textarea(gestalt)
|
78
|
-
gestalt.textarea(@args){ value.to_s }
|
79
|
-
end
|
80
|
-
|
81
|
-
def build_tag(gestalt)
|
82
|
-
@args = {:id => id, :name => field}
|
83
|
-
|
84
|
-
case hint
|
85
|
-
when :password
|
86
|
-
password(gestalt)
|
87
|
-
when :boolean, :checkbox
|
88
|
-
checkbox(gestalt)
|
89
|
-
when :textarea
|
90
|
-
textarea(gestalt)
|
91
|
-
when :file
|
92
|
-
file(gestalt)
|
93
|
-
when Array, Range
|
94
|
-
select(gestalt)
|
95
|
-
else
|
96
|
-
case db_type
|
97
|
-
when /varchar|integer/
|
98
|
-
input(gestalt)
|
99
|
-
when /boolean/
|
100
|
-
checkbox(gestalt)
|
101
|
-
when /string/
|
102
|
-
textarea(gestalt)
|
103
|
-
else
|
104
|
-
raise("Unsupported type: (%p : %p)" % [db_type || hint, field])
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def build_errors(gestalt)
|
110
|
-
each_error do |error|
|
111
|
-
gestalt.span(:class => :error){ error }
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# TODO: suggest 'validated?' feature to sequel
|
116
|
-
def each_error(&block)
|
117
|
-
return unless show_errors
|
118
|
-
|
119
|
-
this.validate if this.errors.empty?
|
120
|
-
this.errors[field].first(show_errors).each(&block)
|
121
|
-
end
|
122
|
-
|
123
|
-
module Model
|
124
|
-
def form_field(field, hint = nil)
|
125
|
-
show_errors = Ramaze::Request.current.post? ? 1 : 0
|
126
|
-
FormField.new(self, field, show_errors, hint).to_s
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,196 +0,0 @@
|
|
1
|
-
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
-
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
-
|
4
|
-
# Scaffold image models utilizing thumbnailing and Ramaze integration.
|
5
|
-
# Resizing is done by ImageScience.
|
6
|
-
#
|
7
|
-
# Usage:
|
8
|
-
# class Avatar < Sequel::Model
|
9
|
-
# IMAGE = {
|
10
|
-
# # specifies many_to_one, will create relation and foreign key
|
11
|
-
#
|
12
|
-
# :owner => :User,
|
13
|
-
#
|
14
|
-
#
|
15
|
-
# # Remove original and thumbnails on Avatar#destroy
|
16
|
-
#
|
17
|
-
# :cleanup => true,
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# # Algorithm to use in ImageScience
|
21
|
-
# #
|
22
|
-
# # * resize(width, height)
|
23
|
-
# # Resizes the image to +width+ and +height+ using a cubic-bspline
|
24
|
-
# # filter.
|
25
|
-
# #
|
26
|
-
# # * thumbnail(size)
|
27
|
-
# # Creates a proportional thumbnail of the image scaled so its
|
28
|
-
# # longest edge is resized to +size+.
|
29
|
-
# #
|
30
|
-
# # * cropped_thumbnail(size)
|
31
|
-
# # Creates a square thumbnail of the image cropping the longest edge
|
32
|
-
# # to match the shortest edge, resizes to +size+.
|
33
|
-
#
|
34
|
-
# :algorithm => :thumbnail,
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# # Key specifies the filename and accessors, value are arguments to the
|
38
|
-
# # algorithm
|
39
|
-
#
|
40
|
-
# :sizes => {
|
41
|
-
# :small => 150,
|
42
|
-
# :medium => 300,
|
43
|
-
# :large => 600
|
44
|
-
# }
|
45
|
-
# }
|
46
|
-
#
|
47
|
-
# # Perform the scaffold
|
48
|
-
# include SequelImage
|
49
|
-
# end
|
50
|
-
|
51
|
-
module SequelImage
|
52
|
-
def self.included(model)
|
53
|
-
args = model::IMAGE
|
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
|
-
|
57
|
-
# Define schema
|
58
|
-
model.set_schema do
|
59
|
-
primary_key :id
|
60
|
-
|
61
|
-
varchar :original # path to the original image
|
62
|
-
varchar :mime, :size => 22 # average of /etc/mime.types
|
63
|
-
|
64
|
-
time :created_at
|
65
|
-
time :updated_at
|
66
|
-
|
67
|
-
foreign_key set_foreign_key
|
68
|
-
end
|
69
|
-
|
70
|
-
# Define Relations
|
71
|
-
model.many_to_one set_many_to_one
|
72
|
-
|
73
|
-
# Define Hooks
|
74
|
-
model.before_create :generate_thumbnails do
|
75
|
-
generate_thumbnails
|
76
|
-
self.created_at = Time.now
|
77
|
-
end
|
78
|
-
|
79
|
-
model.before_save :update_time do
|
80
|
-
self.updated_at = Time.now
|
81
|
-
end
|
82
|
-
|
83
|
-
model.before_destroy :cleanup do
|
84
|
-
cleanup if conf[:cleanup]
|
85
|
-
end
|
86
|
-
|
87
|
-
# Define singleton methods
|
88
|
-
model.extend(SingletonMethods)
|
89
|
-
|
90
|
-
# Define instance methods
|
91
|
-
model.send(:include,
|
92
|
-
InstanceMethods,
|
93
|
-
Ramaze::Helper::CGI,
|
94
|
-
Ramaze::Helper::Link)
|
95
|
-
|
96
|
-
args[:sizes].each do |size, *args|
|
97
|
-
model.send(:define_method, size){ public_file(size) }
|
98
|
-
model.send(:define_method, "#{size}_url"){ file(size) }
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
module SingletonMethods
|
103
|
-
def store(file, uid, hash = {})
|
104
|
-
image = new(hash)
|
105
|
-
|
106
|
-
type = file[:type]
|
107
|
-
filename = file[:filename]
|
108
|
-
tempfile = file[:tempfile]
|
109
|
-
raise ArgumentError, 'Empty tempfile' if tempfile.size == 0
|
110
|
-
|
111
|
-
ext = Rack::Mime::MIME_TYPES.invert[type]
|
112
|
-
image.mime = type
|
113
|
-
target_name = image.next_name(File.basename(filename, File.extname(filename)), ext)
|
114
|
-
target_path = File.join(image.public_root, image.path, target_name)
|
115
|
-
|
116
|
-
FileUtils.mkdir_p(File.dirname(target_path))
|
117
|
-
FileUtils.cp(tempfile.path, target_path)
|
118
|
-
|
119
|
-
image.original = target_path
|
120
|
-
image.save
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
module InstanceMethods
|
125
|
-
def file(size = nil)
|
126
|
-
File.join('/', path, filename(size))
|
127
|
-
end
|
128
|
-
|
129
|
-
def public_file(size)
|
130
|
-
File.join(public_path, filename(size))
|
131
|
-
end
|
132
|
-
|
133
|
-
def public_path
|
134
|
-
File.join(public_root, path)
|
135
|
-
end
|
136
|
-
|
137
|
-
def path
|
138
|
-
conf[:path] || conf[:owner].to_s.downcase
|
139
|
-
end
|
140
|
-
|
141
|
-
def next_name(uid, ext)
|
142
|
-
uid = uid.to_s.scan(%r![^\\/'".:?&;\s]+!).join('-')
|
143
|
-
"#{uid}#{ext}"
|
144
|
-
end
|
145
|
-
|
146
|
-
def basename
|
147
|
-
File.basename(original, File.extname(original))
|
148
|
-
end
|
149
|
-
|
150
|
-
def public_root
|
151
|
-
Ramaze.options.roots.first
|
152
|
-
end
|
153
|
-
|
154
|
-
def filename(size)
|
155
|
-
if size
|
156
|
-
"#{basename}_#{size}.png"
|
157
|
-
else
|
158
|
-
"#{basename}.png"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def conf
|
163
|
-
self.class::IMAGE
|
164
|
-
end
|
165
|
-
|
166
|
-
def cleanup
|
167
|
-
conf[:sizes].each do |name, args|
|
168
|
-
out = public_file(name)
|
169
|
-
Ramaze::Log.debug "Remove Thumbnail: #{out}"
|
170
|
-
FileUtils.rm_f(out)
|
171
|
-
end
|
172
|
-
|
173
|
-
Ramaze::Log.debug "Remove original: #{original}"
|
174
|
-
FileUtils.rm_f(original)
|
175
|
-
end
|
176
|
-
|
177
|
-
def generate_thumbnails
|
178
|
-
FileUtils.mkdir_p(public_path)
|
179
|
-
|
180
|
-
sizes, algorithm = conf.values_at(:sizes, :algorithm)
|
181
|
-
|
182
|
-
ImageScience.with_image(original) do |img|
|
183
|
-
Ramaze::Log.debug "Process original: #{original}"
|
184
|
-
|
185
|
-
sizes.each do |name, args|
|
186
|
-
out = public_file(name)
|
187
|
-
Ramaze::Log.debug "Generate Thumbnail: #{out}"
|
188
|
-
|
189
|
-
img.send(algorithm, *args) do |thumb|
|
190
|
-
thumb.save(out)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
-
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
-
|
4
|
-
# Pretty DSL to express Sequel relations
|
5
|
-
#
|
6
|
-
# Usage:
|
7
|
-
# SequelRelation.relations do
|
8
|
-
# the User do
|
9
|
-
# has_many Article
|
10
|
-
# has_one Avatar
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# the Article do
|
14
|
-
# belongs_to User
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# the Avatar do
|
18
|
-
# belongs_to User
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
|
22
|
-
module SequelRelation
|
23
|
-
def self.relations(&block)
|
24
|
-
rema = RelationshipManager.new(&block)
|
25
|
-
rema.finalize
|
26
|
-
end
|
27
|
-
|
28
|
-
class RelationshipManager
|
29
|
-
TODO = {}
|
30
|
-
|
31
|
-
def initialize(&block)
|
32
|
-
instance_eval(&block)
|
33
|
-
end
|
34
|
-
|
35
|
-
def finalize
|
36
|
-
TODO.keys.each do |model|
|
37
|
-
model.create_table unless model.table_exists?
|
38
|
-
end
|
39
|
-
|
40
|
-
TODO.each do |model, instructions|
|
41
|
-
instructions.each do |args|
|
42
|
-
model.send(*args)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
=begin
|
47
|
-
# uncomment for debugging
|
48
|
-
|
49
|
-
pp TODO
|
50
|
-
|
51
|
-
TODO.keys.each do |model|
|
52
|
-
puts "the #{model}"
|
53
|
-
assoc = model.send(:association_reflections)
|
54
|
-
assoc.each do |key, reflection|
|
55
|
-
puts " #{reflection[:type]} => #{key}"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
=end
|
59
|
-
end
|
60
|
-
|
61
|
-
def the(left_model, &block)
|
62
|
-
@left = left_model
|
63
|
-
TODO[@left] = []
|
64
|
-
instance_eval(&block)
|
65
|
-
end
|
66
|
-
|
67
|
-
def belongs_to(model)
|
68
|
-
todo :many_to_one, singular_sym(model), :class => model
|
69
|
-
end
|
70
|
-
|
71
|
-
def has_many(model)
|
72
|
-
todo :create_join, model
|
73
|
-
todo :many_to_many, plural_sym(model), :class => model
|
74
|
-
end
|
75
|
-
|
76
|
-
def has_one(model)
|
77
|
-
todo :many_to_one, singular_sym(model), :class => model
|
78
|
-
end
|
79
|
-
|
80
|
-
def todo(method, *args)
|
81
|
-
TODO[@left] << [method, *args]
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def plural_sym(obj)
|
87
|
-
basename(obj).pluralize.to_sym
|
88
|
-
end
|
89
|
-
|
90
|
-
def singular_sym(obj)
|
91
|
-
basename(obj).to_sym
|
92
|
-
end
|
93
|
-
|
94
|
-
def basename(obj)
|
95
|
-
obj.to_s.split('::').last.downcase
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'securerandom' # Ruby >= 1.8.7
|
3
|
-
rescue LoadError
|
4
|
-
require 'uuidtools'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'digest/md5'
|
8
|
-
|
9
|
-
module Ramaze
|
10
|
-
module Helper
|
11
|
-
# Authorization using HTTP Digest.
|
12
|
-
#
|
13
|
-
# For custom authorization failure handling add an {httpdigest_failure}
|
14
|
-
# method in your controller.
|
15
|
-
module HttpDigest
|
16
|
-
|
17
|
-
SESSION_NONCE = 'httpdigest_authentication_nonce'
|
18
|
-
SESSION_OPAQUE = 'httpdigest_authentication_opaque'
|
19
|
-
DIGEST_HEADER = %|Digest realm="%s", qop="auth,auth-int", nonce="%s", opaque="%s"|
|
20
|
-
|
21
|
-
# Delete the nonce and opaque from session to log out.
|
22
|
-
def httpdigest_logout
|
23
|
-
session.delete(SESSION_NONCE)
|
24
|
-
session.delete(SESSION_OPAQUE)
|
25
|
-
end
|
26
|
-
|
27
|
-
def httpdigest_uuid
|
28
|
-
::SecureRandom.hex(32)
|
29
|
-
end
|
30
|
-
|
31
|
-
def httpdigest_failure_internal(uid,realm)
|
32
|
-
nonce = session[SESSION_NONCE] = httpdigest_uuid
|
33
|
-
opaque = session[SESSION_OPAQUE][realm][uid] = httpdigest_uuid
|
34
|
-
response['WWW-Authenticate'] = DIGEST_HEADER % [realm, nonce, opaque]
|
35
|
-
response['Pragma'] = 'no-cache' # HTTP/1.0
|
36
|
-
response['Cache-Control'] = 'no-cache' # HTTP/1.1
|
37
|
-
response['Last-Modified'] = Time.now.httpdate
|
38
|
-
httpdigest_failure
|
39
|
-
end
|
40
|
-
|
41
|
-
def httpdigest_failure
|
42
|
-
respond 'Unauthorized', 401
|
43
|
-
end
|
44
|
-
|
45
|
-
def httpdigest_http_authorization(uid, realm)
|
46
|
-
http_authorization = request.env['HTTP_AUTHORIZATION']
|
47
|
-
return http_authorization if http_authorization
|
48
|
-
|
49
|
-
httpdigest_failure_internal(uid, realm)
|
50
|
-
end
|
51
|
-
|
52
|
-
def httpdigest_lookup(username, realm)
|
53
|
-
if block_given?
|
54
|
-
yield(username)
|
55
|
-
elsif respond_to?(:httpdigest_lookup_password)
|
56
|
-
httpdigest_lookup_password(username)
|
57
|
-
elsif respond_to?(:httpdigest_lookup_plaintext_password)
|
58
|
-
plain = httpdigest_lookup_plaintext_password(username)
|
59
|
-
Digest::MD5.hexdigest([username, realm, plain].join(':'))
|
60
|
-
else
|
61
|
-
raise "No password lookup handler found"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def httpdigest(uid, realm, &block)
|
66
|
-
session[SESSION_OPAQUE] ||= {}
|
67
|
-
session[SESSION_OPAQUE][realm] ||= {}
|
68
|
-
|
69
|
-
http_authorization = httpdigest_http_authorization(uid, realm)
|
70
|
-
|
71
|
-
httpdigest_failure_internal(uid, realm) unless session_nonce = session[SESSION_NONCE]
|
72
|
-
httpdigest_failure_internal(uid, realm) unless session_opaque = session[SESSION_OPAQUE][realm][uid]
|
73
|
-
|
74
|
-
auth_type, auth_raw = http_authorization.split(' ', 2)
|
75
|
-
httpdigest_failure_internal(uid, realm) unless auth_type == 'Digest'
|
76
|
-
|
77
|
-
authorization = Rack::Auth::Digest::Params.parse(auth_raw)
|
78
|
-
|
79
|
-
digest_response, username, nonce, nc, cnonce, qop, opaque, uri =
|
80
|
-
authorization.values_at(*%w[response username nonce nc cnonce qop opaque uri])
|
81
|
-
|
82
|
-
httpdigest_failure_internal(uid, realm) unless nonce == session_nonce and opaque == session_opaque
|
83
|
-
|
84
|
-
ha1 = httpdigest_lookup(username, realm, &block)
|
85
|
-
a2 = [request.request_method,uri]
|
86
|
-
a2 << Digest::MD5.hexdigest(request.body.read) if qop == "auth-int"
|
87
|
-
ha2 = Digest::MD5.hexdigest(a2.join(':'))
|
88
|
-
md5 = Digest::MD5.hexdigest([ha1, nonce, nc, cnonce, qop, ha2].join(':'))
|
89
|
-
|
90
|
-
httpdigest_failure_internal(uid, realm) unless digest_response == md5
|
91
|
-
|
92
|
-
return username
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|