activeadmin 0.1.0

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 (89) hide show
  1. data/.document +5 -0
  2. data/.gitignore +25 -0
  3. data/Gemfile +16 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +201 -0
  6. data/Rakefile +71 -0
  7. data/active_admin.gemspec +22 -0
  8. data/lib/active_admin.rb +229 -0
  9. data/lib/active_admin/action_builder.rb +60 -0
  10. data/lib/active_admin/action_items.rb +48 -0
  11. data/lib/active_admin/asset_registration.rb +34 -0
  12. data/lib/active_admin/breadcrumbs.rb +26 -0
  13. data/lib/active_admin/dashboards.rb +50 -0
  14. data/lib/active_admin/dashboards/dashboard_controller.rb +40 -0
  15. data/lib/active_admin/dashboards/renderer.rb +45 -0
  16. data/lib/active_admin/dashboards/section.rb +43 -0
  17. data/lib/active_admin/dashboards/section_renderer.rb +28 -0
  18. data/lib/active_admin/filters.rb +189 -0
  19. data/lib/active_admin/form_builder.rb +91 -0
  20. data/lib/active_admin/helpers/optional_display.rb +34 -0
  21. data/lib/active_admin/menu.rb +42 -0
  22. data/lib/active_admin/menu_item.rb +67 -0
  23. data/lib/active_admin/namespace.rb +111 -0
  24. data/lib/active_admin/page_config.rb +15 -0
  25. data/lib/active_admin/pages.rb +11 -0
  26. data/lib/active_admin/pages/base.rb +92 -0
  27. data/lib/active_admin/pages/edit.rb +21 -0
  28. data/lib/active_admin/pages/index.rb +58 -0
  29. data/lib/active_admin/pages/index/blog.rb +65 -0
  30. data/lib/active_admin/pages/index/table.rb +48 -0
  31. data/lib/active_admin/pages/index/thumbnails.rb +40 -0
  32. data/lib/active_admin/pages/new.rb +21 -0
  33. data/lib/active_admin/pages/show.rb +54 -0
  34. data/lib/active_admin/renderer.rb +72 -0
  35. data/lib/active_admin/resource.rb +96 -0
  36. data/lib/active_admin/resource_controller.rb +325 -0
  37. data/lib/active_admin/sidebar.rb +78 -0
  38. data/lib/active_admin/table_builder.rb +162 -0
  39. data/lib/active_admin/tabs_renderer.rb +39 -0
  40. data/lib/active_admin/version.rb +3 -0
  41. data/lib/active_admin/view_helpers.rb +106 -0
  42. data/lib/active_admin/views/active_admin_dashboard/index.html.erb +1 -0
  43. data/lib/active_admin/views/active_admin_default/edit.html.erb +1 -0
  44. data/lib/active_admin/views/active_admin_default/index.csv.erb +2 -0
  45. data/lib/active_admin/views/active_admin_default/index.html.erb +1 -0
  46. data/lib/active_admin/views/active_admin_default/new.html.erb +1 -0
  47. data/lib/active_admin/views/active_admin_default/show.html.erb +1 -0
  48. data/lib/active_admin/views/layouts/active_admin.html.erb +40 -0
  49. data/lib/activeadmin.rb +1 -0
  50. data/lib/generators/active_admin/install/install_generator.rb +31 -0
  51. data/lib/generators/active_admin/install/templates/active_admin.css +325 -0
  52. data/lib/generators/active_admin/install/templates/active_admin.js +10 -0
  53. data/lib/generators/active_admin/install/templates/active_admin.rb +47 -0
  54. data/lib/generators/active_admin/install/templates/active_admin_vendor.js +382 -0
  55. data/lib/generators/active_admin/install/templates/dashboards.rb +36 -0
  56. data/lib/generators/active_admin/install/templates/images/orderable.gif +0 -0
  57. data/lib/generators/active_admin/resource/resource_generator.rb +16 -0
  58. data/lib/generators/active_admin/resource/templates/admin.rb +3 -0
  59. data/spec/integration/dashboard_spec.rb +44 -0
  60. data/spec/integration/index_as_blog_spec.rb +65 -0
  61. data/spec/integration/index_as_csv_spec.rb +40 -0
  62. data/spec/integration/index_as_table_spec.rb +160 -0
  63. data/spec/integration/index_as_thumbnails_spec.rb +43 -0
  64. data/spec/integration/layout_spec.rb +82 -0
  65. data/spec/integration/new_view_spec.rb +52 -0
  66. data/spec/integration/show_view_spec.rb +91 -0
  67. data/spec/spec_helper.rb +104 -0
  68. data/spec/support/rails_template.rb +19 -0
  69. data/spec/unit/action_builder_spec.rb +76 -0
  70. data/spec/unit/action_items_spec.rb +41 -0
  71. data/spec/unit/active_admin_spec.rb +52 -0
  72. data/spec/unit/asset_registration_spec.rb +37 -0
  73. data/spec/unit/controller_filters_spec.rb +26 -0
  74. data/spec/unit/dashboard_section_spec.rb +63 -0
  75. data/spec/unit/dashboards_spec.rb +59 -0
  76. data/spec/unit/filter_form_builder_spec.rb +157 -0
  77. data/spec/unit/form_builder_spec.rb +238 -0
  78. data/spec/unit/menu_item_spec.rb +137 -0
  79. data/spec/unit/menu_spec.rb +53 -0
  80. data/spec/unit/namespace_spec.rb +107 -0
  81. data/spec/unit/registration_spec.rb +46 -0
  82. data/spec/unit/renderer_spec.rb +100 -0
  83. data/spec/unit/resource_controller_spec.rb +48 -0
  84. data/spec/unit/resource_spec.rb +197 -0
  85. data/spec/unit/routing_spec.rb +12 -0
  86. data/spec/unit/sidebar_spec.rb +96 -0
  87. data/spec/unit/table_builder_spec.rb +162 -0
  88. data/spec/unit/tabs_renderer_spec.rb +34 -0
  89. metadata +247 -0
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,25 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .bundle
23
+ spec/rails
24
+ *.sqlite3-journal
25
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # These resources are needed to setup the test env
2
+ source 'http://rubygems.org'
3
+
4
+ # Rails & ActiveAdmin Dependencies
5
+ gem 'rails', '3.0.0'
6
+ gem 'sqlite3-ruby', :require => 'sqlite3'
7
+ gem 'haml', '3.0.18'
8
+ gem 'formtastic', '1.1.0.beta'
9
+ gem 'will_paginate', '3.0.pre2'
10
+ gem "meta_search", '0.9.2'
11
+ gem 'inherited_views'
12
+ gem 'jeweler'
13
+
14
+ # Testing Dependencies
15
+ gem 'rspec', '2.0.0.beta.20'
16
+ gem 'rspec-rails', '2.0.0.beta.20'
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Greg Bell, VersaPay Corporation
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,201 @@
1
+ = Active Admin
2
+
3
+ Active Admin is a tool to facilitate the generation of administration style interfaces.
4
+
5
+
6
+ == Goals
7
+
8
+ Although Active Admin is very young in its development cycle, here are its current goals:
9
+
10
+ 1. Build a toolset to quickly create template-able administration interfaces
11
+ 2. Allow the toolset to be entirely customizable (ie: we use standard rails coding practices
12
+ which can be overridden at any point)
13
+ 3. Design an interface which looks great!
14
+ 4. Build administration interfaces for common rails plugins as gems and share with the
15
+ community (ie: devise admin)
16
+
17
+
18
+ == Status
19
+
20
+ Active Admin is very young. Although the code is well tested and is being used in production,
21
+ the project is under heavy development. Once we get it to a point that has a relatively stable api,
22
+ we will begin numbered releases starting with a 0.1 release.
23
+
24
+ == Installation (Rails 3)
25
+
26
+ Add the following to your Gemfile:
27
+
28
+ gem 'formtastic', :git => "git://github.com/justinfrench/formtastic.git", :branch => 'rails3'
29
+ gem 'will_paginate', :git => "git://github.com/mislav/will_paginate.git", :branch => 'rails3'
30
+ gem 'meta_search', :git => "git://github.com/ernie/meta_search.git"
31
+ gem 'active_admin', :git => "git://github.com/gregbell/active_admin.git"
32
+
33
+ Then, run the installer:
34
+
35
+ rails generate active_admin:install
36
+
37
+ This will create an initializer which is used for configuring defaults used by Active Admin as well
38
+ as a new folder at app/admin to put all your admin configurations. Note: All ruby files in
39
+ the Active Admin load path get loaded into the rails application.
40
+
41
+ == Usage
42
+
43
+ Let's build up an example using a Post model and the provided admin generator.
44
+
45
+ rails generate active_admin:resource post
46
+
47
+ That's all you need to get a full CRUD, beautiful administration interface!
48
+
49
+ The generator will create a new file app/admin/posts.rb that will
50
+ look like the following:
51
+
52
+ ActiveAdmin.register Post
53
+
54
+ === Customize the Index Page
55
+
56
+ By default, the index page is a table with each of the models content columns and links to
57
+ show, edit and delete the object. There are many ways to customize what gets displayed:
58
+
59
+ ==== Simple Columns
60
+
61
+ If all you need to do is change the columns which get displayed, you can do so by passing
62
+ them to the columns method:
63
+
64
+ ActiveAdmin.register Post do
65
+
66
+ index do |display|
67
+ display.columns :title, :comments_count, :created_at
68
+ end
69
+
70
+ end
71
+
72
+ Or you can pass them in individually:
73
+
74
+ ActiveAdmin.register Post do
75
+
76
+ index do |display|
77
+
78
+ # This will title the column 'Title' and call the #title method on each object
79
+ display.column :title
80
+
81
+ # This will title the column 'How many comments?' and call the #comments_count method on each object
82
+ display.column 'How many comments?', :comments_count
83
+
84
+ # You can add methods to the table builder which builds common things (ie: selectable checkboxes)
85
+ display.default_actions
86
+
87
+ end
88
+
89
+ end
90
+
91
+ ==== Advanced Columns
92
+
93
+ Sometimes calling methods just isn't enough and you need to write some view specific code. For
94
+ example, say we wanted a colum called Title which holds a link to the posts admin screen.
95
+
96
+ You can pass a block to a column which will then be rendered within the context of the view
97
+ for each of the objects in the collection.
98
+
99
+
100
+ ActiveAdmin.register Post do
101
+
102
+ index do |display|
103
+ display.column("Title"){|post| link_to post.title, admin_post_path(post) }
104
+ end
105
+
106
+ end
107
+
108
+ The block gets called once for each resource in the collection. The resource gets passed into
109
+ the block as an argument.
110
+
111
+ ==== Sorting
112
+
113
+ The index views in Active Admin include sorting by default.
114
+
115
+ ActiveAdmin.register Post do
116
+
117
+ index do |display|
118
+
119
+ # A column created by a method call assumes its sortable
120
+ display.column :id
121
+
122
+ # If a column is defined using a block, you must pass the key to turn on sorting. The key
123
+ # is the attribute which gets used to sort objects using Active Record.
124
+ display.column("Title", :sortable => :title){|post| link_to post.title, admin_post_path(post) }
125
+
126
+ # Turn off sorting by passing false
127
+ display.column :do_not_sort_me, :sortable => false
128
+
129
+ end
130
+
131
+ end
132
+
133
+
134
+ === Customize the Form
135
+
136
+ Active Admin gives complete control over the output of the form by creating a thin DSL on top of
137
+ the fabulous DSL created by Formtastic (http://github.com/justinfrench/formtastic).
138
+
139
+ ActiveAdmin.register Post do
140
+
141
+ form do |f|
142
+ f.inputs "Details" do
143
+ f.input :title
144
+ f.input :published_at, :label => "Publish Post At"
145
+ f.input :category
146
+ end
147
+ f.inputs "Content" do
148
+ f.input :body
149
+ end
150
+ f.buttons
151
+ end
152
+
153
+ end
154
+
155
+ Please view the documentation for Formtastic to see all the wonderful things you can do:
156
+ http://github.com/justinfrench/formtastic
157
+
158
+
159
+ == Tools Being Used
160
+
161
+ We believe strongly in not writing code unless we have to, so Active Admin is built using many
162
+ other open source projects:
163
+
164
+ InheritedResources::
165
+ Inherited Resources speeds up development by making your controllers inherit all restful
166
+ actions so you just have to focus on what is important.
167
+ InheritedViews::
168
+ Inherited Views is a thin addition to Inherited Resources which adds in html views to the mix
169
+ Formtastic::
170
+ A DSL for semantically building amazing forms.
171
+ WillPaginate::
172
+ Pagination for rails apps
173
+
174
+
175
+ == Contributors
176
+
177
+ * Greg Bell http://github.com/gregbell
178
+ * Philippe Creux http://github.com/pcreux
179
+ * Sam Vincent http://github.com/samvincent
180
+ * Matt Vague http://github.com/mattvague
181
+ * Dan Kubb http://github.com/dkubb
182
+
183
+
184
+ == Roadmap & Issue Tracking
185
+
186
+ We are using the awesome Lighthouse ticketing system. The project can be found at:
187
+ http://activeadmin.lighthouseapp.com
188
+
189
+ == Note on Patches/Pull Requests
190
+
191
+ * Fork the project.
192
+ * Make your feature addition or bug fix.
193
+ * Add tests for it. This is important so I don't break it in a
194
+ future version unintentionally.
195
+ * Commit, do not mess with rakefile, version, or history.
196
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
197
+ * Send me a pull request. Bonus points for topic branches.
198
+
199
+ == Copyright
200
+
201
+ Copyright (c) 2010 Greg Bell, VersaPay Corporation. See LICENSE for details.
@@ -0,0 +1,71 @@
1
+ require 'rubygems'
2
+ require "bundler"
3
+ Bundler.setup
4
+
5
+ require 'rake'
6
+
7
+ desc "Creates a test rails app for the specs to run against"
8
+ task :setup do
9
+ system("mkdir spec/rails") unless File.exists?("spec/rails")
10
+ system "bundle exec rails new spec/rails/rails-3.0.0 -m spec/support/rails_template.rb"
11
+ end
12
+
13
+ require "rspec/core/rake_task"
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
17
+ spec.rcov = true
18
+ end
19
+
20
+ task :default => :spec
21
+
22
+ namespace :spec do
23
+
24
+ desc "Run specs for all versions of rails"
25
+ task :all do
26
+ puts "Runing for Rails 2.3.5"
27
+ out = `rake spec`
28
+ puts out
29
+ puts "Running for Rails 3"
30
+ out = `rake spec RAILS=3.0.0`
31
+ puts out
32
+ end
33
+
34
+ end
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = "active_admin #{version}"
42
+ rdoc.rdoc_files.include('README*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
45
+
46
+ begin
47
+ require 'jeweler'
48
+ Jeweler::Tasks.new do |gem|
49
+ gem.name = "activeadmin"
50
+ gem.summary = "The administration framework for Ruby on Rails."
51
+ gem.description = "The administration framework for Ruby on Rails."
52
+ gem.email = "gregdbell@gmail.com"
53
+ gem.homepage = "http://github.com/gregbell/active_admin"
54
+ gem.authors = ["Greg Bell"]
55
+
56
+ gem.files.exclude 'spec/rails'
57
+ gem.test_files.exclude 'spec/rails'
58
+
59
+ require File.join(File.dirname(File.expand_path(__FILE__)), 'lib', 'active_admin', 'version')
60
+ gem.version = ActiveAdmin::VERSION
61
+
62
+ gem.add_dependency 'rails', '>= 3.0.0'
63
+ gem.add_dependency 'formtastic', '>= 1.1.0.beta'
64
+ gem.add_dependency 'will_paginate', '>= 3.0.pre2'
65
+ gem.add_dependency "meta_search", '>= 0.9.2'
66
+ gem.add_dependency 'inherited_views'
67
+ end
68
+ Jeweler::GemcutterTasks.new
69
+ rescue LoadError
70
+ puts "Jeweler not available. Install it with: gem install jeweler"
71
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+
5
+ require 'active_admin/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "active_admin"
9
+ s.version = ActiveAdmin::VERSION
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = ["Greg Bell"]
12
+ s.email = ["gregdbell@gmail.com"]
13
+ s.homepage = "http://github.com/gregbell/active_admin"
14
+ s.summary = "The missing administration framework for Ruby on Rails"
15
+ s.description = "ActiveAdmin DRY's your administration UI so that you can concentrate on what's actually important"
16
+
17
+ s.add_dependency 'inherited_views', '>= 0.0.1'
18
+ s.add_dependency 'meta_search'
19
+
20
+ s.files = Dir.glob("lib/**/*") + %w(LICENSE README.rdoc)
21
+ s.require_path = 'lib'
22
+ end
@@ -0,0 +1,229 @@
1
+ require 'meta_search'
2
+
3
+ module ActiveAdmin
4
+
5
+ autoload :VERSION, 'active_admin/version'
6
+ autoload :Namespace, 'active_admin/namespace'
7
+ autoload :Resource, 'active_admin/resource'
8
+ autoload :ResourceController, 'active_admin/resource_controller'
9
+ autoload :Dashboards, 'active_admin/dashboards'
10
+ autoload :Renderer, 'active_admin/renderer'
11
+ autoload :TableBuilder, 'active_admin/table_builder'
12
+ autoload :FormBuilder, 'active_admin/form_builder'
13
+ autoload :TabsRenderer, 'active_admin/tabs_renderer'
14
+ autoload :ViewHelpers, 'active_admin/view_helpers'
15
+ autoload :Breadcrumbs, 'active_admin/breadcrumbs'
16
+ autoload :Filters, 'active_admin/filters'
17
+ autoload :PageConfig, 'active_admin/page_config'
18
+ autoload :Pages, 'active_admin/pages'
19
+ autoload :Sidebar, 'active_admin/sidebar'
20
+ autoload :ActionItems, 'active_admin/action_items'
21
+ autoload :AssetRegistration, 'active_admin/asset_registration'
22
+ autoload :Menu, 'active_admin/menu'
23
+ autoload :MenuItem, 'active_admin/menu_item'
24
+ autoload :ActionBuilder, 'active_admin/action_builder'
25
+
26
+ extend AssetRegistration
27
+
28
+ # The default namespace to put controllers and routes inside. Set this
29
+ # in config/initializers/active_admin.rb using:
30
+ #
31
+ # ActiveAdmin.default_namespace = :super_admin
32
+ #
33
+ @@default_namespace = :admin
34
+ mattr_accessor :default_namespace
35
+
36
+ # The default number of resources to display on index pages
37
+ @@default_per_page = 30
38
+ mattr_accessor :default_per_page
39
+
40
+ # The default sort order for index pages
41
+ @@default_sort_order = 'id_desc'
42
+ mattr_accessor :default_sort_order
43
+
44
+ # A hash of all the registered namespaces
45
+ @@namespaces = {}
46
+ mattr_accessor :namespaces
47
+
48
+ # The title which get's displayed in the main layout
49
+ @@site_title = ""
50
+ mattr_accessor :site_title
51
+
52
+ # Load paths for admin configurations. Add folders to this load path
53
+ # to load up other resources for administration. External gems can
54
+ # include thier paths in this load path to provide active_admin UIs
55
+ @@load_paths = [File.expand_path('app/admin', Rails.root)]
56
+ mattr_accessor :load_paths
57
+
58
+ # Stores if everything has been loaded or we need to reload
59
+ @@loaded = false
60
+
61
+ # A hash containing a menu for each of our namespaces
62
+ @@menus = {}
63
+ mattr_accessor :menus
64
+
65
+ # The class to use to render the tabs in the interface
66
+ @@tabs_renderer = ActiveAdmin::TabsRenderer
67
+ mattr_accessor :tabs_renderer
68
+
69
+ class << self
70
+
71
+ # Get's called within the initializer
72
+ def setup
73
+ # Register the default assets
74
+ register_stylesheet 'active_admin.css'
75
+ register_javascript 'active_admin_vendor.js'
76
+ register_javascript 'active_admin.js'
77
+
78
+ # Since we're dealing with all our own file loading, we need
79
+ # to remove our paths from the ActiveSupport autoload paths.
80
+ # If not, file nameing becomes very important and can cause clashes.
81
+ ActiveSupport::Dependencies.autoload_paths.reject!{|path| load_paths.include?(path) }
82
+
83
+ # Don't eagerload our configs, we'll deal with them ourselves
84
+ Rails.application.config.eager_load_paths = Rails.application.config.eager_load_paths.reject do |path|
85
+ load_paths.include?(path)
86
+ end
87
+
88
+ # Dispatch request which gets triggered once in production
89
+ # and on every require in development mode
90
+ ActionDispatch::Callbacks.to_prepare :active_admin do
91
+ ActiveAdmin.unload!
92
+ # Because every time we load, the routes may have changed
93
+ # we must ensure to load the routes each request (in dev)
94
+ Rails.application.reload_routes!
95
+ end
96
+
97
+ yield self
98
+ end
99
+
100
+ # Registers a brand new configuration for the given resource.
101
+ #
102
+ # TODO: Setup docs for registration options
103
+ def register(resource, options = {}, &block)
104
+ namespace_name = options[:namespace] == false ? :root : (options[:namespace] || default_namespace)
105
+ namespace = namespaces[namespace_name] ||= Namespace.new(namespace_name)
106
+ namespace.register(resource, options, &block)
107
+ end
108
+
109
+ # Returns true if all the configuration files have been loaded.
110
+ def loaded?
111
+ @@loaded
112
+ end
113
+
114
+ # Removes all the controllers that were defined by registering
115
+ # resources for administration.
116
+ #
117
+ # We remove them, then load them on each request in development
118
+ # to allow for changes without having to restart the server.
119
+ def unload!
120
+ namespaces.values.each{|namespace| namespace.unload! }
121
+ @@loaded = false
122
+ end
123
+
124
+ # Loads all of the ruby files that are within the load path of
125
+ # ActiveAdmin.load_paths. This should load all of the administration
126
+ # UIs so that they are available for the router to proceed.
127
+ #
128
+ # The files are only loaded if we haven't already loaded all the files
129
+ # and they aren't marked for re-loading. To mark the files for re-loading
130
+ # you must first call ActiveAdmin.unload!
131
+ def load!
132
+ unless loaded?
133
+ load_paths.flatten.compact.uniq.each do |path|
134
+ Dir["#{path}/*.rb"].each{|f| load f }
135
+ end
136
+ @@loaded = true
137
+ return true
138
+ end
139
+ false
140
+ end
141
+
142
+ # Creates all the necessary routes for the ActiveAdmin configurations
143
+ #
144
+ # Use this within the routes.rb file:
145
+ #
146
+ # Application.routes.draw do |map|
147
+ # ActiveAdmin.routes(self)
148
+ # end
149
+ #
150
+ def routes(router)
151
+ # Ensure that all the configurations (which define the routes)
152
+ # are all loaded
153
+ load!
154
+
155
+ # Define any necessary dashboard routes
156
+ router.instance_exec(namespaces.values) do |namespaces|
157
+ namespaces.each do |namespace|
158
+ if namespace.root?
159
+ match '/' => 'dashboard#index', :as => 'dashboard'
160
+ else
161
+ name = namespace.name
162
+ match name.to_s => "#{name}/dashboard#index", :as => "#{name.to_s}_dashboard"
163
+ end
164
+ end
165
+ end
166
+
167
+ # Now define the routes for each resource
168
+ router.instance_exec(namespaces) do |namespaces|
169
+ resources = namespaces.values.collect{|n| n.resources.values }.flatten
170
+ resources.each do |config|
171
+
172
+ # Define the block the will get eval'd within the namespace
173
+ route_definition_block = Proc.new do
174
+ resources config.underscored_resource_name.pluralize do
175
+
176
+ # Define any member actions
177
+ member do
178
+ config.member_actions.each do |action|
179
+ # eg: get :comment
180
+ send(action.http_verb, action.name)
181
+ end
182
+ end
183
+
184
+ # Define any collection actions
185
+ collection do
186
+ config.collection_actions.each do |action|
187
+ send(action.http_verb, action.name)
188
+ end
189
+ end
190
+ end
191
+ end
192
+
193
+ if config.namespace.root?
194
+ instance_eval(&route_definition_block)
195
+ else
196
+ namespace config.namespace.name do
197
+ instance_eval(&route_definition_block)
198
+ end
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ #
205
+ # Add before, around and after filters to each registered resource.
206
+ #
207
+ # eg:
208
+ #
209
+ # ActiveAdmin.before_filter :authenticate_admin!
210
+ #
211
+ def before_filter(*args, &block)
212
+ ResourceController.before_filter(*args, &block)
213
+ end
214
+
215
+ def after_filter(*args, &block)
216
+ ResourceController.after_filter(*args, &block)
217
+ end
218
+
219
+ def around_filter(*args, &block)
220
+ ResourceController.around_filter(*args, &block)
221
+ end
222
+
223
+ # Helper method to add a dashboard section
224
+ def dashboard_section(name, options = {}, &block)
225
+ ActiveAdmin::Dashboards.add_section(name, options, &block)
226
+ end
227
+
228
+ end
229
+ end