andrewroth_activeadmin 0.3.4 → 0.3.4.1

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.
Files changed (201) hide show
  1. data/CHANGELOG.md +159 -3
  2. data/CONTRIBUTING.md +113 -0
  3. data/LICENSE +1 -1
  4. data/README.rdoc +19 -20
  5. data/activeadmin.gemspec +3 -1
  6. data/app/assets/javascripts/active_admin/application.js +9 -0
  7. data/app/assets/javascripts/active_admin/base.js +4 -12
  8. data/app/assets/stylesheets/active_admin/_base.css.scss +16 -340
  9. data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
  10. data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
  11. data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
  12. data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
  13. data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
  14. data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
  15. data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
  16. data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
  17. data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
  18. data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
  19. data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
  20. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
  21. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
  22. data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
  23. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
  24. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
  25. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
  26. data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
  27. data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
  28. data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
  29. data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
  30. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
  31. data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
  32. data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
  33. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
  34. data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
  35. data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
  36. data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
  37. data/app/views/active_admin/devise/shared/_links.erb +1 -1
  38. data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
  39. data/app/views/active_admin/page/index.html.arb +1 -0
  40. data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
  41. data/cucumber.yml +3 -2
  42. data/docs/1-general-configuration.md +46 -10
  43. data/docs/6-show-screens.md +7 -0
  44. data/docs/8-custom-actions.md +12 -2
  45. data/docs/9-custom-pages.md +84 -0
  46. data/features/belongs_to.feature +27 -0
  47. data/features/comments/commenting.feature +3 -2
  48. data/features/dashboard.feature +18 -0
  49. data/features/development_reloading.feature +19 -0
  50. data/features/index/filter_with_check_boxes.feature +25 -0
  51. data/features/index/index_as_table.feature +14 -0
  52. data/features/index/index_scopes.feature +42 -0
  53. data/features/index/pagination.feature +19 -1
  54. data/features/menu.feature +22 -2
  55. data/features/registering_assets.feature +2 -2
  56. data/features/registering_pages.feature +66 -0
  57. data/features/specifying_actions.feature +5 -0
  58. data/features/step_definitions/action_item_steps.rb +2 -6
  59. data/features/step_definitions/action_link_steps.rb +7 -0
  60. data/features/step_definitions/additional_web_steps.rb +8 -0
  61. data/features/step_definitions/asset_steps.rb +5 -1
  62. data/features/step_definitions/breadcrumb_steps.rb +5 -0
  63. data/features/step_definitions/configuration_steps.rb +56 -8
  64. data/features/step_definitions/dashboard_steps.rb +5 -1
  65. data/features/step_definitions/factory_steps.rb +9 -2
  66. data/features/step_definitions/flash_steps.rb +9 -1
  67. data/features/step_definitions/index_scope_steps.rb +16 -4
  68. data/features/step_definitions/member_link_steps.rb +7 -0
  69. data/features/step_definitions/site_title_steps.rb +15 -0
  70. data/features/support/paths.rb +6 -0
  71. data/features/users/logging_out.feature +11 -0
  72. data/lib/active_admin.rb +25 -10
  73. data/lib/active_admin/application.rb +63 -20
  74. data/lib/active_admin/arbre/html/element.rb +10 -0
  75. data/lib/active_admin/asset_registration.rb +15 -2
  76. data/lib/active_admin/base_controller.rb +61 -0
  77. data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
  78. data/lib/active_admin/comments.rb +48 -54
  79. data/lib/active_admin/comments/comment.rb +13 -2
  80. data/lib/active_admin/comments/namespace_helper.rb +1 -1
  81. data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
  82. data/lib/active_admin/dashboards.rb +4 -0
  83. data/lib/active_admin/dashboards/dashboard_controller.rb +20 -4
  84. data/lib/active_admin/dsl.rb +6 -159
  85. data/lib/active_admin/event.rb +5 -3
  86. data/lib/active_admin/filter_form_builder.rb +53 -0
  87. data/lib/active_admin/form_builder.rb +25 -19
  88. data/lib/active_admin/inputs.rb +14 -0
  89. data/lib/active_admin/inputs/datepicker_input.rb +11 -0
  90. data/lib/active_admin/inputs/filter_base.rb +46 -0
  91. data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
  92. data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
  93. data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
  94. data/lib/active_admin/inputs/filter_select_input.rb +23 -0
  95. data/lib/active_admin/inputs/filter_string_input.rb +22 -0
  96. data/lib/active_admin/locales/ca.yml +44 -0
  97. data/lib/active_admin/locales/cs.yml +14 -10
  98. data/lib/active_admin/locales/de.yml +43 -0
  99. data/lib/active_admin/locales/en.yml +5 -0
  100. data/lib/active_admin/locales/hr.yml +40 -0
  101. data/lib/active_admin/locales/ko.yml +40 -0
  102. data/lib/active_admin/locales/lv.yml +43 -0
  103. data/lib/active_admin/locales/nl.yml +40 -0
  104. data/lib/active_admin/locales/no-NB.yml +40 -0
  105. data/lib/active_admin/locales/pl.yml +7 -1
  106. data/lib/active_admin/locales/pt-BR.yml +6 -2
  107. data/lib/active_admin/namespace.rb +48 -33
  108. data/lib/active_admin/page.rb +54 -0
  109. data/lib/active_admin/page_controller.rb +15 -0
  110. data/lib/active_admin/page_dsl.rb +21 -0
  111. data/lib/active_admin/page_presenter.rb +30 -0
  112. data/lib/active_admin/resource.rb +38 -44
  113. data/lib/active_admin/resource/action_items.rb +5 -0
  114. data/lib/active_admin/resource/belongs_to.rb +4 -2
  115. data/lib/active_admin/resource/controllers.rb +35 -0
  116. data/lib/active_admin/resource/menu.rb +1 -2
  117. data/lib/active_admin/resource/naming.rb +43 -31
  118. data/lib/active_admin/resource/page_presenters.rb +28 -0
  119. data/lib/active_admin/resource/scopes.rb +16 -3
  120. data/lib/active_admin/resource/sidebars.rb +4 -0
  121. data/lib/active_admin/resource_collection.rb +88 -0
  122. data/lib/active_admin/resource_controller.rb +18 -54
  123. data/lib/active_admin/resource_controller/action_builder.rb +1 -1
  124. data/lib/active_admin/resource_controller/actions.rb +1 -1
  125. data/lib/active_admin/resource_controller/callbacks.rb +1 -1
  126. data/lib/active_admin/resource_controller/collection.rb +8 -4
  127. data/lib/active_admin/resource_controller/filters.rb +1 -1
  128. data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
  129. data/lib/active_admin/resource_controller/scoping.rb +1 -1
  130. data/lib/active_admin/resource_controller/sidebars.rb +1 -1
  131. data/lib/active_admin/resource_dsl.rb +157 -0
  132. data/lib/active_admin/router.rb +21 -14
  133. data/lib/active_admin/scope.rb +15 -3
  134. data/lib/active_admin/version.rb +1 -1
  135. data/lib/active_admin/view_factory.rb +4 -3
  136. data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
  137. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
  138. data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
  139. data/lib/active_admin/views/components/attributes_table.rb +1 -1
  140. data/lib/active_admin/views/components/paginated_collection.rb +42 -13
  141. data/lib/active_admin/views/components/scopes.rb +17 -17
  142. data/lib/active_admin/views/components/status_tag.rb +6 -5
  143. data/lib/active_admin/views/components/table_for.rb +6 -2
  144. data/lib/active_admin/views/header_renderer.rb +31 -12
  145. data/lib/active_admin/views/index_as_block.rb +2 -2
  146. data/lib/active_admin/views/index_as_blog.rb +3 -3
  147. data/lib/active_admin/views/index_as_grid.rb +4 -4
  148. data/lib/active_admin/views/index_as_table.rb +13 -6
  149. data/lib/active_admin/views/pages/base.rb +4 -4
  150. data/lib/active_admin/views/pages/form.rb +49 -0
  151. data/lib/active_admin/views/pages/index.rb +18 -6
  152. data/lib/active_admin/views/pages/page.rb +24 -0
  153. data/lib/active_admin/views/pages/show.rb +1 -1
  154. data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
  155. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
  156. data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
  157. data/spec/spec_helper.rb +4 -0
  158. data/spec/support/rails_template.rb +11 -0
  159. data/spec/support/templates/cucumber_with_reloading.rb +5 -0
  160. data/spec/unit/active_admin_spec.rb +8 -0
  161. data/spec/unit/application_spec.rb +48 -2
  162. data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
  163. data/spec/unit/asset_registration_spec.rb +9 -3
  164. data/spec/unit/auto_link_spec.rb +2 -2
  165. data/spec/unit/base_controller_shared_examples.rb +28 -0
  166. data/spec/unit/base_controller_spec.rb +8 -0
  167. data/spec/unit/belongs_to_spec.rb +30 -33
  168. data/spec/unit/comments_spec.rb +45 -15
  169. data/spec/unit/config_shared_examples.rb +108 -0
  170. data/spec/unit/dashboard_controller_spec.rb +44 -0
  171. data/spec/unit/event_spec.rb +6 -0
  172. data/spec/unit/filter_form_builder_spec.rb +9 -0
  173. data/spec/unit/form_builder_spec.rb +8 -14
  174. data/spec/unit/namespace/register_page_spec.rb +102 -0
  175. data/spec/unit/namespace/register_resource_spec.rb +188 -0
  176. data/spec/unit/namespace_spec.rb +11 -183
  177. data/spec/unit/page_controller_spec.rb +8 -0
  178. data/spec/unit/page_spec.rb +60 -0
  179. data/spec/unit/resource/menu_spec.rb +1 -51
  180. data/spec/unit/resource/naming_spec.rb +24 -19
  181. data/spec/unit/resource/page_presenters_spec.rb +32 -0
  182. data/spec/unit/resource/scopes_spec.rb +13 -0
  183. data/spec/unit/resource_collection_spec.rb +101 -0
  184. data/spec/unit/resource_controller_spec.rb +40 -32
  185. data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
  186. data/spec/unit/resource_spec.rb +8 -24
  187. data/spec/unit/routing_spec.rb +50 -1
  188. data/spec/unit/scope_spec.rb +18 -4
  189. data/spec/unit/views/components/paginated_collection_spec.rb +150 -0
  190. data/spec/unit/views/components/status_tag_spec.rb +9 -0
  191. data/tasks/test.rake +43 -27
  192. metadata +140 -31
  193. data/app/assets/javascripts/active_admin/vendor.js +0 -382
  194. data/lib/active_admin/comments/configuration.rb +0 -18
  195. data/lib/active_admin/page_config.rb +0 -15
  196. data/lib/active_admin/resource_controller/form.rb +0 -42
  197. data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
  198. data/lib/active_admin/views/pages/edit.rb +0 -28
  199. data/lib/active_admin/views/pages/new.rb +0 -28
  200. data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
  201. data/spec/integration/belongs_to_spec.rb +0 -42
