equipment 0.1.0 → 1.4.84
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/LICENSE +340 -0
- data/README +29 -12
- data/Rakefile +157 -0
- data/TODO +14 -0
- data/doc/structure.dia +0 -0
- data/doc/structure.png +0 -0
- data/lib/camping_ext.rb +72 -0
- data/lib/equipment.rb +39 -116
- data/lib/ext.rb +33 -0
- data/lib/ext/active_record.rb +146 -0
- data/lib/ext/basic_auth.rb +15 -15
- data/lib/ext/controls.rb +16 -14
- data/lib/ext/flash.rb +35 -17
- data/lib/ext/form_helpers.rb +46 -0
- data/lib/ext/forward.rb +44 -15
- data/lib/ext/js_helpers.rb +66 -19
- data/lib/ext/logging.rb +61 -0
- data/lib/ext/mount.rb +33 -27
- data/lib/ext/negociate_content.rb +90 -0
- data/lib/ext/og.rb +18 -10
- data/lib/ext/og_scaffold.rb +5 -8
- data/lib/ext/resource.rb +127 -0
- data/lib/ext/security.rb +66 -31
- data/lib/ext/sendfile.rb +3 -4
- data/lib/ext/settings.rb +243 -0
- data/lib/ext/template_view.rb +9 -37
- data/lib/ext/use_helper.rb +6 -10
- data/lib/ext/view.rb +98 -0
- data/lib/ext/view_slot.rb +60 -0
- data/lib/mimetype_ext.rb +12 -0
- data/lib/more/typecast.rb +288 -0
- data/lib/ruby_ext.rb +126 -0
- data/share/js/date_ext.js +234 -0
- data/share/js/es-confirm.js +23 -0
- data/share/js/event-selector.js +145 -0
- data/share/js/jquery.js +1793 -0
- data/share/js/prototype.js +2012 -0
- metadata +50 -35
- data/ProjectInfo +0 -55
- data/examples/basicauthtest.rb +0 -59
- data/examples/erubytest.rb +0 -36
- data/examples/flashtest.rb +0 -46
- data/examples/index.erb +0 -9
- data/examples/mounttest.rb +0 -34
- data/examples/ogtest.rb +0 -41
- data/examples/patchestest.rb +0 -40
- data/examples/sendfiletest.rb +0 -29
- data/lib/ext/forms.rb +0 -22
- data/lib/ext/patches.rb +0 -130
- data/lib/ext/ressource.rb +0 -88
data/lib/ext/use_helper.rb
CHANGED
@@ -42,24 +42,20 @@ module Ext
|
|
42
42
|
# between the controller and the view. This may cause unwanted behavior.
|
43
43
|
module UseHelper
|
44
44
|
extend Equipment
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@
|
49
|
-
@__stylesheets ||= []
|
50
|
-
puts "UseHelper::Base : Initialized well" if $DBG
|
45
|
+
|
46
|
+
module Base
|
47
|
+
def initialize(r,env,m)
|
48
|
+
@__uses = {}
|
51
49
|
super
|
52
50
|
end
|
53
51
|
end
|
54
|
-
super
|
55
|
-
end
|
56
52
|
|
57
53
|
module Helpers
|
58
54
|
def javascripts
|
59
|
-
@
|
55
|
+
@__uses[:javascripts] ||= []
|
60
56
|
end
|
61
57
|
def stylesheets
|
62
|
-
@
|
58
|
+
@__uses[:stylesheets] ||= []
|
63
59
|
end
|
64
60
|
def use(*elems)
|
65
61
|
elems.each do |elem|
|
data/lib/ext/view.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'equipment'
|
2
|
+
require 'ext/app_util'
|
3
|
+
|
4
|
+
module Ext
|
5
|
+
|
6
|
+
# Generalized View extension.
|
7
|
+
#
|
8
|
+
# == Dependencies
|
9
|
+
#
|
10
|
+
# * Equipment
|
11
|
+
# * AppUtil
|
12
|
+
#
|
13
|
+
module View
|
14
|
+
extend Equipment
|
15
|
+
depends_on AppUtil
|
16
|
+
|
17
|
+
def self.equip(app)
|
18
|
+
super
|
19
|
+
app.module_eval <<-SOME_VIEW
|
20
|
+
# Some kind of view data proxy for template-based renderers
|
21
|
+
class V
|
22
|
+
def bind(m,*a,&b); binding; end
|
23
|
+
def R(klass, *args); self / super; end
|
24
|
+
end
|
25
|
+
SOME_VIEW
|
26
|
+
end
|
27
|
+
|
28
|
+
module CClassMethods
|
29
|
+
def create
|
30
|
+
puts "INFO: View#create called" if $DBG
|
31
|
+
self::V.send :include, self::Helpers, self::Controllers
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module Base
|
37
|
+
|
38
|
+
# = Re-defined render
|
39
|
+
#
|
40
|
+
# The method_missing method is great but it ties the system too much to
|
41
|
+
# markaby. It makes also harder to debunk wrong methods since the call-
|
42
|
+
# stack is longer. Finally, it encourages to put the view in the
|
43
|
+
# controller, which is considered bad in MVC style (that's what ppl say)
|
44
|
+
#
|
45
|
+
# Render is a method that gets the view and puts a layout around it if
|
46
|
+
# found.
|
47
|
+
#
|
48
|
+
# Layout was renamed to _layout because it is a partial. Also partials
|
49
|
+
# don't use the layout feature (so layout doesn't have a layout)
|
50
|
+
def method_missing(*a,&b)
|
51
|
+
a.shift if a[0]==:render
|
52
|
+
m=app::Mab.new({},self)
|
53
|
+
s=m.capture{send(*a,&b)}
|
54
|
+
s=m.layout{s} if m.respond_to?:layout and a[0].to_s[0] != ?_
|
55
|
+
s
|
56
|
+
end
|
57
|
+
|
58
|
+
=begin
|
59
|
+
def render(m, *a, &b)
|
60
|
+
str = view(m, *a, &b)
|
61
|
+
# allow content-negotiation
|
62
|
+
if str and m.to_s[0] != ?_ and has_view? :_layout
|
63
|
+
str = view(:_layout) { str }
|
64
|
+
end
|
65
|
+
str
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get the result of a markaby view
|
69
|
+
def markaby_view(m,*a,&b)
|
70
|
+
return nil unless /text\/html/ =~ content_type and markaby_view?(m)
|
71
|
+
h=app::Mab.new({}, self)
|
72
|
+
h.capture{send(m,*a,&b)}
|
73
|
+
h.to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
# Useful if you want to implement your own view. #markaby_view is the
|
77
|
+
# terminator.
|
78
|
+
alias_method :view, :markaby_view
|
79
|
+
=end
|
80
|
+
|
81
|
+
# Returns true if markaby provides this view
|
82
|
+
def markaby_view?(v)
|
83
|
+
app::Views.method_defined? v # this is specific to markaby
|
84
|
+
end
|
85
|
+
|
86
|
+
# Shortcut.
|
87
|
+
#
|
88
|
+
# This is useful if you want to implement your own view lookup
|
89
|
+
# (cf. ErubisView)
|
90
|
+
alias_method :has_view?, :markaby_view?
|
91
|
+
|
92
|
+
# Shortcut for @headers['Content-Type'] || 'text/html'
|
93
|
+
def content_type; @headers['Content-Type'] || 'text/html' end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'equipment'
|
2
|
+
require 'ext/app_util'
|
3
|
+
|
4
|
+
module Ext
|
5
|
+
# PostRender allows you to render things in your layout,
|
6
|
+
# defined in your view.
|
7
|
+
#
|
8
|
+
# WARNING : Very fragile.
|
9
|
+
module ViewSlot
|
10
|
+
extend Equipment
|
11
|
+
depends_on AppUtil
|
12
|
+
|
13
|
+
module Base
|
14
|
+
def initialize(r,e,m)
|
15
|
+
super
|
16
|
+
@__view_slots = {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Helpers
|
21
|
+
|
22
|
+
def slot(name, &block)
|
23
|
+
name = name.to_s
|
24
|
+
if block_given?
|
25
|
+
@__view_slots[name] = block
|
26
|
+
return nil
|
27
|
+
else
|
28
|
+
return @__view_slots[name]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Call this before using the slots
|
33
|
+
def render_slots(*slots)
|
34
|
+
slots.each do |name|
|
35
|
+
name = name.to_s
|
36
|
+
@__view_slots[name] = if block = @__view_slots[name]
|
37
|
+
m = app::Mab.new({},self)
|
38
|
+
m.capture &block
|
39
|
+
elsif respond_to? "_#{name}"
|
40
|
+
m = app::Mab.new({},self)
|
41
|
+
m.capture { send "_#{name}" }
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
=begin
|
50
|
+
def method_missing(*a,&b)
|
51
|
+
a.shift if a[0]==:render
|
52
|
+
m=Mab.new({},self)
|
53
|
+
s=m.capture{send(*a,&b)}
|
54
|
+
s=m.layout{s} if m.respond_to?:layout
|
55
|
+
s
|
56
|
+
end
|
57
|
+
=end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/mimetype_ext.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file provides fixes for the `mime/types` package.
|
2
|
+
|
3
|
+
require 'mime/types'
|
4
|
+
|
5
|
+
js_type = MIME::Types['text/javascript'].first
|
6
|
+
if js_type.extensions.empty?
|
7
|
+
js_type.extensions.push 'js'
|
8
|
+
MIME::Types.index_extensions(js_type)
|
9
|
+
else
|
10
|
+
raise "Remove the mime-js fix"
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,288 @@
|
|
1
|
+
# = typecast.rb
|
2
|
+
#
|
3
|
+
# == Copyright (c) 2004 Jonas Pfenniger
|
4
|
+
#
|
5
|
+
# Ruby License
|
6
|
+
#
|
7
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
+
# software under the same terms as Ruby.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
# FOR A PARTICULAR PURPOSE.
|
13
|
+
#
|
14
|
+
# == Author(s)
|
15
|
+
#
|
16
|
+
# * Jonas Pfenniger
|
17
|
+
#
|
18
|
+
# == Changelog
|
19
|
+
#
|
20
|
+
# 06.06.2006 - 3v1l d4y
|
21
|
+
#
|
22
|
+
# * Removed transformation options.
|
23
|
+
# * Removed StringIO typecast. It is not required by default.
|
24
|
+
# * Added TypeCastException for better error reporting while coding.
|
25
|
+
#
|
26
|
+
# == Developer Notes
|
27
|
+
#
|
28
|
+
# TODO Consider how this might fit in with method signitures, overloading,
|
29
|
+
# and expiremental euphoria-like type system.
|
30
|
+
#
|
31
|
+
# TODO Look to implement to_int, to_mailtext, to_r, to_rfc822text and to_str.
|
32
|
+
|
33
|
+
|
34
|
+
# Author:: Jonas Pfenniger
|
35
|
+
# Copyright:: Copyright (c) 2004 Jonas Pfenniger
|
36
|
+
# License:: Ruby License
|
37
|
+
|
38
|
+
require 'time'
|
39
|
+
|
40
|
+
require 'facet/string/methodize'
|
41
|
+
require 'facet/string/modulize'
|
42
|
+
|
43
|
+
# = TypeCast
|
44
|
+
#
|
45
|
+
# Provides a generic simple type conversion utility. All the ruby core
|
46
|
+
# conversions are available by default.
|
47
|
+
#
|
48
|
+
# To implement a new type conversion, you have two choices :
|
49
|
+
#
|
50
|
+
# Take :
|
51
|
+
#
|
52
|
+
# class CustomType
|
53
|
+
# def initialize(my_var)
|
54
|
+
# @my_var = my_var
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# * Define a to_class_name instance method
|
59
|
+
#
|
60
|
+
# class CustomType
|
61
|
+
# def to_string
|
62
|
+
# my_var.to_s
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# c = CustomType.new 1234
|
67
|
+
# s.cast_to String => "1234" (String)
|
68
|
+
#
|
69
|
+
# * Define a from_class_name class method
|
70
|
+
#
|
71
|
+
# class CustomType
|
72
|
+
# def self.from_string(str)
|
73
|
+
# self.new(str)
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# "1234".cast_to CustomType => #<CustomType:0xb7d1958c @my_var="1234">
|
78
|
+
#
|
79
|
+
#
|
80
|
+
# Those two methods are equivalent in the result. It was coded like that to
|
81
|
+
# avoid the pollution of core classes with tons of to_* methods.
|
82
|
+
#
|
83
|
+
# The standard methods to_s, to_f, to_i, to_a and to_sym are also used by
|
84
|
+
# this system if available.
|
85
|
+
#
|
86
|
+
# == Usage
|
87
|
+
#
|
88
|
+
# "1234".cast_to Float => 1234.0 (Float)
|
89
|
+
# Time.cast_from("6:30") => 1234.0 (Time)
|
90
|
+
#
|
91
|
+
# == FAQ
|
92
|
+
#
|
93
|
+
# Why didn't you name the `cast_to` method to `to` ?
|
94
|
+
#
|
95
|
+
# Even if it would make the syntax more friendly, I suspect it could cause
|
96
|
+
# a lot of collisions with already existing code. The goal is that each
|
97
|
+
# time you call cast_to, you either get your result, either a
|
98
|
+
# TypeCastException
|
99
|
+
#
|
100
|
+
|
101
|
+
class TypeCastException < Exception; end
|
102
|
+
|
103
|
+
#
|
104
|
+
|
105
|
+
class Object
|
106
|
+
|
107
|
+
# class TypeCastException < Exception; end
|
108
|
+
|
109
|
+
# Cast an object to another
|
110
|
+
#
|
111
|
+
# 1234.cast_to(String) => "1234"
|
112
|
+
#
|
113
|
+
def cast_to(klass)
|
114
|
+
klass.cast_from(self)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Cast on object from another
|
118
|
+
#
|
119
|
+
# String.cast_from(1234) => "1234"
|
120
|
+
#
|
121
|
+
def cast_from(object)
|
122
|
+
method_to = "to_#{self.name.methodize}".to_sym
|
123
|
+
if object.respond_to? method_to
|
124
|
+
retval = object.send(method_to)
|
125
|
+
return retval
|
126
|
+
end
|
127
|
+
|
128
|
+
method_from = "from_#{object.class.name.methodize}".to_sym
|
129
|
+
if respond_to? method_from
|
130
|
+
retval = send(method_from, object)
|
131
|
+
return retval
|
132
|
+
end
|
133
|
+
|
134
|
+
raise TypeCastException, "TypeCasting from #{object.class.name} to #{self.name} not supported"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Extend the ruby core
|
139
|
+
|
140
|
+
class Array
|
141
|
+
class << self
|
142
|
+
def cast_from(object)
|
143
|
+
return super
|
144
|
+
rescue TypeCastException
|
145
|
+
return object.to_a if object.respond_to? :to_a
|
146
|
+
raise
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class Float
|
152
|
+
class << self
|
153
|
+
def cast_from(object)
|
154
|
+
return super
|
155
|
+
rescue TypeCastException
|
156
|
+
return object.to_f if object.respond_to? :to_f
|
157
|
+
raise
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
class Integer
|
163
|
+
class << self
|
164
|
+
def cast_from(object)
|
165
|
+
return super
|
166
|
+
rescue TypeCastException
|
167
|
+
return object.to_i if object.respond_to? :to_i
|
168
|
+
raise
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
class String
|
174
|
+
class << self
|
175
|
+
def cast_from(object)
|
176
|
+
return super
|
177
|
+
rescue TypeCastException
|
178
|
+
return object.to_s if object.respond_to? :to_s
|
179
|
+
raise
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
class Symbol
|
185
|
+
class << self
|
186
|
+
def cast_from(object)
|
187
|
+
return super
|
188
|
+
rescue TypeCastException
|
189
|
+
return object.to_sym if object.respond_to? :to_sym
|
190
|
+
raise
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Extensions
|
196
|
+
|
197
|
+
class Class
|
198
|
+
class << self
|
199
|
+
|
200
|
+
# "string".cast_to Class #=> String
|
201
|
+
|
202
|
+
def from_string(string)
|
203
|
+
string = string.to_s.modulize
|
204
|
+
base = string.sub!(/^::/, '') ? Object : (self.kind_of?(Module) ? self : self.class )
|
205
|
+
klass = string.split(/::/).inject(base){ |mod, name| mod.const_get(name) }
|
206
|
+
return klass if klass.kind_of? Class
|
207
|
+
nil
|
208
|
+
rescue
|
209
|
+
nil
|
210
|
+
end
|
211
|
+
|
212
|
+
alias_method :from_symbol, :from_string
|
213
|
+
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
class Time
|
218
|
+
class << self
|
219
|
+
def from_string(string, options={})
|
220
|
+
parse(string)
|
221
|
+
rescue
|
222
|
+
nil
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
|
228
|
+
# _____ _
|
229
|
+
# |_ _|__ ___| |_
|
230
|
+
# | |/ _ \/ __| __|
|
231
|
+
# | | __/\__ \ |_
|
232
|
+
# |_|\___||___/\__|
|
233
|
+
#
|
234
|
+
=begin test
|
235
|
+
|
236
|
+
require 'test/unit'
|
237
|
+
|
238
|
+
class TestClass
|
239
|
+
attr_accessor :my_var
|
240
|
+
def initialize(my_var); @my_var = my_var; end
|
241
|
+
|
242
|
+
def to_string(options={})
|
243
|
+
@my_var
|
244
|
+
end
|
245
|
+
|
246
|
+
class << self
|
247
|
+
def from_string(string, options={})
|
248
|
+
self.new( string )
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
class TC_TypeCast < Test::Unit::TestCase
|
254
|
+
|
255
|
+
def setup
|
256
|
+
@test_string = "this is a test"
|
257
|
+
@test_class = TestClass.new(@test_string)
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_to_string
|
261
|
+
assert_equal( '1234', 1234.cast_to(String) )
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_custom_to_string
|
265
|
+
assert_equal( @test_string, @test_class.cast_to(String) )
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_custom_from_string
|
269
|
+
assert_equal( @test_class.my_var, @test_string.cast_to(TestClass).my_var )
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_string_to_class
|
273
|
+
assert_equal( Test::Unit::TestCase, "Test::Unit::TestCase".cast_to(Class) )
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_string_to_time
|
277
|
+
assert_equal( "Mon Oct 10 00:00:00 2005", "2005-10-10".cast_to(Time).strftime("%a %b %d %H:%M:%S %Y") )
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_no_converter
|
281
|
+
"sfddsf".cast_to( ::Regexp )
|
282
|
+
assert(1+1==3, 'should not get here')
|
283
|
+
rescue TypeCastException => ex
|
284
|
+
assert_equal(TypeCastException, ex.class)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
=end
|