Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Break copy_assets and copy_locales out into their own rake tasks, for…

… cases when you just want the assets

but not a full new installation, e.g. for updates or during deployments. See README for details.
  • Loading branch information...
commit 6d7852055085b9c816c3630d1216ff9bce477b9b 1 parent ceb7384
@wolframarnold wolframarnold authored
Showing with 75 additions and 37 deletions.
  1. +28 −0 README.md
  2. +36 −37 lib/rails_admin/tasks/install.rb
  3. +11 −0 lib/tasks/install.rake
View
28 README.md
@@ -982,6 +982,34 @@ with [CanCan](https://github.com/ryanb/cancan), pass it like this.
See the [wiki](https://github.com/sferik/rails_admin/wiki) for more on authorization.
+Static Assets & Locales
+-----------------------
+
+When running `rake rails_admin:install` the locale files (`config/locales/...`) and the static asset files
+(javascript files, images, stylesheets) are copied to your local application tree.
+
+Should you update the gem to a new version that perhaps includes updated locale or asset files, then you won't automatically
+be able to take advantage of these. In fact, you may choose for this reason, to not commit locale files and asset
+files to your local repository and instead have them loaded from the gem.
+
+You can choose to commit locale files to your local application tree, if you want to modify them from what the gem
+supplies; then you also need to manage updates by hand. Locale files will be automatically loaded from the gem
+unless overrides exist.
+
+For asset files, the following applies: When running in development mode, the rails_admin engine will inject a middleware
+to serve static assets (javascript files, images, stylesheets) from the gem's location. This generally isn't a good
+setup for high-traffic production environments. Depending on your web server configuration is may also just plain fail.
+You may need to serve the asset files from the local application tree (public/...). You can choose to have the assets
+served from the gem in development mode but from the local application tree in production mode. In that case, you
+need to copy the assets during deployment (e.g. via a capistrano hook).
+
+Two rake tasks have been provided to copy locale and asset files to the local application tree:
+
+ rake rails_admin:copy_locales
+ rake rails_admin:copy_assets
+
+These tasks run automatically during installation, but are provided separately, e.g. for updates or deployments.
+
Contributing
------------
In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
View
73 lib/rails_admin/tasks/install.rb
@@ -25,42 +25,6 @@ def run(model_name = 'user')
puts "Done."
end
- private
-
- def check_for_devise_models
- devise_path = Rails.root.join("config/initializers/devise.rb")
-
- if File.exists?(devise_path)
- parse_route_files
- else
- puts "Looks like you don't have devise install! We'll install it for you!"
- `rails g devise:install`
- set_devise
- end
- end
-
- def parse_route_files
- routes_path = Rails.root.join("config/routes.rb")
-
- content = ""
-
- File.readlines(routes_path).each{|line| content += line }
-
- unless content.index("devise_for").nil?
- # there is a devise_for in routes => Do nothing
- puts "Great! You have devise installed and setup!"
- else
- puts "Great you have devise installed, but not set up!"
- set_devise
- end
- end
-
- def set_devise
- puts "Setting up devise for you!
- ======================================================"
- `rails g devise #{@@model_name}`
- end
-
def copy_locales_files
print "Now copying locales files! "
locales_path = gem_path + "/config/locales/*.yml"
@@ -75,7 +39,6 @@ def copy_locales_files
Dir.glob(locales_path).each do |file|
copier.copy_file file, File.join(app_path, File.basename(file))
end
-
end
def copy_assets_files
@@ -99,6 +62,42 @@ def copy_assets_files
end
end
+ private
+
+ def check_for_devise_models
+ devise_path = Rails.root.join("config/initializers/devise.rb")
+
+ if File.exists?(devise_path)
+ parse_route_files
+ else
+ puts "Looks like you don't have devise install! We'll install it for you!"
+ `rails g devise:install`
+ set_devise
+ end
+ end
+
+ def parse_route_files
+ routes_path = Rails.root.join("config/routes.rb")
+
+ content = ""
+
+ File.readlines(routes_path).each{|line| content += line }
+
+ unless content.index("devise_for").nil?
+ # there is a devise_for in routes => Do nothing
+ puts "Great! You have devise installed and setup!"
+ else
+ puts "Great you have devise installed, but not set up!"
+ set_devise
+ end
+ end
+
+ def set_devise
+ puts "Setting up devise for you!
+ ======================================================"
+ `rails g devise #{@@model_name}`
+ end
+
def gem_path
File.expand_path('../../..', File.dirname(__FILE__))
end
View
11 lib/tasks/install.rake
@@ -5,5 +5,16 @@ namespace :rails_admin do
task :install do
RailsAdmin::Tasks::Install.run(ENV['model_name'] || 'user')
end
+
+ desc "Copy only locale files (part of install, but useful for deployments when only assets are needed)"
+ task :copy_locales do
+ RailsAdmin::Tasks::Install.copy_locales_files
+ end
+
+ desc "Copy only assets files (part of install, useful for deployments when only assets are needed)"
+ task :copy_assets do
+ RailsAdmin::Tasks::Install.copy_assets_files
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.