@@ -7,5 +7,9 @@ Then /^I should not see the default welcome message$/ do
7
7
  end
8
8
 
9
9
  Then /^I should see a dashboard widget "([^"]*)"$/ do |name|
10
- Then %{I should see "#{name}" within ".dashboard .panel h3"}
10
+ page.should have_css('.dashboard .panel h3', :text => name)
11
+ end
12
+
13
+ Then /^I should not see a dashboard widget "([^"]*)"$/ do |name|
14
+ page.should_not have_css('.dashboard .panel h3', :text => name)
11
15
  end
@@ -12,9 +12,9 @@ Given /^a post with the title "([^"]*)" written by "([^"]*)" exists$/ do |title,
12
12
  Post.create! :title => title, :author => author
13
13
  end
14
14
 
15
- Given /^(\d+) posts? exists?/ do |count|
15
+ Given /^(\d+)( published)? posts? exists?$/ do |count, published|
16
16
  (0...count.to_i).each do |i|
17
- Post.create! :title => "Hello World #{i}"
17
+ Post.create! :title => "Hello World #{i}", :published_at => (published ? Time.now : nil)
18
18
  end
19
19
  end
20
20
 
@@ -27,3 +27,10 @@ Given /^a (user|publisher) named "([^"]*)" exists$/ do |type, name|
27
27
  type = type.camelize.constantize
