merb-admin 0.6.6 → 0.6.7

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.rdoc CHANGED
@@ -11,7 +11,7 @@ http://github.com/sferik/merb-admin/raw/master/screenshots/edit.png
11
11
  == Installation
12
12
  $ gem install merb-admin -s http://gemcutter.org
13
13
  In your app, add the following dependency to <tt>config/dependencies.rb</tt>:
14
- dependency "merb-admin", "0.6.6"
14
+ dependency "merb-admin", "0.6.7"
15
15
  Add the following route to <tt>config/router.rb</tt>:
16
16
  add_slice(:merb_admin, :path_prefix => "admin")
17
17
  Then, run the following rake task:
@@ -21,7 +21,7 @@ If you're feeling crafty, you can set a couple configuration options in <tt>conf
21
21
  Merb::BootLoader.before_app_loads do
22
22
  Merb::Slices::config[:merb_admin][:app_name] = "My App"
23
23
  Merb::Slices::config[:merb_admin][:per_page] = 100
24
- Merb::Slices::config[:merb_admin][:excluded_models] = [:Top, :Secret]
24
+ Merb::Slices::config[:merb_admin][:excluded_models] = ["Top", "Secret"]
25
25
  end
26
26
  == Usage
27
27
  Start the server:
@@ -67,7 +67,7 @@ class MerbAdmin::Main < MerbAdmin::Application
67
67
 
68
68
  def destroy
69
69
  if @object.destroy
70
- redirect(url(:merb_admin_list, :model_name => @abstract_model.singular_name), :message => {:notice => "#{@abstract_model.pretty_name} was successfully destroyed"})
70
+ redirect(url(:merb_admin_list, :model_name => @abstract_model.to_param), :message => {:notice => "#{@abstract_model.pretty_name} was successfully destroyed"})
71
71
  else
72
72
  raise BadRequest
73
73
  end
@@ -80,7 +80,7 @@ class MerbAdmin::Main < MerbAdmin::Application
80
80
  end
81
81
 
82
82
  def get_model
83
- model_name = params[:model_name].camel_case
83
+ model_name = to_model_name(params[:model_name])
84
84
  @abstract_model = MerbAdmin::AbstractModel.new(model_name)
85
85
  get_properties
86
86
  end
@@ -143,7 +143,7 @@ class MerbAdmin::Main < MerbAdmin::Application
143
143
  end
144
144
 
145
145
  def get_attributes
146
- @attributes = params[@abstract_model.singular_name] || {}
146
+ @attributes = params[@abstract_model.to_param] || {}
147
147
  # Delete fields that are blank
148
148
  @attributes.each do |key, value|
149
149
  @attributes[key] = nil if value.blank?
@@ -170,24 +170,21 @@ class MerbAdmin::Main < MerbAdmin::Application
170
170
  end
171
171
 
172
172
  def update_associations(association, ids = [])
173
- associated_object = @object.send(association[:name])
174
- @object.clear_association(associated_object)
175
- @object.save
176
173
  ids.each do |id|
177
174
  update_association(association, id)
178
175
  end
179
176
  end
180
177
 
181
178
  def redirect_on_success
182
- singular_name = @abstract_model.singular_name
179
+ param = @abstract_model.to_param
183
180
  pretty_name = @abstract_model.pretty_name
184
181
  action = params[:action]
185
182
  if params[:_continue]
