scaffolding_extensions 1.3.7 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +2 -2
- data/doc/ramaze.txt +0 -4
- data/lib/scaffolding_extensions/controller.rb +7 -13
- data/lib/scaffolding_extensions/controller/action_controller.rb +0 -6
- data/lib/scaffolding_extensions/controller/ramaze.rb +48 -41
- data/lib/scaffolding_extensions/controller/sinatra.rb +12 -12
- data/lib/scaffolding_extensions/helper.rb +11 -1
- data/lib/scaffolding_extensions/meta_controller.rb +1 -1
- data/lib/scaffolding_extensions/meta_model.rb +3 -6
- data/lib/scaffolding_extensions/model/active_record.rb +1 -2
- data/lib/scaffolding_extensions/model/sequel.rb +1 -1
- data/scaffolds/layout.rhtml +1 -1
- data/scaffolds/list.rhtml +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -22,13 +22,13 @@ Scaffolding Extensions currently supports:
|
|
22
22
|
|
23
23
|
* Web Frameworks
|
24
24
|
* Rails 2.3.2
|
25
|
-
* Ramaze 2009.
|
25
|
+
* Ramaze 2009.06.12
|
26
26
|
* Camping 1.5
|
27
27
|
* Sinatra 0.9.2
|
28
28
|
* Merb 1.0.4
|
29
29
|
* Object Relational Mappers
|
30
30
|
* ActiveRecord 2.3.2
|
31
|
-
* Sequel 3.
|
31
|
+
* Sequel 3.1.0
|
32
32
|
* Javascript Libaries (used for Ajax/Autocompleting)
|
33
33
|
* Prototype 1.6.0.3
|
34
34
|
* JQuery 1.2.3
|
data/doc/ramaze.txt
CHANGED
@@ -18,7 +18,3 @@ controllers have been loaded.
|
|
18
18
|
|
19
19
|
Also, note that Scaffolding Extensions uses the :Erubis engine in Ramaze,
|
20
20
|
so you must have Erubis installed to use it.
|
21
|
-
|
22
|
-
Scaffolding Extensions currently does not support Ramaze 2009.04+ (the
|
23
|
-
versions based on Innate). A patch that gives partial support is
|
24
|
-
available at http://pastie.org/484442.
|
@@ -7,17 +7,6 @@ module ScaffoldingExtensions
|
|
7
7
|
scaffold_method_not_allowed if scaffolded_nonidempotent_method?(scaffold_request_action) && scaffold_request_method != 'POST'
|
8
8
|
end
|
9
9
|
|
10
|
-
# Force the given value into an array. If the items is currently an array,
|
11
|
-
# return it. If the item is nil or false, return the empty array. Otherwise,
|
12
|
-
# return an array with the value as the only member.
|
13
|
-
def scaffold_force_array(value)
|
14
|
-
if value
|
15
|
-
Array === value ? value : [value]
|
16
|
-
else
|
17
|
-
[]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
10
|
# Returns path to the given scaffold template file
|
22
11
|
def scaffold_path(template_name)
|
23
12
|
File.join(self.class.scaffold_template_dir, "#{template_name}.rhtml")
|
@@ -51,14 +40,19 @@ module ScaffoldingExtensions
|
|
51
40
|
return send(meth, notice) if respond_to?(meth, true)
|
52
41
|
meth = "scaffold_#{action}_redirect"
|
53
42
|
return send(meth, suffix, notice) if respond_to?(meth, true)
|
54
|
-
|
43
|
+
scaffold_set_flash(notice)
|
55
44
|
scaffold_redirect_to(scaffold_url(action_suffix, oid ? {:id=>oid} : {}))
|
56
45
|
end
|
57
46
|
|
58
47
|
# Converts the value to an array, converts all values of the array to integers,
|
59
48
|
# removes all 0 values, and returns the array.
|
60
49
|
def scaffold_select_ids(value)
|
61
|
-
|
50
|
+
Array(value).collect{|x| x.to_i}.delete_if{|x| x == 0}
|
51
|
+
end
|
52
|
+
|
53
|
+
# Set the notice entry in the scaffold_flash hash by default.
|
54
|
+
def scaffold_set_flash(notice)
|
55
|
+
scaffold_flash[:notice] = notice if notice
|
62
56
|
end
|
63
57
|
|
64
58
|
# Return whether scaffolding defined the method, whether or not it was overwritten
|
@@ -11,12 +11,6 @@ module ScaffoldingExtensions
|
|
11
11
|
# Helper methods for ActionController::Base that override the defaults in Scaffolding Extensions
|
12
12
|
module ActionControllerHelper
|
13
13
|
private
|
14
|
-
# ActionController::Base requires that params that are desired to be lists have
|
15
|
-
# the suffix '[]'
|
16
|
-
def scaffold_param_list_suffix
|
17
|
-
'[]'
|
18
|
-
end
|
19
|
-
|
20
14
|
# ActionController::Base allows easy access to the CSRF token via token_tag
|
21
15
|
def scaffold_token_tag
|
22
16
|
token_tag
|
@@ -13,15 +13,15 @@ module ScaffoldingExtensions
|
|
13
13
|
def scaffold_flash
|
14
14
|
flash
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def scaffold_method_not_allowed
|
18
18
|
respond('Method not allowed', 405)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def scaffold_redirect_to(url)
|
22
22
|
redirect(url)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# Renders user provided template if it exists, otherwise renders a scaffold template.
|
26
26
|
# If a layout is specified (either in the controller or as an render_option), use that layout,
|
27
27
|
# otherwise uses the scaffolded layout. If :inline is one of the render_options,
|
@@ -32,78 +32,84 @@ module ScaffoldingExtensions
|
|
32
32
|
@scaffold_options ||= options
|
33
33
|
@scaffold_suffix ||= suffix
|
34
34
|
@scaffold_class ||= @scaffold_options[:class]
|
35
|
-
unless
|
35
|
+
unless self.action.view
|
36
36
|
if render_options.include?(:inline)
|
37
37
|
response['Content-Type'] = 'text/javascript' if @scaffold_javascript
|
38
38
|
render_options[:inline]
|
39
39
|
else
|
40
|
-
|
40
|
+
self.action.view = scaffold_path(action)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def scaffold_request_action
|
46
|
-
|
46
|
+
action.name
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def scaffold_request_env
|
50
50
|
request.env
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def scaffold_request_id
|
54
54
|
request.params['id']
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def scaffold_request_method
|
58
58
|
request.env['REQUEST_METHOD']
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def scaffold_request_param(v)
|
62
62
|
request.params[v.to_s]
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def scaffold_session
|
66
66
|
session
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
# Treats the id option as special (appending it so the list of options),
|
70
70
|
# which requires a lambda router.
|
71
71
|
def scaffold_url(action, options = {})
|
72
|
-
options[:id] ?
|
72
|
+
options[:id] ? r(action, options.delete(:id), options) : r(action, options)
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
# Class methods for Ramaze::Controller related necessary for Scaffolding Extensions
|
77
77
|
module MetaRamazeController
|
78
78
|
DENY_LAYOUT_RE = %r{\A(scaffold_auto_complete_for|associations|add|remove)_}
|
79
|
-
|
79
|
+
|
80
80
|
private
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# Adds a default scaffolded layout if none has been set. Activates the Erubis
|
95
|
-
# engine. Includes the necessary scaffolding helper and controller methods.
|
96
|
-
def scaffold_setup_helper
|
97
|
-
engine :Erubis
|
98
|
-
include ScaffoldingExtensions::Controller
|
99
|
-
include ScaffoldingExtensions::RamazeController
|
100
|
-
include ScaffoldingExtensions::Helper
|
101
|
-
include ScaffoldingExtensions::PrototypeHelper
|
102
|
-
unless trait[:layout] && trait[:layout][:all]
|
103
|
-
layout(:scaffold_layout)
|
104
|
-
define_method(:scaffold_layout){::Ramaze::Action.current.template = scaffold_path(:layout)}
|
105
|
-
end
|
81
|
+
# Denies the layout to names that match DENY_LAYOUT_RE (the Ajax methods).
|
82
|
+
# Sets request.params['id'] if it was given as part of the request path.
|
83
|
+
# Checks nonidempotent requests require POST.
|
84
|
+
def scaffold_define_method(name, &block)
|
85
|
+
scaffolded_methods.add(name)
|
86
|
+
|
87
|
+
define_method(name) do |*args|
|
88
|
+
scaffold_check_nonidempotent_requests
|
89
|
+
request.params['id'] = args.shift if args.length > 0
|
90
|
+
instance_eval(&block)
|
106
91
|
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Adds a default scaffolded layout if none has been set. Activates the Erubis
|
95
|
+
# engine. Includes the necessary scaffolding helper and controller methods.
|
96
|
+
def scaffold_setup_helper
|
97
|
+
map generate_mapping, :scaffolding_extensions
|
98
|
+
map_views '/'
|
99
|
+
map_layouts '/'
|
100
|
+
engine :Erubis
|
101
|
+
layout(:layout){|name, wish| DENY_LAYOUT_RE !~ name }
|
102
|
+
|
103
|
+
o = Ramaze::App[:scaffolding_extensions].options
|
104
|
+
o.roots = [scaffold_template_dir]
|
105
|
+
o.views = ['/']
|
106
|
+
o.layouts = ['/']
|
107
|
+
|
108
|
+
include ScaffoldingExtensions::Controller
|
109
|
+
include ScaffoldingExtensions::RamazeController
|
110
|
+
include ScaffoldingExtensions::Helper
|
111
|
+
include ScaffoldingExtensions::PrototypeHelper
|
112
|
+
end
|
107
113
|
end
|
108
114
|
end
|
109
115
|
|
@@ -112,3 +118,4 @@ class Ramaze::Controller
|
|
112
118
|
extend ScaffoldingExtensions::MetaController
|
113
119
|
extend ScaffoldingExtensions::MetaRamazeController
|
114
120
|
end
|
121
|
+
|
@@ -76,7 +76,7 @@ module ScaffoldingExtensions
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def scaffold_request_method
|
79
|
-
|
79
|
+
request.env['REQUEST_METHOD']
|
80
80
|
end
|
81
81
|
|
82
82
|
def scaffold_request_param(v)
|
@@ -110,18 +110,18 @@ module ScaffoldingExtensions
|
|
110
110
|
include ScaffoldingExtensions::Helper
|
111
111
|
include ScaffoldingExtensions::PrototypeHelper
|
112
112
|
include ScaffoldingExtensions::SinatraHelper
|
113
|
+
p = 'POST'
|
114
|
+
block = lambda do
|
115
|
+
captures = params[:captures] || []
|
116
|
+
@scaffold_path = request.env['SCRIPT_NAME']
|
117
|
+
@scaffold_method = meth = captures[0] || 'index'
|
118
|
+
params[:id] ||= captures[1]
|
119
|
+
raise(ArgumentError, 'Method Not Allowed') if scaffold_request_method != p && scaffolded_nonidempotent_method?(meth)
|
120
|
+
scaffolded_method?(meth) ? send(meth) : pass
|
121
|
+
end
|
122
|
+
get('/?', &block)
|
113
123
|
[:get, :post].each do |req_meth|
|
114
|
-
|
115
|
-
send(req_meth, %r{\A(?:/(\w+)(?:/(\w+))?)?\z}) do
|
116
|
-
captures = params[:captures] || []
|
117
|
-
@scaffold_path = request.env['SCRIPT_NAME']
|
118
|
-
@scaffold_method = meth = captures[0] || 'index'
|
119
|
-
@scaffold_request_method = sreq_meth
|
120
|
-
params[:id] ||= captures[1]
|
121
|
-
raise(ArgumentError, 'Method Not Allowed') if req_meth == :get && scaffolded_nonidempotent_method?(meth)
|
122
|
-
raise(Sinatra::NotFound) unless scaffolded_method?(meth)
|
123
|
-
send(meth)
|
124
|
-
end
|
124
|
+
send(req_meth, %r{\A/(\w+)(?:/(\w+))?\z}, &block)
|
125
125
|
end
|
126
126
|
self
|
127
127
|
end
|
@@ -154,6 +154,11 @@ module ScaffoldingExtensions
|
|
154
154
|
''
|
155
155
|
end
|
156
156
|
|
157
|
+
# Return the notice entry in the flash hash.
|
158
|
+
def scaffold_get_flash
|
159
|
+
scaffold_flash[:notice]
|
160
|
+
end
|
161
|
+
|
157
162
|
# Returns html fragment containing autocompleting text or select boxes to add associated records
|
158
163
|
# to the current record, and line items with buttons to remove associated records
|
159
164
|
# from the current record.
|
@@ -204,6 +209,11 @@ module ScaffoldingExtensions
|
|
204
209
|
content
|
205
210
|
end
|
206
211
|
|
212
|
+
# Is the action given an idempotent action? True for show and edit, false otherwise
|
213
|
+
def scaffold_idempotent_action?(action)
|
214
|
+
[:show, :edit].include?(action)
|
215
|
+
end
|
216
|
+
|
207
217
|
# Script tag with javascript included inside a CDATA section
|
208
218
|
def scaffold_javascript_tag(javascript)
|
209
219
|
"<script type='text/javascript'>\n//<![CDATA[\n#{javascript}\n//]]>\n</script>"
|
@@ -278,7 +288,7 @@ module ScaffoldingExtensions
|
|
278
288
|
|
279
289
|
# The suffix needed to params that should be lists. The empty string by default.
|
280
290
|
def scaffold_param_list_suffix
|
281
|
-
''
|
291
|
+
'[]'
|
282
292
|
end
|
283
293
|
|
284
294
|
# A select tag with the provided name for the given collection of items. The options
|
@@ -149,7 +149,7 @@ module ScaffoldingExtensions
|
|
149
149
|
page = scaffold_request_param(:page).to_i > 1 ? scaffold_request_param(:page).to_i : 1
|
150
150
|
page -= 1 if scaffold_request_param(:page_previous)
|
151
151
|
page += 1 if scaffold_request_param(:page_next)
|
152
|
-
@scaffold_search_results_form_params, @scaffold_objects = klass.scaffold_search(:model=>scaffold_request_param(singular_name), :notnull=>
|
152
|
+
@scaffold_search_results_form_params, @scaffold_objects = klass.scaffold_search(:model=>scaffold_request_param(singular_name), :notnull=>Array(scaffold_request_param(:notnull)), :null=>Array(scaffold_request_param(:null)), :page=>page, :session=>scaffold_session)
|
153
153
|
@scaffold_listtable_type = :search
|
154
154
|
scaffold_render_template(:listtable, scaffold_options)
|
155
155
|
end
|
@@ -126,11 +126,8 @@ module ScaffoldingExtensions::MetaModel
|
|
126
126
|
def scaffold_add_associated_objects(association, object, options, *associated_object_ids)
|
127
127
|
unless associated_object_ids.empty?
|
128
128
|
scaffold_transaction do
|
129
|
-
associated_objects = associated_object_ids.
|
130
|
-
|
131
|
-
scaffold_add_associated_object(association, object, associated_object)
|
132
|
-
associated_object
|
133
|
-
end
|
129
|
+
associated_objects = associated_object_ids.map{|i| scaffold_association_find_object(association, i.to_i, :session=>options[:session])}
|
130
|
+
associated_objects.each{|o| scaffold_add_associated_object(association, object, o)}
|
134
131
|
associated_object_ids.length == 1 ? associated_objects.first : associated_objects
|
135
132
|
end
|
136
133
|
end
|
@@ -310,7 +307,7 @@ module ScaffoldingExtensions::MetaModel
|
|
310
307
|
# The name string to use in urls, defaults to name.underscore. Can be set with an
|
311
308
|
# instance variable.
|
312
309
|
def scaffold_name
|
313
|
-
@scaffold_name ||= name.underscore
|
310
|
+
@scaffold_name ||= name.underscore.gsub('/', '__')
|
314
311
|
end
|
315
312
|
|
316
313
|
# Merges the record with id from into the record with id to. Updates all
|
@@ -20,8 +20,7 @@ module ScaffoldingExtensions::MetaActiveRecord
|
|
20
20
|
# Add the associated object to the object's association
|
21
21
|
def scaffold_add_associated_object(association, object, associated_object)
|
22
22
|
association_proxy = object.send(association)
|
23
|
-
|
24
|
-
association_proxy << associated_object
|
23
|
+
association_proxy << associated_object unless association_proxy.include?(associated_object)
|
25
24
|
end
|
26
25
|
|
27
26
|
# Array of all association reflections for this model
|
@@ -19,7 +19,7 @@ module ScaffoldingExtensions::MetaSequel
|
|
19
19
|
|
20
20
|
# Add the associated object to the object's association
|
21
21
|
def scaffold_add_associated_object(association, object, associated_object)
|
22
|
-
object.send(association_reflection(association).add_method, associated_object)
|
22
|
+
object.send(association_reflection(association).add_method, associated_object) unless object.send(association).include?(associated_object)
|
23
23
|
end
|
24
24
|
|
25
25
|
# Array of all association reflections for this model
|
data/scaffolds/layout.rhtml
CHANGED
data/scaffolds/list.rhtml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<% @scaffold_title = "Choose #{hn = @scaffold_options[:singular_lc_human_name]} to #{(haction = (action = @scaffold_action).to_s.humanize).downcase}" %>
|
2
2
|
|
3
|
-
<%= scaffold_form(scaffold_url("#{action}#{@scaffold_suffix}"), :method=>(action
|
3
|
+
<%= scaffold_form(scaffold_url("#{action}#{@scaffold_suffix}"), :method=>scaffold_idempotent_action?(action) ? :get : :post) %>
|
4
4
|
<% if @scaffold_class.scaffold_use_auto_complete %>
|
5
5
|
<%= scaffold_text_field_tag_with_auto_complete('id', @scaffold_options[:singular_name]) %>
|
6
6
|
<% else %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffolding_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|