28
28
  type.create! :first_name => first, :last_name => last, :username => name
29
29
  end
30
+
31
+ Given /^I create a new post with the title "([^"]*)"$/ do |title|
32
+ click_link "Posts"
33
+ click_link "New Post"
34
+ fill_in :title, :with => title
35
+ click_button "Create Post"
36
+ end
@@ -1,3 +1,11 @@
1
1
  Then /^I should see a flash with "([^"]*)"$/ do |text|
2
- Then %{I should see "#{text}"}
2
+ page.should have_content(text)
3
+ end
4
+
5
+ Then /^I should see a successful create flash$/ do
6
+ page.should have_css('div.flash_notice', :text => /was successfully created/)
7
+ end
8
+
9
+ Then /^I should not see a successful create flash$/ do
10
+ page.should_not have_css('div.flash_notice', :text => /was successfully created/)
3
11
  end
@@ -2,19 +2,31 @@ Then /^I should see the scope "([^"]*)"$/ do |name|
2
2
  Then %{I should see "#{name}" within ".scopes"}
3
3
  end
4
4
 
5
+ Then /^I should not see the scope "([^"]*)"$/ do |name|
6
+ Then %{I should not see "#{name}" within ".scopes"}
7
+ end
8
+
5
9
  Then /^I should see the scope "([^"]*)" selected$/ do |name|