186
- redirect(url(:merb_admin_edit, :model_name => singular_name, :id => @object.id), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
183
+ redirect(url(:merb_admin_edit, :model_name => param, :id => @object.id), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
187
184
  elsif params[:_add_another]
188
- redirect(url(:merb_admin_new, :model_name => singular_name), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
185
+ redirect(url(:merb_admin_new, :model_name => param), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
189
186
  else
190
- redirect(url(:merb_admin_list, :model_name => singular_name), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
187
+ redirect(url(:merb_admin_list, :model_name => param), :message => {:notice => "#{pretty_name} was successfully #{action}d"})
191
188
  end
192
189
  end
193
190
 
@@ -2,6 +2,10 @@ require 'builder'
2
2
  module Merb
3
3
  module MerbAdmin
4
4
  module MainHelper
5
+ def to_model_name(param)
6
+ param.split("__").map{|x| x.camel_case}.join("::")
7
+ end
8
+
5
9
  def object_label(object)
6
10
  if object.nil?
7
11
  nil
@@ -32,7 +32,7 @@
32
32
  </div>
33
33
  <div class="breadcrumbs">
34
34
  <%= link_to("Home", url(:merb_admin_dashboard)) %> &rsaquo;
35
- <%= link_to(@abstract_model.plural_name.to_s.capitalize, url(:merb_admin_list, :model_name => @abstract_model.singular_name)) %> &rsaquo;
35
+ <%= link_to(@abstract_model.pretty_name, url(:merb_admin_list, :model_name => @abstract_model.to_param)) %> &rsaquo;
36
36
  <%= page_name %>
37
37
  </div>
38
38
  <%= partial('layout/message', :message => message) unless message.blank? -%>
@@ -27,7 +27,7 @@
27
27
  </div>
28
28
  <div class="breadcrumbs">
29
29
  <%= link_to("Home", url(:merb_admin_dashboard)) %> &rsaquo;
30
- <%= @abstract_model.plural_name.to_s.capitalize %>
30
+ <%= @abstract_model.pretty_name %>
31
31
  </div>
32
32
  <%= partial('layout/message', :message => message) unless message.blank? -%>
33
33
  <div id="content" class="flex">
@@ -1,7 +1,7 @@
1
1
  <p>Are you sure you want to delete the <%= @abstract_model.pretty_name.downcase %> &ldquo;<%= object_label(@object) %>&rdquo;? All of the following related items will be deleted:</p>
2
2
  <ul>
3
3
  <li>
4
- <%= @abstract_model.pretty_name %>: <%= link_to(object_label(@object), url(:merb_admin_edit, :model_name => @abstract_model.singular_name, :id => @object.id)) %>
4
+ <%= @abstract_model.pretty_name %>: <%= link_to(object_label(@object), url(:merb_admin_edit, :model_name => @abstract_model.to_param, :id => @object.id)) %>
5
5
  <ul>
6
6
  <% @abstract_model.has_many_associations.each do |association| %>
7
7
  <% @object.send(association[:name]).reject{|child| child.nil?}.each do |child| %>
@@ -20,7 +20,7 @@
20
20
  </ul>
21
21
  </li>
22
22
  </ul>
23
- <%= form_for(@object, :action => url(:merb_admin_destroy, :model_name => @abstract_model.singular_name, :id => @object.id), :method => :delete) do %>
23
+ <%= form_for(@object, :action => url(:merb_admin_destroy, :model_name => @abstract_model.to_param, :id => @object.id), :method => :delete) do %>
24
24
  <div>
25
25
  <%= submit "Yes, I'm sure" %>
26
26
  </div>
@@ -1,5 +1,5 @@
1
1
  <div id="content-main">
2
- <%= form_for(@object, :action => url(:merb_admin_update, :model_name => @abstract_model.singular_name, :id => @object.id)) do %>
2
+ <%= form_for(@object, :action => url(:merb_admin_update, :model_name => @abstract_model.to_param, :id => @object.id)) do %>
3
3
  <div>
4
4
  <%= partial('properties', :properties => @properties) -%>
5
5
  <%= partial('belongs_to', :with => @abstract_model.belongs_to_associations, :as => :association) -%>
@@ -8,7 +8,7 @@
8
8
  <div class="submit-row" >
9
9
  <%= submit "Save", :class => "default", :name => "_save" %>
10
10
  <p class="deletelink-box">
11
- <%= link_to("Delete", url(:merb_admin_delete, :model_name => @abstract_model.singular_name, :id => @object.id), :class => "deletelink") %>
11
+ <%= link_to("Delete", url(:merb_admin_delete, :model_name => @abstract_model.to_param, :id => @object.id), :class => "deletelink") %>
12
12
  </p>
13
13
  <%= submit "Save and add another", :name => "_add_another" %>
14
14
  <%= submit "Save and continue editing", :name => "_continue" %>
@@ -7,13 +7,13 @@
7
7
  <% @abstract_models.each do |abstract_model| %>
8
8
  <tr>
9
9
  <th scope="row">
10
- <%= link_to(abstract_model.plural_name.to_s.capitalize, url(:merb_admin_list, :model_name => abstract_model.singular_name)) %>
10
+ <%= link_to(abstract_model.pretty_name, url(:merb_admin_list, :model_name => abstract_model.to_param)) %>
11
11
  </th>
12
12
  <td>
13
- <%= link_to("Add", url(:merb_admin_new, :model_name => abstract_model.singular_name), :class => "addlink") %>
13
+ <%= link_to("Add", url(:merb_admin_new, :model_name => abstract_model.to_param), :class => "addlink") %>
14
14
  </td>
15
15
  <td>
16
- <%= link_to("Edit", url(:merb_admin_list, :model_name => abstract_model.singular_name), :class => "changelink") %>
16
+ <%= link_to("Edit", url(:merb_admin_list, :model_name => abstract_model.to_param), :class => "changelink") %>
17
17
  </td>
18
18
  </tr>
19
19
  <% end %>
@@ -9,7 +9,7 @@
9
9
  <div id="content-main">
10
10
  <ul class="object-tools">
11
11
  <li>
12
- <%= link_to("Add #{@abstract_model.pretty_name.downcase}", url(:merb_admin_new, :model_name => @abstract_model.singular_name), :class => "addlink") %>
12
+ <%= link_to("Add #{@abstract_model.pretty_name.downcase}", url(:merb_admin_new, :model_name => @abstract_model.to_param), :class => "addlink") %>
13
13
  </li>
14
14
  </ul>
15
15
  <div class="<%= filters_exist ? "module filtered" : "module" %>" id="changelist">
@@ -72,7 +72,7 @@
72
72
  <tr class="row<%= index % 2 == 0 ? "1" : "2" %>">
73
73
  <% @properties.each do |property| %>
74
74
  <td>
75
- <%= link_to(object_property(object, property), url(:merb_admin_edit, :model_name => @abstract_model.singular_name, :id => object.id)) %>
75
+ <%= link_to(object_property(object, property), url(:merb_admin_edit, :model_name => @abstract_model.to_param, :id => object.id)) %>
76
76
  </td>
77
77
  <% end %>
78
78
  </tr>
@@ -1,5 +1,5 @@
1
1
  <div id="content-main">
2
- <%= form_for(@object, :action => url(:merb_admin_create, :model_name => @abstract_model.singular_name)) do %>
2
+ <%= form_for(@object, :action => url(:merb_admin_create, :model_name => @abstract_model.to_param)) do %>
3
3
  <div>
4
4
  <%= partial('properties', :properties => @properties) -%>
5
5
  <%= partial('belongs_to', :with => @abstract_model.belongs_to_associations, :as => :association) -%>
@@ -10,29 +10,29 @@ module MerbAdmin
10
10
  when :activerecord, :sequel
11
11
  Dir.glob(Merb.dir_for(:model) / Merb.glob_for(:model)).each do |filename|
12
12
  File.read(filename).scan(/class ([\w\d_\-:]+)/).flatten.each do |model_name|
13
- add_model(model_name.to_sym)
13
+ add_model(model_name)
14
14
  end
15
15
  end
16
16
  when :datamapper
17
- DataMapper::Model.descendants.each do |model_name|
18
- add_model(model_name.to_s.to_sym)
17
+ DataMapper::Model.descendants.each do |model|
18
+ add_model(model.to_s)
19
19
  end
20
20
  else
21
21
  raise "MerbAdmin does not support the #{orm} ORM"
22
22
  end
23
23
  @models.sort!{|x, y| x.model.to_s <=> y.model.to_s}
24
24
  end
25
-
26
- def self.add_model(name)
27
- return if MerbAdmin[:excluded_models].include?(name)
28
- model = lookup(name)
25
+
26
+ def self.add_model(model_name)
27
+ model = lookup(model_name)
29
28
  @models << new(model) if model
30
29
  end
31
30
 
32
- # Given a symbol +model_name+, finds the corresponding model class
31
+ # Given a string +model_name+, finds the corresponding model class
33
32
  def self.lookup(model_name)
33
+ return nil if MerbAdmin[:excluded_models].include?(model_name)
34
34
  begin
35
- model = Object.full_const_get(model_name.to_s)
35
+ model = Object.full_const_get(model_name)
36
36
  rescue NameError
37
37
  raise "MerbAdmin could not find model #{model_name}"
38
38
  end
@@ -39,7 +39,7 @@ module MerbAdmin
39
39
  end
40
40
 
41
41
  def create(params = {})
42
- model.create(params)
42
+ model.create(params).extend(InstanceMethods)
43
43
  end
44
44
 
45
45
  def new(params = {})
@@ -143,9 +143,6 @@ module MerbAdmin
143
143
  end
144
144
 
145
145
  module InstanceMethods
146
- def clear_association(association)
147
- association.clear
148
- end
149
146
  end
150
147
 
151
148
  end
@@ -39,7 +39,7 @@ module MerbAdmin
39
39
  end
40
40
 
41
41
  def create(params = {})
42
- model.create(params)
42
+ model.create(params).extend(InstanceMethods)
43
43
  end
44
44
 
45
45
  def new(params = {})
@@ -136,10 +136,6 @@ module MerbAdmin
136
136
  def update_attributes(attributes)
137
137
  update(attributes)
138
138
  end
139
-
140
- def clear_association(association)
141
- association.clear
142
- end
143
139
  end
144
140
 
145
141
  end
@@ -1,12 +1,8 @@
1
1
  module MerbAdmin
2
2
  class AbstractModel
3
3
  module GenericSupport
4
- def singular_name
5
- model.to_s.snake_case.to_sym
6
- end
7
-
8
- def plural_name
9
- model.to_s.snake_case.pluralize.to_sym
4
+ def to_param
5
+ model.to_s.snake_case.gsub("::", "__")
10
6
  end
11
7
 
12
8
  def pretty_name
data/lib/merb-admin.rb CHANGED
@@ -24,7 +24,7 @@ if defined?(Merb::Plugins)
24
24
 
25
25
  # Slice metadata
26
26
  self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
27
- self.version = "0.6.6"
27
+ self.version = "0.6.7"
28
28
  self.author = "Erik Michaels-Ober"
29
29
 
30
30
  # Stub classes loaded hook - runs before LoadClasses BootLoader
@@ -76,7 +76,7 @@ module MerbAdmin
76
76
  end
77
77
 
78
78
  def create(params = {})
79
- model.create(params)
79
+ model.create(params).extend(InstanceMethods)
80
80
  end
81
81
 
82
82
  def new(params = {})
@@ -268,11 +268,6 @@ module MerbAdmin
268
268
  def update_attributes(attributes)
269
269
  update(attributes)
270
270
  end
271
-
272
- def clear_association(association)
273
- # FIXME: This should be changed to use the remove_all_* association method.
274
- association.clear
275
- end
276
271
  end
277
272
 
278
273
  end
@@ -80,16 +80,13 @@ describe "MerbAdmin" do
80
80
  it "should show \"Site administration\"" do
81
81
  @response.body.should contain("Site administration")
82
82
  end
83
-
84
- it "should be sorted correctly" do
85
- @response.body.should contain(/Division.*Draft.*League.*Player.*Team/m)
86
- end
87
83
  end
88
84
 
89
85
  describe "dashboard with excluded models" do
90
86
  before(:each) do
91
- MerbAdmin[:excluded_models] = [:Player]
87
+ MerbAdmin[:excluded_models] = ["Player"]
92
88
  @response = request(url(:merb_admin_dashboard))
89
+ MerbAdmin[:excluded_models] = []
93
90
  end
94
91
 
95
92
  it "should respond sucessfully" do
@@ -245,9 +242,9 @@ describe "MerbAdmin" do
245
242
 
246
243
  describe "list with 2 objects", :given => "two players exist" do
247
244
  before(:each) do
248
- MerbAdmin[:paginate] = true
249
245
  MerbAdmin[:per_page] = 1
250
246
  @response = request(url(:merb_admin_list, :model_name => "player"))
247
+ MerbAdmin[:per_page] = 100
251
248
  end
252
249
 
253
250
  it "should respond sucessfully" do
@@ -261,9 +258,9 @@ describe "MerbAdmin" do
261
258
 
262
259
  describe "list with 20 objects", :given => "twenty players exist" do
263
260
  before(:each) do
264
- MerbAdmin[:paginate] = true
265
261
  MerbAdmin[:per_page] = 1
266
262
  @response = request(url(:merb_admin_list, :model_name => "player"))
263
+ MerbAdmin[:per_page] = 100
267
264
  end
268
265
 
269
266
  it "should respond sucessfully" do
@@ -277,9 +274,9 @@ describe "MerbAdmin" do
277
274
 
278
275
  describe "list with 20 objects, page 8", :given => "twenty players exist" do
279
276
  before(:each) do
280
- MerbAdmin[:paginate] = true
281
277
  MerbAdmin[:per_page] = 1
282
278
  @response = request(url(:merb_admin_list, :model_name => "player"), :params => {:page => 8})
279
+ MerbAdmin[:per_page] = 100
283
280
  end
284
281
 
285
282
  it "should respond sucessfully" do
@@ -293,9 +290,9 @@ describe "MerbAdmin" do
293
290
 
294
291
  describe "list with 20 objects, page 17", :given => "twenty players exist" do
295
292
  before(:each) do
296
- MerbAdmin[:paginate] = true
297
293
  MerbAdmin[:per_page] = 1
298
294
  @response = request(url(:merb_admin_list, :model_name => "player"), :params => {:page => 17})
295
+ MerbAdmin[:per_page] = 100
299
296
  end
300
297
 
301
298
  it "should respond sucessfully" do
@@ -309,9 +306,9 @@ describe "MerbAdmin" do
309
306
 
310
307
  describe "list show all", :given => "two players exist" do
311
308
  before(:each) do
312
- MerbAdmin[:paginate] = true
313
309
  MerbAdmin[:per_page] = 1
314
310
  @response = request(url(:merb_admin_list, :model_name => "player"), :params => {:all => true})
311
+ MerbAdmin[:per_page] = 100
315
312
  end
316
313
 
317
314
  it "should respond sucessfully" do
data/spec/spec_helper.rb CHANGED
@@ -64,7 +64,6 @@ module Merb
64
64
  end
65
65
  when :sequel
66
66
  require 'sequel'
67
- require 'sequel/extensions/blank'
68
67
  require 'sequel/extensions/migration'
69
68
  Sequel::Migrator.apply(Sequel.sqlite, File.join(File.dirname(__FILE__), "migrations", "sequel"))
70
69
  require_models(orm)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-13 00:00:00 -08:00
12
+ date: 2009-11-19 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency