scaffolding_extensions 1.2.0 → 1.3.0

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 CHANGED
@@ -21,14 +21,14 @@ to better suit your needs.
21
21
  Scaffolding Extensions currently supports:
22
22
 
23
23
  * Web Frameworks
24
- * Rails 2.1
25
- * Ramaze 2008.06
24
+ * Rails 2.2.2
25
+ * Ramaze 2008.11
26
26
  * Camping 1.5
27
- * Sinatra 0.3.1
27
+ * Sinatra 0.3.2
28
+ * Merb 1.0.4
28
29
  * Object/Relational Mappers
29
- * ActiveRecord 2.1
30
- * DataMapper 0.3.1
31
- * Sequel 2.5.0
30
+ * ActiveRecord 2.2.2
31
+ * Sequel 2.8.0
32
32
  * Javascript Libaries (used for Ajax/Autocompleting)
33
33
  * Prototype 1.6.0.1
34
34
  * JQuery 1.2.3
data/doc/merb.txt ADDED
@@ -0,0 +1,13 @@
1
+ To use this plugin after installing the gem, somewhere in your Merb config,
2
+ add:
3
+
4
+ require 'scaffolding_extensions'
5
+
6
+ Then you can use scaffold, scaffold_habtm, or scaffold_all_models in your
7
+ controllers:
8
+
9
+ class Admin < Merb::Controller
10
+ scaffold Model1
11
+ scaffold_habtm Model1, :things
12
+ scaffold_all_models :only=>[Model1, Model2, Model3]
13
+ end
@@ -23,7 +23,7 @@ module ScaffoldingExtensions
23
23
  end
24
24
  end
25
25
 
26
- # Instance methods for ActionController::Base related necessary for Scaffolding Extensions
26
+ # Instance methods for ActionController::Base necessary for Scaffolding Extensions
27
27
  module ActionController
28
28
  private
29
29
  def scaffold_flash
@@ -93,7 +93,7 @@ module ScaffoldingExtensions
93
93
  end
94
94
  end
95
95
 
96
- # Class methods for ActionController::Base related necessary for Scaffolding Extensions
96
+ # Class methods for ActionController::Base necessary for Scaffolding Extensions
97
97
  module MetaActionController
98
98
  private
99
99
  # Adds a before filter for checking nonidempotent requests use method POST