6
- Then %{I should see "#{name}" within ".scopes span.selected"}
10
+ Then %{I should see "#{name}" within ".scopes .selected"}
7
11
  end
8
12
 
9
13
  Then /^I should see the scope "([^"]*)" not selected$/ do |name|
10
14
  Then %{I should see the scope "#{name}"}
11
- page.should_not have_css('.scopes span.selected', :text => name)
15
+ page.should_not have_css('.scopes .selected', :text => name)
12
16
  end
13
17
 
14
18
  Then /^I should see the scope "([^"]*)" with the count (\d+)$/ do |name, count|
15
- Then %{I should see "#{count}" within ".scopes .#{name.downcase} .count"}
19
+ Then %{I should see "#{count}" within ".scopes .#{name.gsub(" ", "").underscore.downcase} .count"}
16
20
  end
17
21
 
18
22
  Then /^I should see (\d+) ([\w]*) in the table$/ do |count, resource_type|
19
- page.should have_css("table##{resource_type} tr > td:first", :count => count.to_i)
23
+ begin
24
+ page.should have_css("table##{resource_type} tr > td:first", :count => count.to_i)
25
+ rescue
26
+ current_count = 0
27
+
28
+ all("table##{resource_type} tr > td:first").each { current_count += 1 }
29
+
30
+ raise "There were #{current_count} rows in the table not #{count}"
31
+ end
20
32
  end
@@ -0,0 +1,7 @@
1
+ Then /^I should see an action item button "([^"]*)"$/ do |content|
2
+ page.should have_css(".action_items a", :text => content)
3
+ end
4
+
5
+ Then /^I should not see an action item button "([^"]*)"$/ do |content|
6
+ page.should_not have_css(".action_items", :text => content)
7
+ end
@@ -0,0 +1,15 @@
1
+ Then /^I should see the site title "([^"]*)"$/ do |title|
2
+ page.should have_css('h1#site_title', :text => title)
3
+ end
4
+
5
+ Then /^I should not see the site title "([^"]*)"$/ do |title|
6
+ page.should_not have_css('h1#site_title', :text => title)
7
+ end
8
+
9
+ Then /^I should see the site title image "([^"]*)"$/ do |image|
10
+ page.should have_css('h1#site_title img', :src => image)
11
+ end
12
+
13
+ Then /^I should see the site title image linked to "([^"]*)"$/ do |url|
14
+ page.should have_css('h1#site_title a', :href => url)
15
+ end
@@ -28,6 +28,12 @@ module NavigationHelpers
28
28
  when /^the index page for (.*)$/
