active_presenters 1.0.1.6 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_presenter_base.rb +167 -87
- data/lib/active_presenters.rb +1 -1
- data/lib/tasks/rubyforge_config.yml +1 -1
- metadata +2 -2
@@ -34,112 +34,192 @@ module ActivePresenter
|
|
34
34
|
attr_accessor :model_camelcase # => DebateSide
|
35
35
|
|
36
36
|
def initialize(source, options = {})
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
if source.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
# running_time("source = #{source.class.to_s.underscore}; #{source}") do
|
38
|
+
self.model_underscore = source.class.to_s.underscore
|
39
|
+
self.model_camelcase = source.class.to_s
|
40
|
+
eval %{alias :#{self.model_underscore} :model}
|
41
|
+
@model = source
|
42
|
+
self.options = options || {}
|
43
|
+
# running_time("if source.is_a? ActiveRecord::Base") do
|
44
|
+
# if source.is_a? ActiveRecord::Base
|
45
|
+
# if source.is_restful?
|
46
|
+
# running_time("if source.is_restful?") do
|
47
|
+
# running_time("build_common_ar_resource_methods") do
|
48
|
+
# build_common_ar_resource_methods
|
49
|
+
# end
|
50
|
+
# running_time("build_ar_resource_methods") do
|
51
|
+
# build_ar_resource_methods
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
# else
|
55
|
+
# #build_ar_non_resource_methods
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
# end
|
50
60
|
end
|
51
61
|
|
52
62
|
def model
|
53
63
|
@model
|
54
64
|
end
|
55
|
-
|
56
|
-
protected
|
57
|
-
|
58
|
-
def build_common_ar_resource_methods
|
59
|
-
instance_eval do
|
60
|
-
unless method_defined?(:destroy_link_options)
|
61
|
-
def destroy_link_options
|
62
|
-
{:confirm => 'Are you sure?', :method => :delete}
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
unless method_defined?(:#{verb}_link_options)
|
77
|
-
def #{verb}_link_options
|
78
|
-
#{meth == :get ? "{}" : "{:method => :#{meth}}"}
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
unless method_defined?(:#{verb}_link)
|
83
|
-
def #{verb}_link(name = #{verb}_link_text, options = {}, html_options = nil, *args)
|
84
|
-
options = #{verb}_link_options.merge(options)
|
85
|
-
link_to(h(name), #{verb}_path, options, html_options, *args)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
}
|
66
|
+
REST_VERBS.each_pair do |verb, meth|
|
67
|
+
define_method("#{verb}_link_text") do
|
68
|
+
verb.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
define_method("#{verb}_link_options") do
|
72
|
+
opts = {}
|
73
|
+
unless meth == :get
|
74
|
+
opts.merge!({:method => meth})
|
89
75
|
end
|
76
|
+
opts
|
90
77
|
end
|
78
|
+
|
79
|
+
eval %{
|
80
|
+
unless method_defined?(:#{verb}_link)
|
81
|
+
def #{verb}_link(name = #{verb}_link_text, options = {}, html_options = nil, *args)
|
82
|
+
options = #{verb}_link_options.merge(options)
|
83
|
+
link_to(h(name), #{verb}_path, options, html_options, *args)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
}
|
91
87
|
end
|
92
88
|
|
93
|
-
def
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
unless method_defined?(:show_path)
|
103
|
-
def show_path
|
104
|
-
#{self.singular}_path#{self.nested_resource_path_string(true)}
|
105
|
-
end
|
106
|
-
end
|
89
|
+
def destroy_link_options
|
90
|
+
{:confirm => 'Are you sure?', :method => :delete}
|
91
|
+
end
|
92
|
+
|
93
|
+
def index_path
|
94
|
+
ivar_cache do
|
95
|
+
eval "#{self.plural}_path#{self.nested_resource_path_string}"
|
96
|
+
end
|
97
|
+
end
|
107
98
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
unless method_defined?(:create_path)
|
115
|
-
def create_path
|
116
|
-
#{self.plural}_path#{self.nested_resource_path_string}
|
117
|
-
end
|
118
|
-
end
|
99
|
+
def show_path
|
100
|
+
ivar_cache do
|
101
|
+
eval "#{self.singular}_path#{self.nested_resource_path_string(true)}"
|
102
|
+
end
|
103
|
+
end
|
119
104
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
105
|
+
def new_path
|
106
|
+
ivar_cache do
|
107
|
+
eval "new_#{self.singular}_path#{self.nested_resource_path_string}"
|
108
|
+
end
|
109
|
+
end
|
125
110
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
111
|
+
def create_path
|
112
|
+
ivar_cache do
|
113
|
+
eval "#{self.plural}_path#{self.nested_resource_path_string}"
|
114
|
+
end
|
115
|
+
end
|
131
116
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
}
|
117
|
+
def edit_path
|
118
|
+
ivar_cache do
|
119
|
+
eval "edit_#{self.singular}_path#{self.nested_resource_path_string(true)}"
|
120
|
+
end
|
121
|
+
end
|
138
122
|
|
123
|
+
def update_path
|
124
|
+
ivar_cache do
|
125
|
+
eval "#{self.singular}_path#{self.nested_resource_path_string(true)}"
|
139
126
|
end
|
127
|
+
end
|
140
128
|
|
129
|
+
def destroy_path
|
130
|
+
ivar_cache do
|
131
|
+
eval "#{self.singular}_path#{self.nested_resource_path_string(true)}"
|
132
|
+
end
|
141
133
|
end
|
142
134
|
|
135
|
+
|
136
|
+
protected
|
137
|
+
|
138
|
+
# def build_common_ar_resource_methods
|
139
|
+
# instance_eval do
|
140
|
+
# unless method_defined?(:destroy_link_options)
|
141
|
+
# def destroy_link_options
|
142
|
+
# {:confirm => 'Are you sure?', :method => :delete}
|
143
|
+
# end
|
144
|
+
# end
|
145
|
+
# end
|
146
|
+
#
|
147
|
+
# instance_eval do
|
148
|
+
# REST_VERBS.each_pair do |verb, meth|
|
149
|
+
# eval %{
|
150
|
+
# unless method_defined?(:#{verb}_link_text)
|
151
|
+
# def #{verb}_link_text
|
152
|
+
# "#{verb}"
|
153
|
+
# end
|
154
|
+
# end
|
155
|
+
#
|
156
|
+
# unless method_defined?(:#{verb}_link_options)
|
157
|
+
# def #{verb}_link_options
|
158
|
+
# #{meth == :get ? "{}" : "{:method => :#{meth}}"}
|
159
|
+
# end
|
160
|
+
# end
|
161
|
+
#
|
162
|
+
# unless method_defined?(:#{verb}_link)
|
163
|
+
# def #{verb}_link(name = #{verb}_link_text, options = {}, html_options = nil, *args)
|
164
|
+
# options = #{verb}_link_options.merge(options)
|
165
|
+
# link_to(h(name), #{verb}_path, options, html_options, *args)
|
166
|
+
# end
|
167
|
+
# end
|
168
|
+
# }
|
169
|
+
# end
|
170
|
+
# end
|
171
|
+
# end
|
172
|
+
#
|
173
|
+
# def build_ar_resource_methods
|
174
|
+
# instance_eval do
|
175
|
+
# eval %{
|
176
|
+
# unless method_defined?(:index_path)
|
177
|
+
# def index_path
|
178
|
+
# #{self.plural}_path#{self.nested_resource_path_string}
|
179
|
+
# end
|
180
|
+
# end
|
181
|
+
#
|
182
|
+
# unless method_defined?(:show_path)
|
183
|
+
# def show_path
|
184
|
+
# #{self.singular}_path#{self.nested_resource_path_string(true)}
|
185
|
+
# end
|
186
|
+
# end
|
187
|
+
#
|
188
|
+
# unless method_defined?(:new_path)
|
189
|
+
# def new_path
|
190
|
+
# new_#{self.singular}_path#{self.nested_resource_path_string}
|
191
|
+
# end
|
192
|
+
# end
|
193
|
+
#
|
194
|
+
# unless method_defined?(:create_path)
|
195
|
+
# def create_path
|
196
|
+
# #{self.plural}_path#{self.nested_resource_path_string}
|
197
|
+
# end
|
198
|
+
# end
|
199
|
+
#
|
200
|
+
# unless method_defined?(:edit_path)
|
201
|
+
# def edit_path
|
202
|
+
# edit_#{self.singular}_path#{self.nested_resource_path_string(true)}
|
203
|
+
# end
|
204
|
+
# end
|
205
|
+
#
|
206
|
+
# unless method_defined?(:update_path)
|
207
|
+
# def update_path
|
208
|
+
# #{self.singular}_path#{self.nested_resource_path_string(true)}
|
209
|
+
# end
|
210
|
+
# end
|
211
|
+
#
|
212
|
+
# unless method_defined?(:destroy_path)
|
213
|
+
# def destroy_path
|
214
|
+
# #{self.singular}_path#{self.nested_resource_path_string(true)}
|
215
|
+
# end
|
216
|
+
# end
|
217
|
+
# }
|
218
|
+
#
|
219
|
+
# end
|
220
|
+
#
|
221
|
+
# end
|
222
|
+
|
143
223
|
def nested_resource_path_string(include_self = false)
|
144
224
|
x = self.model.nested_resource.nil? ? '' : "self.model.nested_resource"
|
145
225
|
x << (x.blank? ? '' : ", ") << "self.model" if include_self
|
data/lib/active_presenters.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: active_presenters
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2007-10-
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2007-10-04 00:00:00 -04:00
|
8
8
|
summary: active_presenters
|
9
9
|
require_paths:
|
10
10
|
- lib
|