@@ -0,0 +1,123 @@
1
+ module ScaffoldingExtensions
2
+ class << self
3
+ private
4
+ # Use whatever model directory Merb is using.
5
+ def model_files
6
+ @model_files ||= Dir["#{Merb.dir_for(:model)}/*.rb"]
7
+ end
8
+ end
9
+
10
+ # Helper methods for Merb that override the defaults in Scaffolding Extensions
11
+ module MerbControllerHelper
12
+ private
13
+ # Merb apparently requires that params that are desired to be lists have
14
+ # the suffix '[]'
15
+ def scaffold_param_list_suffix
16
+ '[]'
17
+ end
18
+ end
19
+
20
+ # Instance methods for Merb necessary for Scaffolding Extensions
21
+ module MerbController
22
+ private
23
+ def scaffold_flash
24
+ message
25
+ end
26
+
27
+ def scaffold_method_not_allowed
28
+ render('', :status=>405)
29
+ end
30
+
31
+ def scaffold_redirect_to(url)
32
+ redirect("#{request.protocol}://#{request.host}#{url}")
33
+ end
34
+
35
+ # Renders user provided template if it exists, otherwise renders a scaffold template.
36
+ # If a layout is specified (either in the controller or as an render_option), use that layout,
37
+ # otherwise uses the scaffolded layout. If :inline is one of the render_options,
38
+ # use the contents of it as the template without the layout.
39
+ #
40
+ # There may well be a much better way to do this via modifying the _template_roots, but
41
+ # I didn't have much luck and decided to take the path I used with Camping and Sinatra,
42
+ # rendering the templates directly.
43
+ def scaffold_render_template(action, options = {}, render_options = {})
44
+ suffix = options[:suffix]
45
+ suffix_action = "#{action}#{suffix}".to_sym
46
+ @scaffold_options ||= options
47
+ @scaffold_suffix ||= suffix
48
+ @scaffold_class ||= @scaffold_options[:class]
49
+ begin
50
+ render(suffix_action, render_options)
51
+ rescue Merb::ControllerExceptions::TemplateNotFound
52
+ if render_options.include?(:inline)
53
+ headers['Content-Type'] = 'text/javascript' if @scaffold_javascript
54
+ render(Erubis::Eruby.new(render_options[:inline]).result(binding), {:layout=>false}.merge(render_options))
55
+ else
56
+ html = Erubis::Eruby.new(File.read(scaffold_path(action))).result(binding)
57
+ merb_layout = begin
58
+ merb_layout = _get_layout
59
+ rescue Merb::ControllerExceptions::TemplateNotFound
60
+ merb_layout = false
61
+ end
62
+ if merb_layout
63
+ render(html, render_options)
64
+ else
65
+ @content = html
66
+ render(Erubis::Eruby.new(File.read(scaffold_path('layout'))).result(binding), render_options.merge(:layout=>false))
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def scaffold_request_action
73
+ params[:action]
74
+ end
75
+
76
+ def scaffold_request_env
77
+ request.env
78
+ end
79
+
80
+ # Merb overrides any given query params with the path params even if the
81
+ # path params are nil. Work around it by getting the query params
82
+ # directly.
83
+ def scaffold_request_id
84
+ params[:id] || request.send(:query_params)[:id]
85
+ end
86
+
87
+ def scaffold_request_method
88
+ request.method.to_s.upcase
89
+ end
90
+
91
+ def scaffold_request_param(v)
92
+ params[v]
93
+ end
94
+
95
+ def scaffold_session
96
+ session
97
+ end
98
+
99
+ def scaffold_url(action, options = {})
100
+ url(options.merge(:controller=>controller_name, :action=>action))
101
+ end
102
+ end
103
+
104
+ # Class methods for Merb necessary for Scaffolding Extensions
105
+ module MetaMerbController
106
+ private
107
+ # Adds a before filter for checking nonidempotent requests use method POST
108
+ def scaffold_setup_helper
109
+ include ScaffoldingExtensions::Helper
110
+ include ScaffoldingExtensions::MerbControllerHelper
111
+ include ScaffoldingExtensions::PrototypeHelper
112
+ include ScaffoldingExtensions::Controller
113
+ include ScaffoldingExtensions::MerbController
114
+ before :scaffold_check_nonidempotent_requests
115
+ end
116
+ end
117
+ end
118
+
119
+ # Add class methods necessary for Scaffolding Extensions
120
+ class Merb::Controller
121
+ extend ScaffoldingExtensions::MetaController
122
+ extend ScaffoldingExtensions::MetaMerbController
123
+ end
@@ -1,5 +1,3 @@
1
- require 'scaffolding_extensions/model/ardm'
2
-
3
1
  ScaffoldingExtensions::MODEL_SUPERCLASSES << ::ActiveRecord::Base
4
2
 
5
3
  # Instance methods added to ActiveRecord::Base to allow it to work with Scaffolding Extensions.
@@ -8,6 +6,11 @@ module ScaffoldingExtensions::ActiveRecord
8
6
  def scaffold_attribute_value(field)
9
7
  self[field]
10
8
  end
9
+
10
+ # the value of the primary key for this object
11
+ def scaffold_id
12
+ id
13
+ end
11
14
  end
12
15
 
13
16
  # Class methods added to ActiveRecord::Base to allow it to work with Scaffolding Extensions.
@@ -138,6 +141,32 @@ module ScaffoldingExtensions::MetaActiveRecord
138
141
  end
139
142
 
140
143
  private