29
29
  send(:"admin_#{$1}_path")
30
30
 
31
+ when /^the last author's posts$/
32
+ admin_user_posts_path(User.last)
33
+
34
+ when /^the last author's last post page$/
35
+ admin_user_post_path(User.last, Post.where(:author_id => User.last.id).last)
36
+
31
37
  # Add more mappings here.
32
38
  # Here is an example that pulls values out of the Regexp:
33
39
  #
@@ -11,3 +11,14 @@ Feature: User Logging out
11
11
  When I go to the dashboard
12
12
  And I follow "Logout"
13
13
  Then I should see "Login"
14
+
15
+ Scenario: With logout_link_path set to :logout_path (the symbol)
16
+ Given a configuration of:
17
+ """
18
+ ActiveAdmin.setup do |config|
19
+ config.logout_link_path = :logout_path
20
+ end
21
+ """
22
+ And I am logged in
23
+ When I go to the dashboard
24
+ Then I should see the default welcome message
data/lib/active_admin.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'meta_search'
2
+ require 'bourbon'
2
3
  require 'devise'
3
4
  require 'kaminari'
5
+ require 'formtastic'
4
6
  require 'sass'
7
+ require 'jquery-rails'
5
8
  require 'active_admin/arbre'
6
9
  require 'active_admin/engine'
7
10
 
@@ -13,6 +16,7 @@ module ActiveAdmin
13
16
  autoload :Breadcrumbs, 'active_admin/breadcrumbs'
14
17
  autoload :Callbacks, 'active_admin/callbacks'
15
18
  autoload :Component, 'active_admin/component'
19
+ autoload :BaseController, 'active_admin/base_controller'
16
20
  autoload :ControllerAction, 'active_admin/controller_action'
17
21
  autoload :CSVBuilder, 'active_admin/csv_builder'
18
22
  autoload :Dashboards, 'active_admin/dashboards'
@@ -22,14 +26,20 @@ module ActiveAdmin
22
26
  autoload :DSL, 'active_admin/dsl'
23
27
  autoload :Event, 'active_admin/event'
24
28
  autoload :FormBuilder, 'active_admin/form_builder'
29
+ autoload :FilterFormBuilder, 'active_admin/filter_form_builder'
30
+ autoload :Inputs, 'active_admin/inputs'
25
31
  autoload :Iconic, 'active_admin/iconic'
26
32
  autoload :Menu, 'active_admin/menu'
27
33
  autoload :MenuItem, 'active_admin/menu_item'
28
34
  autoload :Namespace, 'active_admin/namespace'
29
- autoload :PageConfig, 'active_admin/page_config'
35
+ autoload :Page, 'active_admin/page'
36
+ autoload :PagePresenter, 'active_admin/page_presenter'
37
+ autoload :PageController, 'active_admin/page_controller'
38
+ autoload :PageDSL, 'active_admin/page_dsl'
30
39
  autoload :Reloader, 'active_admin/reloader'
31
40
  autoload :Resource, 'active_admin/resource'
32
41
  autoload :ResourceController, 'active_admin/resource_controller'
42
+ autoload :ResourceDSL, 'active_admin/resource_dsl'
33
43
  autoload :Renderer, 'active_admin/renderer'
34
44
  autoload :Scope, 'active_admin/scope'
35
45
  autoload :ScopeChain, 'active_admin/helpers/scope_chain'
@@ -45,27 +55,31 @@ module ActiveAdmin
45
55
  I18n.load_path += Dir[File.expand_path('../active_admin/locales/*.yml', __FILE__)]
46
56
  end
47
57
 
