activeadmin 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeadmin might be problematic. Click here for more details.

Files changed (41) hide show
  1. data/CHANGELOG.md +63 -15
  2. data/Gemfile +1 -0
  3. data/README.rdoc +1 -14
  4. data/docs/3-index-pages/index-as-table.md +8 -2
  5. data/features/comments/commenting.feature +14 -1
  6. data/features/index/index_scope_to.feature +3 -0
  7. data/features/index/index_scopes.feature +13 -0
  8. data/features/menu.feature +0 -31
  9. data/features/new_page.feature +23 -0
  10. data/features/site_title.feature +47 -0
  11. data/features/step_definitions/comment_steps.rb +5 -0
  12. data/features/step_definitions/user_steps.rb +7 -4
  13. data/lib/active_admin/arbre/builder.rb +12 -1
  14. data/lib/active_admin/comments.rb +5 -5
  15. data/lib/active_admin/comments/views/active_admin_comments.rb +3 -3
  16. data/lib/active_admin/dependency_checker.rb +12 -0
  17. data/lib/active_admin/engine.rb +5 -0
  18. data/lib/active_admin/inputs/filter_base.rb +1 -1
  19. data/lib/active_admin/locales/de.yml +10 -0
  20. data/lib/active_admin/locales/en.yml +11 -1
  21. data/lib/active_admin/locales/fr.yml +15 -0
  22. data/lib/active_admin/locales/zh-TW.yml +45 -0
  23. data/lib/active_admin/scope.rb +2 -1
  24. data/lib/active_admin/version.rb +1 -1
  25. data/lib/active_admin/view_helpers/method_or_proc_helper.rb +12 -0
  26. data/lib/active_admin/views/components/scopes.rb +1 -1
  27. data/lib/active_admin/views/header_renderer.rb +22 -16
  28. data/lib/active_admin/views/pages/base.rb +1 -0
  29. data/lib/active_admin/views/pages/form.rb +3 -1
  30. data/lib/generators/active_admin/devise/devise_generator.rb +0 -1
  31. data/lib/generators/active_admin/install/install_generator.rb +3 -1
  32. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +3 -3
  33. data/lib/generators/active_admin/install/templates/migrations/1_create_admin_notes.rb +2 -1
  34. data/spec/support/rails_template.rb +18 -0
  35. data/spec/unit/arbre/html_spec.rb +9 -0
  36. data/spec/unit/comments_spec.rb +13 -0
  37. data/spec/unit/filter_form_builder_spec.rb +9 -0
  38. data/spec/unit/form_builder_spec.rb +5 -0
  39. data/spec/unit/renderer_spec.rb +18 -0
  40. data/spec/unit/scope_spec.rb +14 -0
  41. metadata +7 -4
@@ -1,29 +1,51 @@
1
1
  ## Master (unreleased)
2
2
 