144
+ # Merge an array of conditions into a single condition array
145
+ def scaffold_merge_conditions(conditions)
146
+ new_conditions = [[]]
147
+ if Array === conditions
148
+ if conditions.length == 0 || (conditions.length == 1 && conditions[0].nil?)
149
+ nil
150
+ elsif Array === conditions[0]
151
+ conditions.each do |cond|
152
+ next unless cond
153
+ new_conditions[0] << cond.shift
154
+ cond.each{|c| new_conditions << c}
155
+ end
156
+ if new_conditions[0].length > 0
157
+ new_conditions[0] = "(#{new_conditions[0].join(") AND (")})"
158
+ new_conditions
159
+ else
160
+ nil
161
+ end
162
+ else
163
+ conditions
164
+ end
165
+ else
166
+ conditions
167
+ end
168
+ end
169
+
141
170
  # Updates associated records for a given reflection and from record to point to the
142
171
  # to record
143
172
  def scaffold_reflection_merge(reflection, from, to)
@@ -153,16 +182,19 @@ module ScaffoldingExtensions::MetaActiveRecord
153
182
  end
154
183
  connection.update(sql)
155
184
  end
185
+
186
+ # Remove the associated object from object's association
187
+ def scaffold_remove_associated_object(association, object, associated_object)
188
+ object.send(association).delete(associated_object)
189
+ end
156
190
  end
157
191
 
158
192
  # Add the class methods and instance methods from Scaffolding Extensions
159
193
  class ActiveRecord::Base
160
194
  SCAFFOLD_OPTIONS = ::ScaffoldingExtensions::MetaModel::SCAFFOLD_OPTIONS
161
195
  include ScaffoldingExtensions::Model
162
- include ScaffoldingExtensions::ARDM
163
196
  include ScaffoldingExtensions::ActiveRecord
164
197
  extend ScaffoldingExtensions::MetaModel
165
- extend ScaffoldingExtensions::MetaARDM
166
198
  extend ScaffoldingExtensions::MetaActiveRecord
167
199
  extend ScaffoldingExtensions::Overridable
168
200
  end
@@ -82,9 +82,9 @@ require 'scaffolding_extensions/controller/action_controller' if defined? Action
82
82
  require 'scaffolding_extensions/controller/camping' if defined? Camping::Controllers
83
83
  require 'scaffolding_extensions/controller/ramaze' if defined? Ramaze::Controller
84
84
  require 'scaffolding_extensions/controller/sinatra' if defined? Sinatra
85
+ require 'scaffolding_extensions/controller/merb' if defined? Merb
85
86
 
86
87
  require 'scaffolding_extensions/model/active_record' if defined? ActiveRecord::Base
87
- require 'scaffolding_extensions/model/data_mapper' if defined? DataMapper::Base
88
88
  require 'scaffolding_extensions/model/sequel' if defined? Sequel::Model
89
89
 
90
90
  ScaffoldingExtensions.javascript_library = 'Prototype'
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.2.0
4
+ version: 1.3.0
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: 2008-09-09 00:00:00 -07:00
12
+ date: 2008-12-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,6 +32,7 @@ files:
32
32
  - lib/scaffolding_extensions/controller/camping.rb
33
33
  - lib/scaffolding_extensions/controller/ramaze.rb
34
34
  - lib/scaffolding_extensions/controller/sinatra.rb
35
+ - lib/scaffolding_extensions/controller/merb.rb
35
36
  - lib/scaffolding_extensions/helper.rb
36
37
  - lib/scaffolding_extensions/jquery_helper.rb
37
38
  - lib/scaffolding_extensions/meta_controller.rb
@@ -39,8 +40,6 @@ files:
39
40
  - lib/scaffolding_extensions/model.rb
40
41
  - lib/scaffolding_extensions/model
41
42
  - lib/scaffolding_extensions/model/active_record.rb
42
- - lib/scaffolding_extensions/model/ardm.rb
43
- - lib/scaffolding_extensions/model/data_mapper.rb
44
43
  - lib/scaffolding_extensions/model/sequel.rb
45
44
  - lib/scaffolding_extensions/overridable.rb
46
45
  - lib/scaffolding_extensions/prototype_helper.rb
@@ -53,6 +52,7 @@ files:
53
52
  - doc/ramaze.txt
54
53
  - doc/sinatra.txt
55
54
  - doc/testing.txt
55
+ - doc/merb.txt
56
56
  - contrib/scaffold_associations_tree
57
57
  - contrib/scaffold_associations_tree/README
58
58
  - contrib/scaffold_associations_tree/bullet.gif
@@ -98,6 +98,7 @@ rdoc_options:
98
98
  - doc/ramaze.txt
99
99
  - doc/sinatra.txt
100
100
  - doc/testing.txt
101
+ - doc/merb.txt
101
102
  require_paths:
102
103
  - lib
103
104
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -115,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  requirements: []
116
117
 
117
118
  rubyforge_project: scaffolding-ext
118
- rubygems_version: 1.0.1
119
+ rubygems_version: 1.3.1
119
120
  signing_key:
120
121
  specification_version: 2
121
122
  summary: Administrative database front-end for multiple web-frameworks and ORMs
@@ -1,42 +0,0 @@
1
- # Instance methods used by both ActiveRecord and Datamapper
2
- module ScaffoldingExtensions::ARDM
3
- # the value of the primary key for this object
4
- def scaffold_id
5
- id
6
- end
7
- end
8
-
9
- # Class methods used by both ActiveRecord and DataMapper
10
- module ScaffoldingExtensions::MetaARDM
11
- private
12
- # Merge an array of conditions into a single condition array
13
- def scaffold_merge_conditions(conditions)
14
- new_conditions = [[]]
15
- if Array === conditions
16
- if conditions.length == 0 || (conditions.length == 1 && conditions[0].nil?)
17
- nil
18
- elsif Array === conditions[0]
19
- conditions.each do |cond|
20
- next unless cond
21
- new_conditions[0] << cond.shift
22
- cond.each{|c| new_conditions << c}
23
- end
24
- if new_conditions[0].length > 0
25
- new_conditions[0] = "(#{new_conditions[0].join(") AND (")})"
26
- new_conditions
27
- else
28
- nil
29
- end
30
- else
31
- conditions
32
- end
33
- else
34
- conditions
35
- end
36
- end
37
-
38
- # Remove the associated object from object's association
39
- def scaffold_remove_associated_object(association, object, associated_object)
40
- object.send(association).delete(associated_object)
41
- end
42
- end
@@ -1,174 +0,0 @@
1
- require 'scaffolding_extensions/model/ardm'
2
-
3
- ScaffoldingExtensions::MODEL_SUPERCLASSES << ::DataMapper::Base
4
-
5
- # Instance methods added to DataMapper::Base to allow it to work with Scaffolding Extensions.
6
- module ScaffoldingExtensions::DataMapper
7
- # Get value for given attribute
8
- def scaffold_attribute_value(field)
9
- attributes[field]
10
- end
11
- end
12
-
13
- # Class methods added to DataMapper::Base to allow it to work with Scaffolding Extensions.
14
- module ScaffoldingExtensions::MetaDataMapper
15
- SCAFFOLD_OPTIONS = ::ScaffoldingExtensions::MetaModel::SCAFFOLD_OPTIONS
16
-
17
- # Add the associated object to the object's association
18
- def scaffold_add_associated_object(association, object, associated_object)
19
- association_proxy = object.send(association)
20
- next if association_proxy.include?(associated_object)
21
- association_proxy << associated_object
22
- object.save
23
- end
24
-
25
- # Array of all association reflections for this model
26
- def scaffold_all_associations
27
- database.schema[self].associations.to_a
28
- end
29
-
30
- # The class that this model is associated with via the association
31
- def scaffold_associated_class(association)
32
- case reflection = scaffold_association(association)
33
- when DataMapper::Associations::HasManyAssociation
34
- reflection.associated_constant
35
- else
36
- reflection.constant
37
- end
38
- end
39
-
40
- # The association reflection for this association
41
- def scaffold_association(association)
42
- database.schema[self].associations.each{|assoc| return assoc if assoc.name == association}
43
- nil
44
- end
45
-
46
- # The type of association, either :new for :has_many (as you can create new objects
47
- # associated with the current object), :edit for :has_and_belongs_to_many (since you
48
- # can edit the list of associated objects), or :one for other associations. I'm not
49
- # sure that :has_one is supported, as I don't use it.
50
- def scaffold_association_type(association)
51
- case scaffold_association(association)
52
- when DataMapper::Associations::HasManyAssociation
53
- :new
54
- when DataMapper::Associations::HasAndBelongsToManyAssociation
55
- :edit
56
- else
57
- :one
58
- end
59
- end
60
-
61
- # List of symbols for associations to display on the scaffolded edit page. Defaults to
62
- # all associations that aren't :through or :polymorphic. Can be set with an instance variable.
63
- def scaffold_associations
64
- @scaffold_associations ||= scaffold_all_associations.collect{|assoc| assoc.name}.sort_by{|name| name.to_s}
65
- end
66
-
67
- # Destroys the object
68
- def scaffold_destroy(object)
69
- object.destroy!
70
- end
71
-
72
- # The error to raise, should match other errors raised by the underlying library.
73
- # I'm not sure that this is the correct error, but it is the most common error I've
74
- # received.
75
- def scaffold_error_raised
76
- ::DataObject::ReaderClosed
77
- end
78
-
79
- # Returns the list of fields to display on the scaffolded forms. Defaults
80
- # to displaying all columns with the exception of primary key column, timestamp columns,
81
- # count columns, and inheritance columns. Also includes belongs_to associations, replacing
82
- # the foriegn keys with the association itself. Can be set with an instance variable.
83
- def scaffold_fields(action = :default)
84
- return @scaffold_fields if @scaffold_fields
85
- schema = database.schema[self]
86
- key = schema.key.name
87
- fields = schema.columns.to_a.collect{|x| x.name}.reject{|x| x == key}
88
- schema.associations.each do |r|
89
- next unless DataMapper::Associations::BelongsToAssociation === r
90
- fields << r.name
91
- fields.delete(r.foreign_key_name.to_sym)
92
- end
93
- @scaffold_fields = fields.sort_by{|x| x.to_s}
94
- end
95
-
96
- # The foreign key for the given reflection
97
- def scaffold_foreign_key(reflection)
98
- reflection.foreign_key_name
99
- end
100
-
101
- # Retrieve a single model object given an id
102
- def scaffold_get_object(id)
103
- self[id]
104
- end
105
-
106
- # Retrieve multiple objects given a hash of options
107
- def scaffold_get_objects(options)
108
- options[:conditions] = scaffold_merge_conditions(options[:conditions])
109
- all(options)
110
- end
111
-
112
- # Return the class, left foreign key, right foreign key, and join table for this habtm association
113
- def scaffold_habtm_reflection_options(association)
114
- reflection = scaffold_association(association)
115
- [reflection.constant, reflection.left_foreign_key, reflection.right_foreign_key, reflection.join_table]
116
- end
117
-
118
- # Returns a hash of values to be used as url parameters on the link to create a new
119
- # :has_many associated object. Defaults to setting the foreign key field to the
120
- # record's primary key.
121
- def scaffold_new_associated_object_values(association, record)
122
- {scaffold_foreign_key(scaffold_association(association))=>record.id}
123
- end
124
-
125
- # The primary key for the given table
126
- def scaffold_primary_key
127
- database.schema[self].key.name
128
- end
129
-
130
- # Saves the object.
131
- def scaffold_save(action, object)
132
- object.save rescue false
133
- end
134
-
135
- # The column type for the given table column, or nil if it isn't a table column
136
- def scaffold_table_column_type(column)
137
- column = database.schema[self][column]
138
- column.type if column
139
- end
140
-
141
- # The name of the underlying table
142
- def scaffold_table_name
143
- database.schema[self].name
144
- end
145
-
146
- private
147
- # Updates associated records for a given reflection and from record to point to the
148
- # to record
149
- def scaffold_reflection_merge(reflection, from, to)
150
- sql = case reflection
151
- when DataMapper::Associations::HasManyAssociation
152
- foreign_key = scaffold_foreign_key(reflection)
153
- "UPDATE #{reflection.associated_constant.scaffold_table_name} SET #{foreign_key} = #{to} WHERE #{foreign_key} = #{from}"
154
- when DataMapper::Associations::HasAndBelongsToManyAssociation
155
- foreign_key = reflection.left_foreign_key
156
- "UPDATE #{reflection.join_table} SET #{foreign_key} = #{to} WHERE #{foreign_key} = #{from}"
157
- else
158
- return
159
- end
160
- database.execute(sql)
161
- end
162
- end
163
-
164
- # Add the class methods and instance methods from Scaffolding Extensions
165
- class DataMapper::Base
166
- SCAFFOLD_OPTIONS = ::ScaffoldingExtensions::MetaModel::SCAFFOLD_OPTIONS
167
- include ScaffoldingExtensions::Model
168
- include ScaffoldingExtensions::ARDM
169
- include ScaffoldingExtensions::DataMapper
170
- extend ScaffoldingExtensions::MetaModel
171
- extend ScaffoldingExtensions::MetaARDM
172
- extend ScaffoldingExtensions::MetaDataMapper
173
- extend ScaffoldingExtensions::Overridable
174
- end