48
- # The instance of the configured application
49
- @@application = ::ActiveAdmin::Application.new
50
- mattr_accessor :application
51
-
52
58
  class << self
53
59
 
60
+ attr_accessor :application
61
+
62
+ def application
63
+ @application ||= ::ActiveAdmin::Application.new
64
+ end
65
+
54
66
  # Gets called within the initializer
55
67
  def setup
68
+ application.setup!
56
69
  yield(application)
57
70
  application.prepare!
58
71
  end
59
72
 
60
- delegate :register, :to => :application
61
- delegate :unload!, :to => :application
62
- delegate :load!, :to => :application
63
- delegate :routes, :to => :application
73
+ delegate :register, :to => :application
74
+ delegate :register_page, :to => :application
75
+ delegate :unload!, :to => :application
76
+ delegate :load!, :to => :application
77
+ delegate :routes, :to => :application
64
78
 
65
79
  # Returns true if this rails application has the asset
66
80
  # pipeline enabled.
67
81
  def use_asset_pipeline?
68
- DependencyChecker.rails_3_1? && Rails.application.config.assets.enabled
82
+ DependencyChecker.rails_3_1? && Rails.application.config.try(:assets).try(:enabled)
69
83
  end
70
84
 
71
85
  # Migration MoveAdminNotesToComments generated with version 0.2.2 might reference
@@ -75,6 +89,7 @@ module ActiveAdmin
75
89
  "ActiveAdmin.default_namespace is deprecated. Please use ActiveAdmin.application.default_namespace"
76
90
 
77
91
  end
92
+
78
93
  end
79
94
 
80
95
  ActiveAdmin::DependencyChecker.check!
@@ -5,6 +5,13 @@ module ActiveAdmin
5
5
  class Application
6
6
  include Settings
7
7
 
8
+ # Adds settings to both the Application and the Namespace instance
9
+ # so that they can be configured independantly.
10
+ def self.inheritable_setting(name, default)
11
+ Namespace.setting name, nil
12
+ setting name, default
13
+ end
14
+
8
15
  # The default namespace to put controllers and routes inside. Set this
9
16
  # in config/initializers/active_admin.rb using:
10
17
  #
@@ -12,40 +19,43 @@ module ActiveAdmin
12
19
  #
13
20
  setting :default_namespace, :admin
14
21
 
15
- # The default number of resources to display on index pages
16
- setting :default_per_page, 30
17
-
18
22
  # A hash of all the registered namespaces
19
23
  setting :namespaces, {}
20
24
 
21
- # The title which gets displayed in the main layout
22
- setting :site_title, ""
23
-
24
- # Set the site title link href (defaults to AA dashboard)
25
- setting :site_title_link, ""
26
-
27
25
  # Load paths for admin configurations. Add folders to this load path
28
26
  # to load up other resources for administration. External gems can
29
27
  # include their paths in this load path to provide active_admin UIs
30
28
  setting :load_paths, [File.expand_path('app/admin', Rails.root)]
31
29
 
30
+ # The default number of resources to display on index pages
31
+ inheritable_setting :default_per_page, 30
32
+
33
+ # The title which gets displayed in the main layout
34
+ inheritable_setting :site_title, ""
35
+
36
+ # Set the site title link href (defaults to AA dashboard)
37
+ inheritable_setting :site_title_link, ""
38
+
39
+ # Set the site title image displayed in the main layout (has precendence over :site_title)
40
+ inheritable_setting :site_title_image, ""
41
+
32
42
  # The view factory to use to generate all the view classes. Take
33
43
  # a look at ActiveAdmin::ViewFactory
34
- setting :view_factory, ActiveAdmin::ViewFactory.new
44
+ inheritable_setting :view_factory, ActiveAdmin::ViewFactory.new
35
45
 
36
46
  # The method to call in controllers to get the current user
37
- setting :current_user_method, false
47
+ inheritable_setting :current_user_method, false
38
48
 
39
49
  # The method to call in the controllers to ensure that there
40
50
  # is a currently authenticated admin user