3
+ ## 0.4.2
4
+
5
+ ### Enhancements
6
+
7
+ * [#822][]: Automatically include js and css to precompile list ([@jschwindt][])
8
+ * [#1033][]: Site title accepts a proc that is rendered in the context
9
+ of the view ([@pcreux][])
10
+ * [#70][]: Form blocks are now rendered within the context of the view ([@gregbell][])
11
+ * [#70][]: Filter's collections are now eval'd in the context of the view ([@gregbell][])
12
+ * [#1032][]: The html body now includes a class for the namespace name ([@mattvague][])
13
+ * [#1013][]: Hide the count from one specific scope using `:show_count => false`
14
+ ([@latortuga][])
15
+
16
+ ### Bug Fixes
17
+
18
+ * [#34][]: Comments now work with models using string ids ([@jancel][])
19
+ * [#1041][]: When `table_for` collection is empty it no longer outputs
20
+ a blank array in Ruby 1.9 ([@jancel][], [#1016][])
21
+ * [#983][]: Fixed compatibility with pry-rails ([@pcreux][])
22
+ * [#409][]: Install generator handles custom class names for user ([@gregbell][])
23
+
24
+
3
25
  ## 0.4.1
4
26
 
5
27
  ### Enhancements
6
28
 
7
- * #865: Pages support the `#page_action` to add custom controller actions
8
- to a page (@BoboFraggins)
29
+ * [#865][]: Pages support the `#page_action` to add custom controller actions
30
+ to a page ([@BoboFraggins][])
9
31
  * Columns component now supports column spans, max and min widths ([@gregbell][])
10
- * #497: Custom pagination settings per resource (@pcreux)
11
- * #993: Login form now focuses on email (@mattvague)
12
- * #865: Add `:if` support to sidebar sections (@BoboFraggins)
13
- * #865: Added `:scope_count => false` to the index to hide scope counts
14
- in generated scopes (@BoboFraggins)
32
+ * [#497][]: Custom pagination settings per resource ([@pcreux][])
33
+ * [#993][]: Login form now focuses on email ([@mattvague][])
34
+ * [#865][]: Add `:if` support to sidebar sections ([@BoboFraggins][])
35
+ * [#865][]: Added `:scope_count => false` to the index to hide scope counts
36
+ in generated scopes ([@BoboFraggins][])
15
37
 
16
38
  ### Bug Fixes
17
39
 
18
- * #101: Global nav now works with RackBaseURI ([@gregbell][])
19
- * #960: Global nav works when scoped in rails routes ([@gregbell][])
20
- * #994: Fix index page check collection.limit(1).exists? causes exception when
21
- ordering by virtual colum (@latortuga, @gregbell)
22
- * #971: Fix SQL when sorting tables with a column named "group" (@ggilder)
40
+ * [#101][]: Global nav now works with RackBaseURI ([@gregbell][])
41
+ * [#960][]: Global nav works when scoped in rails routes ([@gregbell][])
42
+ * [#994][]: Fix index page check collection.limit(1).exists? causes exception when
43
+ ordering by virtual colum ([@latortuga][], [@gregbell][])
44
+ * [#971][]: Fix SQL when sorting tables with a column named "group" ([@ggilder][])
23
45
 
24
46
  ### Dependencies
25
47
 
26
- * #978: Support for Inherited Resources 1.3.0 (@fabiormoura)
48
+ * [#978][]: Support for Inherited Resources 1.3.0 ([@fabiormoura][])
27
49
 
28
50
  ### Contributors
29
51
 
@@ -112,7 +134,7 @@ since we've changed both the CSS and JS files.
112
134
  * [#869][]: Upgraded Kaminari to >= 0.13.0 and added support for
113
135
  `Kaminari.config.page_method_name`. Active Admin should now be happy if
114
136
  `will_paginate` is installed with it. ([@j][]-manu)
115
- * #931: Support for Rails 3.2 added (@mperham)
137
+ * [#931][]: Support for Rails 3.2 added ([@mperham][])
116
138
 
117
139
  ### Contributors
118
140
 
@@ -421,6 +443,7 @@ of the highlights. 250 commits. Enough said.
421
443
  [#28]: https://github.com/gregbell/active_admin/issues/28
422
444
  [#31]: https://github.com/gregbell/active_admin/issues/31
423
445
  [#32]: https://github.com/gregbell/active_admin/issues/32
446
+ [#34]: https://github.com/gregbell/active_admin/issues/34
424
447
  [#38]: https://github.com/gregbell/active_admin/issues/38
425
448
  [#42]: https://github.com/gregbell/active_admin/issues/42
426
449
  [#45]: https://github.com/gregbell/active_admin/issues/45
@@ -428,12 +451,14 @@ of the highlights. 250 commits. Enough said.
428
451
  [#52]: https://github.com/gregbell/active_admin/issues/52
429
452
  [#55]: https://github.com/gregbell/active_admin/issues/55
430
453
  [#69]: https://github.com/gregbell/active_admin/issues/69
454
+ [#70]: https://github.com/gregbell/active_admin/issues/70
431
455
  [#77]: https://github.com/gregbell/active_admin/issues/77
432
456
  [#92]: https://github.com/gregbell/active_admin/issues/92
433
457
  [#95]: https://github.com/gregbell/active_admin/issues/95
434
458
  [#96]: https://github.com/gregbell/active_admin/issues/96
435
459
  [#99]: https://github.com/gregbell/active_admin/issues/99
436
460
  [#100]: https://github.com/gregbell/active_admin/issues/100
461
+ [#101]: https://github.com/gregbell/active_admin/issues/101
437
462
  [#110]: https://github.com/gregbell/active_admin/issues/110
438
463
  [#122]: https://github.com/gregbell/active_admin/issues/122
439
464
  [#131]: https://github.com/gregbell/active_admin/issues/131
@@ -449,10 +474,12 @@ of the highlights. 250 commits. Enough said.
449
474
  [#332]: https://github.com/gregbell/active_admin/issues/332
450
475
  [#369]: https://github.com/gregbell/active_admin/issues/369
451
476
  [#381]: https://github.com/gregbell/active_admin/issues/381
477
+ [#409]: https://github.com/gregbell/active_admin/issues/409
452
478
  [#428]: https://github.com/gregbell/active_admin/issues/428
453
479
  [#468]: https://github.com/gregbell/active_admin/issues/468
454
480
  [#470]: https://github.com/gregbell/active_admin/issues/470
455
481
  [#496]: https://github.com/gregbell/active_admin/issues/496
482
+ [#497]: https://github.com/gregbell/active_admin/issues/497
456
483
  [#505]: https://github.com/gregbell/active_admin/issues/505
457
484
  [#527]: https://github.com/gregbell/active_admin/issues/527
458
485
  [#551]: https://github.com/gregbell/active_admin/issues/551
@@ -472,8 +499,23 @@ of the highlights. 250 commits. Enough said.
472
499
  [#751]: https://github.com/gregbell/active_admin/issues/751
473
500
  [#758]: https://github.com/gregbell/active_admin/issues/758
474
501
  [#780]: https://github.com/gregbell/active_admin/issues/780
502
+ [#822]: https://github.com/gregbell/active_admin/issues/822
503
+ [#865]: https://github.com/gregbell/active_admin/issues/865
475
504
  [#869]: https://github.com/gregbell/active_admin/issues/869
476
505
  [#897]: https://github.com/gregbell/active_admin/issues/897
506
+ [#931]: https://github.com/gregbell/active_admin/issues/931
507
+ [#960]: https://github.com/gregbell/active_admin/issues/960
508
+ [#971]: https://github.com/gregbell/active_admin/issues/971
509
+ [#978]: https://github.com/gregbell/active_admin/issues/978
510
+ [#983]: https://github.com/gregbell/active_admin/issues/983
511
+ [#993]: https://github.com/gregbell/active_admin/issues/993
512
+ [#994]: https://github.com/gregbell/active_admin/issues/994
513
+ [#1013]: https://github.com/gregbell/active_admin/issues/1013
514
+ [#1016]: https://github.com/gregbell/active_admin/issues/1016
515
+ [#1032]: https://github.com/gregbell/active_admin/issues/1032
516
+ [#1033]: https://github.com/gregbell/active_admin/issues/1033
517
+ [#1041]: https://github.com/gregbell/active_admin/issues/1041
518
+ [@BoboFraggins]: https://github.com/BoboFraggins
477
519
  [@DMajrekar]: https://github.com/DMajrekar
478
520
  [@ZequeZ]: https://github.com/ZequeZ
479
521
  [@bobbytables]: https://github.com/bobbytables
@@ -483,15 +525,21 @@ of the highlights. 250 commits. Enough said.
483
525
  [@ebeigarts]: https://github.com/ebeigarts
484
526
  [@emzeq]: https://github.com/emzeq
485
527
  [@fabiokr]: https://github.com/fabiokr
528
+ [@fabiormoura]: https://github.com/fabiormoura
486
529
  [@fbuenemann]: https://github.com/fbuenemann
487
530
  [@george]: https://github.com/george
531
+ [@ggilder]: https://github.com/ggilder
488
532
  [@gregbell]: https://github.com/gregbell
489
533
  [@j]: https://github.com/j
534
+ [@jancel]: https://github.com/jancel
490
535
  [@jbarket]: https://github.com/jbarket
536
+ [@jschwindt]: https://github.com/jschwindt
491
537
  [@knoopx]: https://github.com/knoopx
492
538
  [@krug]: https://github.com/krug
539
+ [@latortuga]: https://github.com/latortuga
493
540
  [@macfanatic]: https://github.com/macfanatic
494
541
  [@mattvague]: https://github.com/mattvague
542
+ [@mperham]: https://github.com/mperham
495
543
  [@mwindwer]: https://github.com/mwindwer
496
544
  [@page_title]: https://github.com/page_title
497
545
  [@pcreux]: https://github.com/pcreux
@@ -503,4 +551,4 @@ of the highlights. 250 commits. Enough said.
503
551
  [@tricknotes]: https://github.com/tricknotes
504
552
  [@utkarshkukreti]: https://github.com/utkarshkukreti
505
553
  [@vairix]: https://github.com/vairix
506
- [@watson]: https://github.com/watson
554
+ [@watson]: https://github.com/watson
data/Gemfile CHANGED
@@ -29,6 +29,7 @@ end
29
29
 
30
30
  group :test do
31
31
  gem 'rspec-rails', '~> 2.8.1'
32
+ gem 'cucumber', '1.1.4'
32
33
  gem 'cucumber-rails', '1.2.1'
33
34
  gem 'capybara', '1.1.2'
34
35
  gem 'database_cleaner'
@@ -9,6 +9,7 @@ to implement beautiful and elegant interfaces with very little effort.
9
9
  == Documentation & Support
10
10
 
11
11
  * Documentation & Guides: http://activeadmin.info/documentation.html
12
+ * Wiki: https://github.com/gregbell/active_admin/wiki
12
13
  * RDoc: http://rubydoc.info/github/gregbell/active_admin/master/frames
13
14
  * Live demo: http://demo.activeadmin.info/admin
14
15
  * Website: http://www.activeadmin.info
@@ -33,22 +34,8 @@ to implement beautiful and elegant interfaces with very little effort.
33
34
  Active Admin is released as a Ruby Gem. The gem is to be installed within a Ruby
34
35
  on Rails 3 application. To install, simply add the following to your Gemfile:
35
36
 
36
- # Gemfile in Rails < 3.1
37
37
  gem 'activeadmin'
38
38
 
39
- If you are using Rails >= 3.1, you must also have sass-rails and meta_search in your Gemfile (if sass-rails is already present in assets group, move it out):
40
-
41
- # Gemfile in Rails >= 3.1
42
- gem 'activeadmin'
43
- gem 'sass-rails'
44
- gem 'meta_search', '>= 1.1.0.pre'
45
-
46
- and add activeadmin assets into precompiling by adding the following line into your config/environments/production.rb:
47
-
48
- config.assets.precompile += %w[active_admin.css active_admin.js]
49
-
50
- There is also some issue with precompiling activeadmin images in Rails 3.1.0, it is fixed in Rails 3.1.1.
51
-
52
39
  After updating your bundle, run the installer
53
40
 
54
41
  $> rails generate active_admin:install
@@ -15,6 +15,13 @@ column method:
15
15
  column :title
16
16
  end
17
17
 
18
+ For association columns we make an educated guess on what to display by
19
+ calling the following methods in the following order:
20
+
21
+ :display_name, :full_name, :name, :username, :login, :title, :email, :to_s
22
+
23
+ This can be customized in config/initializers/active_admin.rb.
24
+
18
25
  If the default title does not work for you, pass it as the first argument:
19
26
 
20
27
  index do
@@ -53,7 +60,6 @@ Alternatively, you can create a column with custom links:
53
60
  end
54
61
  end
55
62
 
56
-
57
63
  ## Sorting
58
64
 
59
65
  When a column is generated from an Active Record attribute, the table is
@@ -87,4 +93,4 @@ For example, if you were using CanCan:
87
93
  if can? :manage, Post
88
94
  column :some_secret_data
89
95
  end
90
- end
96
+ end
@@ -89,7 +89,7 @@ Feature: Commenting
89
89
  Then I should see a flash with "Comment wasn't saved, text was empty."
90
90
  And I should see "Comments (0)"
91
91
 
92
- Scenario: Viewing all commments for a namespace
92
+ Scenario: Viewing all comments for a namespace
93
93
  Given a show configuration of:
94
94
  """
95
95
  ActiveAdmin.register Post
@@ -111,3 +111,16 @@ Feature: Commenting
111
111
  When I add a comment "Hello World"
112
112
  Then I should see a flash with "Comment was successfully created"
113
113
  And I should be in the resource section for users
114
+
115
+ Scenario: Commenting on a class with string id
116
+ Given a tag with the name "coolness" exists
117
+ Given a configuration of:
118
+ """
119
+ ActiveAdmin.register Tag
120
+ """
121
+ Given I am logged in
122
+ When I am on the index page for tags
123
+ And I follow "View"
124
+ When I add a comment "Tag Comment"
125
+ Then I should see a flash with "Comment was successfully created"
126
+ And I should be in the resource section for tags
@@ -27,3 +27,6 @@ Feature: Index Scope To
27
27
  Then I should see the scope "All" selected
28
28
  And I should see the scope "All" with the count 2
29
29
  And I should see 2 posts in the table
30
+
31
+ When I follow "Published"
32
+ Then I should see 1 posts in the table
@@ -56,6 +56,19 @@ Feature: Index Scoping
56
56
  And I should see the scope "All" with no count
57
57
  And I should see 10 posts in the table
58
58
 
59
+ @scope
60
+ Scenario: Viewing resources with a scope and scope count turned off for a single scope
61
+ Given 10 posts exist
62
+ And an index configuration of:
63
+ """
64
+ ActiveAdmin.register Post do
65
+ scope :all, :default => true, :show_count => false
66
+ end
67
+ """
68
+ Then I should see the scope "All" selected
69
+ And I should see the scope "All" with no count
70
+ And I should see 10 posts in the table
71
+
59
72
  Scenario: Viewing resources when scoping
60
73
  Given 6 posts exist
61
74
  And 4 published posts exist
@@ -24,34 +24,3 @@ Feature: Menu
24
24
  Then I should see a menu item for "Articles"
25
25
  And I should not see a menu item for "Posts"
26
26
 
27
- Scenario: Set the site title and site title link
28
- Given a configuration of:
29
- """
30
- ActiveAdmin.application.site_title = "My Great Site"
31
- ActiveAdmin.application.site_title_link = "http://www.google.com/"
32
- """
33
- When I am on the dashboard
34
- And I should see the site title "My Great Site"
35
- When I follow "My Great Site"
36
- Then I should see "Ruby on Rails: Welcome aboard"
37
- # Why won't it take me to the Googles??? It takes me to / instead. Oh well
38
-
39
- Scenario: Set the site title image
40
- Given a configuration of:
41
- """
42
- ActiveAdmin.application.site_title = "My Great Site"
43
- ActiveAdmin.application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
44
- """
45
- When I am on the dashboard
46
- And I should not see the site title "My Great Site"
47
- And I should see the site title image "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
48
-
49
- Scenario: Set the site title image with link
50
- Given a configuration of:
51
- """
52
- ActiveAdmin.application.site_title_link = "http://www.google.com"
53
- ActiveAdmin.application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
54
- """
55
- When I am on the dashboard
56
- And I should see the site title image "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
57
- And I should see the site title image linked to "http://www.google.com"
@@ -73,3 +73,26 @@ Feature: New Page
73
73
  Then I should see "Post was successfully created."
74
74
  And I should see the attribute "Title" with "Hello World"
75
75
  And I should see the attribute "Body" with "This is the body"
76
+
77
+ Scenario: Displaying fields at runtime
78
+ Given a configuration of:
79
+ """
80
+ ActiveAdmin.register Post do
81
+ form do |f|
82
+ f.inputs "Your Post" do
83
+ if current_admin_user && false
84
+ f.input :title
85
+ end
86
+
87
+ f.input :body
88
+ end
89
+ f.inputs "Publishing" do
90
+ f.input :published_at
91
+ end
92
+ f.buttons
93
+ end
94
+ end
95
+ """
96
+ Given I follow "New Post"
97
+ Then I should not see "Title"
98
+ And I should see "Body"
@@ -0,0 +1,47 @@
1
+ Feature: Site title
2
+
3
+ As a developer
4
+ In order to customize the site title
5
+ I want to set it in the configuration
6
+
7
+ Background:
8
+ Given I am logged in
9
+
10
+ Scenario: Set the site title and site title link
11
+ Given a configuration of:
12
+ """
13
+ ActiveAdmin.application.site_title = "My Great Site"
14
+ ActiveAdmin.application.site_title_link = "/"
15
+ """
16
+ When I am on the dashboard
17
+ And I should see the site title "My Great Site"
18
+ When I follow "My Great Site"
19
+ Then I should see "Ruby on Rails: Welcome aboard"
20
+
21
+ Scenario: Set the site title image
22
+ Given a configuration of:
23
+ """
24
+ ActiveAdmin.application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
25
+ """
26
+ When I am on the dashboard
27
+ And I should not see the site title "My Great Site"
28
+ And I should see the site title image "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
29
+
30
+ Scenario: Set the site title image with link
31
+ Given a configuration of:
32
+ """
33
+ ActiveAdmin.application.site_title_link = "http://www.google.com"
34
+ ActiveAdmin.application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
35
+ """
36
+ When I am on the dashboard
37
+ And I should see the site title image "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
38
+ And I should see the site title image linked to "http://www.google.com"
39
+
40
+ Scenario: Set the site title to a proc
41
+ Given a configuration of:
42
+ """
43
+ ActiveAdmin.application.site_title_image = nil # Configuration is not reset between scenarios
44
+ ActiveAdmin.application.site_title = proc { "Hello #{controller.current_admin_user.email}" }
45
+ """
46
+ When I am on the dashboard
47
+ And I should see the site title "Hello admin@example.com"
@@ -6,3 +6,8 @@ When /^I add a comment "([^"]*)"$/ do |comment|
6
6
  step %{I fill in "active_admin_comment_body" with "#{comment}"}
7
7
  step %{I press "Add Comment"}
8
8
  end
9
+
10
+
11
+ Given /^a tag with the name "([^"]*)" exists$/ do |tag_name|
12
+ Tag.create(:name => tag_name)
13
+ end
@@ -18,9 +18,12 @@ Given /^I am logged in$/ do
18
18
  end
19
19
 
20
20
  Given /^an admin user "([^"]*)" exists$/ do |admin_email|
21
- unless AdminUser.find_by_email(admin_email)
22
- AdminUser.create! :email => admin_email,
23
- :password => "password",
24
- :password_confirmation => "password"
21
+ user = AdminUser.find_or_create_by_email :email => admin_email,
22
+ :password => "password",
23
+ :password_confirmation => "password"
24
+
25
+ unless user.persisted?
26
+ puts "Coult not create an admin user #{admin_email}: #{user.errors.full_messages}"
27
+ raise "Could not create an admin user"
25
28
  end
26
29
  end
@@ -103,10 +103,21 @@ module Arbre
103
103
  def append_return_block(tag)
104
104
  return nil if current_dom_context.children?
105
105
 
106
- if !tag.is_a?(Arbre::HTML::Element) && tag.respond_to?(:to_s)
106
+ if appendable_return_block?(tag)
107
107
  current_dom_context << Arbre::HTML::TextNode.from_string(tag.to_s)
108
108
  end
109
109
  end
110
+
111
+ def appendable_return_block?(tag)
112
+ appendable = !tag.is_a?(Arbre::HTML::Element) && tag.respond_to?(:to_s)
113
+
114
+ # Ruby 1.9 returns empty array as "[]"
115
+ if tag.respond_to?(:empty?) && tag.empty?
116
+ appendable = false
117
+ end
118
+
119
+ appendable
120
+ end
110
121
  end
111
122
 
112
123
  end
@@ -20,7 +20,7 @@ ActiveAdmin.application.view_factory.show_page.send :include, ActiveAdmin::Comme
20
20
  ActiveAdmin::Event.subscribe ActiveAdmin::Application::LoadEvent do |app|
21
21
  app.namespaces.values.each do |namespace|
22
22
  if namespace.comments?
23
- namespace.register ActiveAdmin::Comment, :as => 'Comment' do
23
+ namespace.register ActiveAdmin::Comment, :as => "Comment" do
24
24
  actions :index, :show, :create
25
25
 
26
26
  # Don't display in the menu
@@ -60,7 +60,7 @@ ActiveAdmin::Event.subscribe ActiveAdmin::Application::LoadEvent do |app|
60
60
  create! do |success, failure|
61
61
  failure.html do
62
62
  resource_config = active_admin_config.namespace.resource_for(@comment.resource.class)
63
- flash[:error] = "Comment wasn't saved, text was empty."
63
+ flash[:error] = I18n.t('active_admin.comments.errors.empty_text')
64
64
  redirect_to send(resource_config.route_instance_path, @comment.resource)
65
65
  end
66
66
  end
@@ -69,9 +69,9 @@ ActiveAdmin::Event.subscribe ActiveAdmin::Application::LoadEvent do |app|
69
69
 
70
70
  # Display as a table
71
71
  index do
72
- column("Resource"){|comment| auto_link(comment.resource) }
73
- column("Author"){|comment| auto_link(comment.author) }
74
- column :body
72
+ column(I18n.t('active_admin.comments.resource')){|comment| auto_link(comment.resource) }
73
+ column(I18n.t('active_admin.comments.author')){|comment| auto_link(comment.author) }
74
+ column(I18n.t('active_admin.comments.body')){|comment| comment.body }
75
75
  end
76
76
  end
77
77
  end
@@ -17,7 +17,7 @@ module ActiveAdmin
17
17
  protected
18
18
 
19
19
  def title_content
20
- "Comments (#{record_comments.count})"
20
+ I18n.t('active_admin.comments.title_content', :count => record_comments.count)
21
21
  end
22
22
 
23
23
  def record_comments
@@ -51,7 +51,7 @@ module ActiveAdmin
51
51
 
52
52
  def build_empty_message
53
53
  span :class => "empty" do
54
- "No comments yet."
54
+ I18n.t('active_admin.comments.no_comments_yet')
55
55
  end
56
56
  end
57
57
 
@@ -71,7 +71,7 @@ module ActiveAdmin
71
71
  form.input :body, :input_html => {:size => "80x8"}, :label => false
72
72
  end
73
73
  form.buttons do
74
- form.commit_button 'Add Comment'
74
+ form.commit_button I18n.t('active_admin.comments.add')
75
75
  end
76
76
  end
77
77
  end
@@ -9,6 +9,10 @@ module ActiveAdmin
9
9
  warn "ActiveAdmin requires meta_search >= 1.1.0.pre and sass-rails ~> 3.1.0.rc to work with rails >= 3.1.0"
10
10
  end
11
11
  end
12
+
13
+ if pry_rails_before_0_1_6?
14
+ warn "ActiveAdmin is not compatible with pry-rails < 0.1.6. Please upgrade pry-rails."
15
+ end
12
16
  end
13
17
 
14
18
  def rails_3_1?
@@ -25,6 +29,14 @@ module ActiveAdmin
25
29
  rescue LoadError
26
30
  false
27
31
  end
32
+
33
+ def pry_rails_before_0_1_6?
34
+ begin
35
+ PryRails::VERSION < "0.1.6"
36
+ rescue NameError
37
+ false
38
+ end
39
+ end
28
40
  end
29
41
  end
30
42
  end
@@ -1,4 +1,9 @@
1
1
  module ActiveAdmin
2
2
  class Engine < Rails::Engine
3
+ if Rails.version > "3.1"
4
+ initializer "ActiveAdmin precompile hook" do |app|
5
+ app.config.assets.precompile += ['active_admin.js', 'active_admin.css']
6
+ end
7
+ end
3
8
  end
4
9
  end
@@ -21,7 +21,7 @@ module ActiveAdmin
21
21
  # Override the standard finder to accept a proc
22
22
  def collection_from_options
23
23
  if options[:collection].is_a?(Proc)
24
- options[:collection].call
24
+ template.instance_eval(&options[:collection])
25
25
  else
26
26
  super
27
27
  end
@@ -42,3 +42,13 @@ de:
42
42
  blank_slate:
43
43
  content: "Es gibt noch keine %{resource_name}."
44
44
  link: "Erstellen"
45
+ comments:
46
+ body: "Inhalt"
47
+ author: "Autor"
48
+ title: "Kommentar"
49
+ resource: "Resource"
50
+ add: "Kommentar hinzufügen"
51
+ no_comments_yet: "Es gibt noch keine Kommentare."
52
+ title_content: "Kommentare (%{count})"
53
+ errors:
54
+ empty_text: "Der Kommentar wurde nicht gespeichert, da der Text fehlt."
@@ -42,4 +42,14 @@ en:
42
42
  any: "Any"
43
43
  blank_slate:
44
44
  content: "There are no %{resource_name} yet."
45
- link: "Create one"
45
+ link: "Create one"
46
+ comments:
47
+ body: "Body"
48
+ author: "Author"
49
+ title: "Comment"
50
+ add: "Add Comment"
51
+ resource: "Resource"
52
+ no_comments_yet: "No comments yet."
53
+ title_content: "Comments (%{count})"
54
+ errors:
55
+ empty_text: "Comment wasn't saved, text was empty."
@@ -9,7 +9,9 @@ fr:
9
9
  delete: "Supprimer"
10
10
  delete_confirmation: "Êtes-vous certain de vouloir supprimer ceci ?"
11
11
  new_model: "Nouveau %{model}"
12
+ create_model: "Nouveau %{model}"
12
13
  edit_model: "Modifier %{model}"
14
+ update_model: "Modifier %{model}"
13
15
  delete_model: "Supprimer %{model}"
14
16
  details: "Détails de %{model}"
15
17
  cancel: "Annuler"
@@ -34,7 +36,20 @@ fr:
34
36
  one: "Affichage de <b>1</b> %{model}"
35
37
  one_page: "Affichage de <b>tous les %{n}</b> %{model}"
36
38
  multiple: "Affichage de %{model} <b>%{from}&nbsp;-&nbsp;%{to}</b> sur un total de <b>%{total}</b>"
39
+ entry:
40
+ one: "entrée"
41
+ other: "entrées"
37
42
  any: "N'importe lequel"
38
43
  blank_slate:
39
44
  content: "Il n'y a pas encore de %{resource_name}."
40
45
  link: "Créez en un"
46
+ comments:
47
+ body: "Corps"
48
+ author: "Auteur"
49
+ title: "Commentaire"
50
+ add: "Ajouter un commentaire"
51
+ resource: "Ressource"
52
+ no_comments_yet: "Aucun commentaire actuellement"
53
+ title_content: "Commentaires (%{count})"
54
+ errors:
55
+ empty_text: "Le commentaire n'a pas été enregistré puisque le texte était vide."
@@ -0,0 +1,45 @@
1
+ "zh-TW":
2
+ active_admin:
3
+ dashboard: 儀表板
4
+ dashboard_welcome:
5
+ welcome: "歡迎來到 Active Admin 這是預設的儀表板頁面。"
6
+ call_to_action: "To add dashboard sections, checkout 'app/admin/dashboards.rb'"
7
+ view: "檢視"
8
+ edit: "編輯"
9
+ delete: "刪除"
10
+ delete_confirmation: "你確定要刪除嗎?"
11
+ new_model: "新增 %{model}"
12
+ create_model: "新增 %{model}"
13
+ edit_model: "編輯 %{model}"
14
+ update_model: "編輯 %{model}"
15
+ delete_model: "刪除 %{model}"
16
+ details: "%{model} 明細"
17
+ cancel: "取消"
18
+ empty: "空的"
19
+ previous: "前一個"
20
+ next: "下一個"
21
+ download: "下載:"
22
+ has_many_new: "增加新的 %{model}"
23
+ has_many_delete: "刪除"
24
+ filter: "篩選"
25
+ clear_filters: "清除篩選條件"
26
+ search_field: "搜尋 %{field}"
27
+ equal_to: "等於"
28
+ greater_than: "大於"
29
+ less_than: "小於"
30
+ main_content: "請編寫 %{model}#main_content 以顯示內容。"
31
+ logout: "登出"
32
+ sidebars:
33
+ filters: "篩選條件"
34
+ pagination:
35
+ empty: "找不到 %{model} "
36
+ one: "顯示 <b>1</b> %{model}"
37
+ one_page: "顯示 <b>全部 %{n}</b> %{model}"
38
+ multiple: "總計 <b>%{total}</b> 顯示 %{model} 中<b>%{from}&nbsp;-&nbsp;%{to}</b> 筆"
39
+ entry:
40
+ one: "筆"
41
+ other: "筆"
42
+ any: "任何"
43
+ blank_slate:
44
+ content: "尚無 %{resource_name}"
45
+ link: "建立一筆"
@@ -1,7 +1,7 @@
1
1
  module ActiveAdmin
2
2
  class Scope
3
3
 
4
- attr_reader :name, :scope_method, :id, :scope_block, :display_if_block
4
+ attr_reader :name, :scope_method, :id, :scope_block, :display_if_block, :show_count
5
5
 
6
6
  # Create a Scope
7
7
  #
@@ -30,6 +30,7 @@ module ActiveAdmin
30
30
  @scope_block = block
31
31
  end
32
32
 
33
+ @show_count = options[:show_count].nil? ? true : options[:show_count]
33
34
  @display_if_block = options[:if]
34
35
  end
35
36
 
@@ -1,3 +1,3 @@
1
1
  module ActiveAdmin
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -23,4 +23,16 @@ module MethodOrProcHelper
23
23
  end
24
24
  end
25
25
 
26
+ # Many configuration options (Ex: site_title, title_image) could either be
27
+ # static (String), methods (Symbol) or procs (Proc). This helper takes care of
28
+ # returning the content when String or call call_method_or_proc_on when Symbol or Proc.
29
+ #
30
+ def render_or_call_method_or_proc_on(obj, string_symbol_or_proc, options = {})
31
+ case string_symbol_or_proc
32
+ when Symbol, Proc
33
+ call_method_or_proc_on(obj, string_symbol_or_proc, options)
34
+ when String
35
+ string_symbol_or_proc
36
+ end
37
+ end
26
38
  end
@@ -38,7 +38,7 @@ module ActiveAdmin
38
38
  text_node scope_name
39
39
  span :class => 'count' do
40
40
  "(" + get_scope_count(scope).to_s + ")"
41
- end if options[:scope_count]
41
+ end if options[:scope_count] && scope.show_count
42
42
  end
43
43
  end
44
44
  end
@@ -13,29 +13,35 @@ module ActiveAdmin
13
13
 
14
14
  # Renders the title/branding area for the site
15
15
  def title
16
- if active_admin_namespace.site_title_image.blank?
17
- title_text
16
+ content_tag('h1', link_to_site_title(title_image_tag || title_text), :id => 'site_title')
17
+ end
18
+
19
+ def link_to_site_title(title_tag)
20
+ if active_admin_namespace.site_title_link.present?
21
+ link_to(title_tag, active_admin_namespace.site_title_link)
18
22
  else
19
- title_image
23
+ title_tag
20
24
  end
21
25
  end
22
26
 
23
- # Renders an image for the site's header/branding area
24
- def title_image
25
- if !active_admin_namespace.site_title_link.blank?
26
- content_tag 'h1', link_to( image_tag(active_admin_namespace.site_title_image, :id => "site_title_image", :alt => active_admin_namespace.site_title), active_admin_namespace.site_title_link ), :id => "site_title"
27
- else
28
- content_tag 'h1', image_tag( active_admin_namespace.site_title_image, :id => "site_title_image", :alt => active_admin_namespace.site_title ), :id => "site_title"
27
+ # @return [String] An HTML img tag with site_title_image. Return nil when
28
+ # site_title_image is blank.
29
+ def title_image_tag
30
+ if active_admin_namespace.site_title_image.present?
31
+ image_tag(title_image,
32
+ :id => "site_title_image",
33
+ :alt => active_admin_namespace.site_title)
29
34
  end
30
35
  end
31
-
32
- # Renders a the site's header/branding area as a string
36
+
37
+ # @return [String] The title image url
38
+ def title_image
39
+ render_or_call_method_or_proc_on(self, active_admin_namespace.site_title_image)
40
+ end
41
+
42
+ # @return [String] The site title
33
43
  def title_text
34
- if !active_admin_namespace.site_title_link || active_admin_namespace.site_title_link == ""
35
- content_tag 'h1', active_admin_namespace.site_title, :id => 'site_title'
36
- else
37
- content_tag 'h1', link_to(active_admin_namespace.site_title, active_admin_namespace.site_title_link), :id => 'site_title'
38
- end
44
+ render_or_call_method_or_proc_on(self, active_admin_namespace.site_title)
39
45
  end
40
46
 
41
47
  # Renders the global navigation returned by
@@ -17,6 +17,7 @@ module ActiveAdmin
17
17
  @body.add_class(params[:action])
18
18
  @body.add_class(params[:controller].gsub('/', '_'))
19
19
  @body.add_class("logged_in")
20
+ @body.add_class(active_admin_namespace.name.to_s + "_namespace")
20
21
  end
21
22
 
22
23
  def build_active_admin_head
@@ -19,7 +19,9 @@ module ActiveAdmin
19
19
  if form_options[:partial]
20
20
  render(form_options[:partial])
21
21
  else
22
- active_admin_form_for(resource, form_options, &form_presenter.block)
22
+ active_admin_form_for(resource, form_options) do |f|
23
+ instance_exec f, &form_presenter.block
24
+ end
23
25
  end
24
26
  end
25
27
 
@@ -2,7 +2,6 @@ module ActiveAdmin
2
2
  module Generators
3
3
  class DeviseGenerator < Rails::Generators::NamedBase
4
4
  desc "Creates an admin user and uses Devise for authentication"
5
-
6
5
  argument :name, :type => :string, :default => "AdminUser"
7
6
 
8
7
  class_option :registerable, :type => :boolean, :default => false,
@@ -1,7 +1,8 @@
1
1
  module ActiveAdmin
2
2
  module Generators
3
- class InstallGenerator < Rails::Generators::Base
3
+ class InstallGenerator < Rails::Generators::NamedBase
4
4
  desc "Installs Active Admin and generats the necessary migrations"
5
+ argument :name, :type => :string, :default => "AdminUser"
5
6
 
6
7
  hook_for :users, :default => "devise", :desc => "Admin user generator to run. Skip with --skip-users"
7
8
 
@@ -16,6 +17,7 @@ module ActiveAdmin
16
17
  end
17
18
 
18
19
  def copy_initializer
20
+ @underscored_user_name = name.underscore
19
21
  template 'active_admin.rb.erb', 'config/initializers/active_admin.rb'
20
22
  end
21
23
 
@@ -55,7 +55,7 @@ ActiveAdmin.setup do |config|
55
55
  #
56
56
  # This setting changes the method which Active Admin calls
57
57
  # within the controller.
58
- config.authentication_method = :authenticate_admin_user!
58
+ config.authentication_method = :authenticate_<%= @underscored_user_name %>!
59
59
 
60
60
 
61
61
  # == Current User
@@ -65,7 +65,7 @@ ActiveAdmin.setup do |config|
65
65
  #
66
66
  # This setting changes the method which Active Admin calls
67
67
  # to return the currently logged in user.
68
- config.current_user_method = :current_admin_user
68
+ config.current_user_method = :current_<%= @underscored_user_name %>
69
69
 
70
70
 
71
71
  # == Logging Out
@@ -78,7 +78,7 @@ ActiveAdmin.setup do |config|
78
78
  # will call the method to return the path.
79
79
  #
80
80
  # Default:
81
- # config.logout_link_path = :destroy_admin_user_session_path
81
+ config.logout_link_path = :destroy_<%= @underscored_user_name %>_session_path
82
82
 
83
83
  # This setting changes the http method used when rendering the
84
84
  # link. For example :get, :delete, :put, etc..
@@ -1,7 +1,8 @@
1
1
  class CreateAdminNotes < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :admin_notes do |t|
4
- t.references :resource, :polymorphic => true, :null => false
4
+ t.string :resource_id, :null => false
5
+ t.string :resource_type, :null => false
5
6
  t.references :admin_user, :polymorphic => true
6
7
  t.text :body
7
8
  t.timestamps
@@ -17,6 +17,24 @@ generate :model, "publisher --migration=false --parent=User"
17
17
  generate :model, 'category name:string description:text'
18
18
  inject_into_file 'app/models/category.rb', " has_many :posts\n", :after => "class Category < ActiveRecord::Base\n"
19
19
 
20
+ # Generate a model with string ids
21
+ generate :model, "tag name:string"
22
+ gsub_file(Dir['db/migrate/*_create_tags.rb'][0], /\:tags\sdo\s.*/, ":tags, :id => false, :primary_key => :id do |t|\n\t\t\tt.string :id\n" )
23
+ id_model_setup = <<-EOF
24
+ self.primary_key = :id
25
+ before_create :set_id
26
+
27
+ private
28
+ def set_id
29
+ self.id = 8.times.inject("") { |s,e| s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
30
+ end
31
+ EOF
32
+ inject_into_file 'app/models/tag.rb', id_model_setup, :after => "class Tag < ActiveRecord::Base\n"
33
+
34
+ if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 1 #Rails 3.1 Gotcha
35
+ gsub_file 'app/models/tag.rb', /self\.primary_key.*$/, "define_attr_method :primary_key, :id"
36
+ end
37
+
20
38
  # Add our local Active Admin to the load path
21
39
  inject_into_file "config/environment.rb", "\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n", :after => "require File.expand_path('../application', __FILE__)"
22
40
 
@@ -215,5 +215,14 @@ HTML
215
215
  HTML
216
216
  end
217
217
  end
218
+
219
+ it "should not render blank nodes" do
220
+ tbody = tbody do
221
+ []
222
+ end
223
+ tbody.to_s.should == <<-HTML
224
+ <tbody></tbody>
225
+ HTML
226
+ end
218
227
 
219
228
  end
@@ -36,6 +36,19 @@ describe "Comments" do
36
36
  ActiveAdmin::Comment.find_for_resource_in_namespace(another_post, namespace_name).should == []
37
37
  end
38
38
  end
39
+
40
+ describe "Commenting on resource with string id" do
41
+ let(:tag){ Tag.create!(:name => "cooltags") }
42
+ let(:namespace_name){ "admin" }
43
+
44
+ it "should allow commenting" do
45
+ comment = ActiveAdmin::Comment.create! :resource => tag,
46
+ :body => "Another Comment",
47
+ :namespace => namespace_name
48
+
49
+ ActiveAdmin::Comment.find_for_resource_in_namespace(tag, namespace_name).should == [comment]
50
+ end
51
+ end
39
52
  end
40
53
 
41
54
  describe ActiveAdmin::Comments::NamespaceHelper do
@@ -17,6 +17,10 @@ describe ActiveAdmin::ViewHelpers::FilterFormHelper do
17
17
  false
18
18
  end
19
19
 
20
+ def view.a_helper_method
21
+ "A Helper Method"
22
+ end
23
+
20
24
  view
21
25
  end
22
26
 
@@ -160,6 +164,11 @@ describe ActiveAdmin::ViewHelpers::FilterFormHelper do
160
164
  body.should have_tag("option", "Title One")
161
165
  body.should have_tag("option", "Title Two")
162
166
  end
167
+
168
+ it "should render the collection in the context of the view" do
169
+ body = filter(:title, :as => :select, :collection => proc{[a_helper_method]})
170
+ body.should have_tag("option", "A Helper Method")
171
+ end
163
172
  end
164
173
  end
165
174
 
@@ -24,6 +24,10 @@ describe ActiveAdmin::FormBuilder do
24
24
  end
25
25
  end
26
26
 
27
+ def view.a_helper_method
28
+ "A Helper Method"
29
+ end
30
+
27
31
  view
28
32
  end
29
33
 
@@ -179,6 +183,7 @@ describe ActiveAdmin::FormBuilder do
179
183
  body.scan(/type=\"radio\"/).size.should == 2
180
184
  end
181
185
  end
186
+
182
187
  end
183
188
 
184
189
  context "with inputs 'for'" do
@@ -105,4 +105,22 @@ describe ActiveAdmin::Renderer do
105
105
  renderer.send(:call_method_or_proc_on, obj, p).should == obj.size
106
106
  end
107
107
  end
108
+
109
+ describe "#render_or_call_method_or_proc_on" do
110
+ let(:renderer){ Renderer.new(action_view) }
111
+ let(:obj){ "Hello World" }
112
+ it "should return nil if no symbol or proc given" do
113
+ renderer.send(:render_or_call_method_or_proc_on, obj, 1).should == nil
114
+ end
115
+ it "should return the string if a string is given" do
116
+ renderer.send(:render_or_call_method_or_proc_on, obj, "Hello!").should == "Hello!"
117
+ end
118
+ it "should call the method if a symbol is given" do
119
+ renderer.send(:render_or_call_method_or_proc_on, obj, :size).should == obj.size
120
+ end
121
+ it "should call the proc with the object if a proc is given" do
122
+ p = Proc.new{|string| string.size }
123
+ renderer.send(:render_or_call_method_or_proc_on, obj, p).should == obj.size
124
+ end
125
+ end
108
126
  end
@@ -52,4 +52,18 @@ describe ActiveAdmin::Scope do
52
52
 
53
53
  end
54
54
 
55
+ describe "show_count" do
56
+
57
+ it "should allow setting of show_count to prevent showing counts" do
58
+ scope = ActiveAdmin::Scope.new(:default, nil, :show_count => false)
59
+ scope.show_count.should == false
60
+ end
61
+
62
+ it "should set show_count to true if not passed in" do
63
+ scope = ActiveAdmin::Scope.new(:default)
64
+ scope.show_count.should == true
65
+ end
66
+
67
+ end
68
+
55
69
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Greg Bell
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-16 00:00:00 Z
18
+ date: 2012-02-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -303,6 +303,7 @@ files:
303
303
  - features/show/default_content.feature
304
304
  - features/show/page_title.feature
305
305
  - features/sidebar_sections.feature
306
+ - features/site_title.feature
306
307
  - features/specifying_actions.feature
307
308
  - features/step_definitions/action_item_steps.rb
308
309
  - features/step_definitions/action_link_steps.rb
@@ -407,6 +408,7 @@ files:
407
408
  - lib/active_admin/locales/pt-BR.yml
408
409
  - lib/active_admin/locales/ru.yml
409
410
  - lib/active_admin/locales/sv-SE.yml
411
+ - lib/active_admin/locales/zh-TW.yml
410
412
  - lib/active_admin/locales/zh_cn.yml
411
413
  - lib/active_admin/menu.rb
412
414
  - lib/active_admin/menu_item.rb
@@ -649,6 +651,7 @@ test_files:
649
651
  - features/show/default_content.feature
650
652
  - features/show/page_title.feature
651
653
  - features/sidebar_sections.feature
654
+ - features/site_title.feature
652
655
  - features/specifying_actions.feature
653
656
  - features/step_definitions/action_item_steps.rb
654
657
  - features/step_definitions/action_link_steps.rb