41
- setting :authentication_method, false
51
+ inheritable_setting :authentication_method, false
42
52
 
43
53
  # The path to log user's out with. If set to a symbol, we assume
44
54
  # that it's a method to call which returns the path
45
- setting :logout_link_path, :destroy_admin_user_session_path
55
+ inheritable_setting :logout_link_path, :destroy_admin_user_session_path
46
56
 
47
57
  # The method to use when generating the link for user logout
48
- setting :logout_link_method, :get
58
+ inheritable_setting :logout_link_method, :get
49
59
 
50
60
  # Active Admin makes educated guesses when displaying objects, this is
51
61
  # the list of methods it tries calling in order
@@ -67,10 +77,12 @@ module ActiveAdmin
67
77
  # the #allow_comments_in option instead
68
78
  attr_accessor :admin_notes
69
79
 
70
-
71
80
  include AssetRegistration
72
81
 
73
- def initialize
82
+ # Event that gets triggered on load of Active Admin
83
+ LoadEvent = 'active_admin.application.load'.freeze
84
+
85
+ def setup!
74
86
  register_default_assets
75
87
  end
76
88
 
@@ -82,21 +94,39 @@ module ActiveAdmin
82
94
 
83
95
  # Registers a brand new configuration for the given resource.
84
96
  def register(resource, options = {}, &block)
85
- namespace_name = options.has_key?(:namespace) ? options[:namespace] : default_namespace
97
+ namespace_name = extract_namespace_name(options)
86
98
  namespace = find_or_create_namespace(namespace_name)
87
99
  namespace.register(resource, options, &block)
88
100
  end
89
101
 
90
102
  # Creates a namespace for the given name
103
+ #
104
+ # Yields the namespace if a block is given
105
+ #
106
+ # @returns [Namespace] the new or existing namespace
91
107
  def find_or_create_namespace(name)
92
108
  name ||= :root
93
109
  return namespaces[name] if namespaces[name]
94
110
  namespace = Namespace.new(self, name)
95
- ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace
96
111
  namespaces[name] = namespace
112
+ ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace
113
+ yield(namespace) if block_given?
97
114
  namespace
98
115
  end
99
116
 
117
+ alias_method :namespace, :find_or_create_namespace
118
+
119
+ # Register a page
120
+ #
121
+ # @param name [String] The page name
122
+ # @options [Hash] Accepts option :namespace.
123
+ # @&block The registration block.
124
+ #
125
+ def register_page(name, options = {}, &block)
126
+ namespace_name = extract_namespace_name(options)
127
+ namespace = find_or_create_namespace(namespace_name)
128
+ namespace.register_page(name, options, &block)
129
+ end
100
130
 
101
131
  # Stores if everything has been loaded or we need to reload
102
132
  @@loaded = false
@@ -113,7 +143,6 @@ module ActiveAdmin
113
143
  # to allow for changes without having to restart the server.
114
144
  def unload!
115
145
  namespaces.values.each{|namespace| namespace.unload! }
116
- self.namespaces = {}
117
146
  @@loaded = false
118
147
  end
119
148
 
@@ -137,6 +166,9 @@ module ActiveAdmin
137
166
  # Load Menus
138
167
  namespaces.values.each{|namespace| namespace.load_menu! }
139
168
 
169
+ # Dispatch an ActiveAdmin::Application::LoadEvent with the Application
170
+ ActiveAdmin::Event.dispatch LoadEvent, self
171
+
140
172
  @@loaded = true
141
173
  end
142
174
 
@@ -192,10 +224,21 @@ module ActiveAdmin
192
224
  private
193
225
 
194
226
  def register_default_assets
195
- register_stylesheet 'active_admin.css'
227
+ register_stylesheet 'active_admin.css', :media => 'all'
228
+
229
+ if !ActiveAdmin.use_asset_pipeline?
230
+ register_javascript 'jquery.min.js'
231
+ register_javascript 'jquery-ui.min.js'
232
+ register_javascript 'jquery_ujs.js'
233
+ end
234
+
196
235
  register_javascript 'active_admin.js'
197
236
  end
198
237
 
238
+ def extract_namespace_name(options)
239
+ options.has_key?(:namespace) ? options[:namespace] : default_namespace
240
+ end
241
+
199
242
  # Since we're dealing with all our own file loading, we need
200
243
  # to remove our paths from the ActiveSupport autoload paths.
201
244
  # If not, file naming becomes very important and can cause clashes.
@@ -97,6 +97,16 @@ module Arbre
97
97
  end
98
98
  alias_method :find_by_tag, :get_elements_by_tag_name
99
99
 
100
+ def get_elements_by_class_name(class_name)
101
+ elements = Collection.new
102
+ children.each do |child|
103
+ elements << child if child.class_list =~ /#{class_name}/
104
+ elements.concat(child.get_elements_by_tag_name(tag_name))
105
+ end
106
+ elements
107
+ end
108
+ alias_method :find_by_class, :get_elements_by_class_name
109
+
100
110
  def content
101
111
  children.to_html
102
112
  end
@@ -3,8 +3,8 @@ module ActiveAdmin
3
3
 
4
4
  # Stylesheets
5
5
 
6
- def register_stylesheet(name)
7
- stylesheets << name
6
+ def register_stylesheet(*args)
7
+ stylesheets << ActiveAdmin::Stylesheet.new(*args)
8
8
  end
9
9
 
10
10
  def stylesheets
@@ -31,4 +31,17 @@ module ActiveAdmin
31
31
  end
32
32
 
33
33
  end
34
+
35
+ # Wrapper class for stylesheet registration
36
+ class Stylesheet
37
+
38
+ attr_reader :options, :path
39
+
40
+ def initialize(*args)
41
+ @options = args.extract_options!
42
+ @path = args.first if args.first
43
+ end
44
+
45
+ end
46
+
34
47
  end
@@ -0,0 +1,61 @@
1
+ require 'inherited_resources'
2
+ require 'active_admin/base_controller/menu'
3
+
4
+ module ActiveAdmin
5
+ # BaseController for ActiveAdmin.
6
+ # It implements ActiveAdmin controllers core features.
7
+ class BaseController < ::InheritedResources::Base
8
+ helper ::ActiveAdmin::ViewHelpers
9
+
10
+ layout 'active_admin'
11
+
12
+ before_filter :only_render_implemented_actions
13
+ before_filter :authenticate_active_admin_user
14
+
15
+ class << self
16
+ # Ensure that this method is available for the DSL
17
+ public :actions
18
+
19
+ # Reference to the Resource object which initialized
20
+ # this controller
21
+ attr_accessor :active_admin_config
22
+ end
23
+
24
+ # By default Rails will render un-implemented actions when the view exists. Becuase Active
25
+ # Admin allows you to not render any of the actions by using the #actions method, we need
26
+ # to check if they are implemented.
27
+ def only_render_implemented_actions
28
+ raise AbstractController::ActionNotFound unless action_methods.include?(params[:action])
29
+ end
30
+
31
+ include Menu
32
+
33
+ private
34
+
35
+ # Calls the authentication method as defined in ActiveAdmin.authentication_method
36
+ def authenticate_active_admin_user
37
+ send(active_admin_namespace.authentication_method) if active_admin_namespace.authentication_method
38
+ end
39
+
40
+ def current_active_admin_user
41
+ send(active_admin_namespace.current_user_method) if active_admin_namespace.current_user_method
42
+ end
43
+ helper_method :current_active_admin_user
44
+
45
+ def current_active_admin_user?
46
+ !current_active_admin_user.nil?
47
+ end
48
+ helper_method :current_active_admin_user?
49
+
50
+ def active_admin_config
51
+ self.class.active_admin_config
52
+ end
53
+ helper_method :active_admin_config
54
+
55
+ def active_admin_namespace
56
+ active_admin_config.namespace
57
+ end
58
+ helper_method :active_admin_namespace
59
+
60
+ end
61
+ end