diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-10-13 16:20:09 +0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-10-14 07:46:12 +0200 |
commit | 959f8576f2b70c35a2fd5c2c9563e695977f37b6 (patch) | |
tree | 5bbb4fc14b9ecde391695ad26d9765b7555285d4 /railties | |
parent | f07cbec865093c30299ad038d52e3e70e2527848 (diff) | |
download | rails-959f8576f2b70c35a2fd5c2c9563e695977f37b6.tar.gz rails-959f8576f2b70c35a2fd5c2c9563e695977f37b6.tar.bz2 rails-959f8576f2b70c35a2fd5c2c9563e695977f37b6.zip |
Added foo:install:assets task that copies assets from plugins public directory to application's public directory
This is the most simple and naive approach: just copy every files from engine to app.
The only exception is when file has changed, in that case developer will be
asked if he wants to rename the field.
There is no need to make this task more sophisticated as 3.1 will be shipped
with better assets handling and it will be the default way to handle things.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/engine.rb | 10 | ||||
-rw-r--r-- | railties/lib/rails/tasks/railties.rake | 28 | ||||
-rw-r--r-- | railties/test/railties/shared_tests.rb | 14 |
3 files changed, 47 insertions, 5 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 86a8374ded..b004724757 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -546,12 +546,12 @@ module Rails ENV["FROM"] = railtie_name Rake::Task["railties:install:migrations"].invoke end - end - desc "Copy assets from #{railtie_name} to application" - task :assets do - ENV["FROM"] = railtie_name - Rake::Task["railties:install:assets"].invoke + desc "Copy assets from #{railtie_name} to application" + task :assets do + ENV["FROM"] = railtie_name + Rake::Task["railties:install:assets"].invoke + end end end end diff --git a/railties/lib/rails/tasks/railties.rake b/railties/lib/rails/tasks/railties.rake index e08bd9687d..23d81e6671 100644 --- a/railties/lib/rails/tasks/railties.rake +++ b/railties/lib/rails/tasks/railties.rake @@ -17,4 +17,32 @@ namespace :railties do puts "Created symlink #{symlink_path} -> #{path}" end end + + namespace :install do + desc "Copies missing assets from Railties (e.g. plugins, engines). You can specify Railties to use with FROM=railtie1,railtie2" + task :assets => :rails_env do + require 'rails/generators/base' + Rails.application.initialize! + + to_load = ENV["FROM"].blank? ? :all : ENV["FROM"].split(",").map {|n| n.strip } + app_public_path = Rails.application.paths["public"].first + + Rails.application.railties.all do |railtie| + next unless to_load == :all || to_load.include?(railtie.railtie_name) + + if railtie.respond_to?(:paths) && (path = railtie.paths["public"].first) && + (assets_dir = railtie.config.compiled_asset_path) && File.exist?(path) + + Rails::Generators::Base.source_root(path) + copier = Rails::Generators::Base.new + Dir[File.join(path, "**/*")].each do |file| + relative = file.gsub(/^#{path}\//, '') + if File.file?(file) + copier.copy_file relative, File.join(app_public_path, assets_dir, relative) + end + end + end + end + end + end end diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 9f48c7acfd..d81155e8af 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -10,6 +10,20 @@ module RailtiesTest @app ||= Rails.application end + def test_copying_assets + @plugin.write "public/javascripts/foo.js", "doSomething()" + @plugin.write "public/stylesheets/foo.css", "h1 { font-size: 10000px }" + @plugin.write "public/images/img.png", "" + + Dir.chdir(app_path) do + `rake bukkits:install:assets --trace` + + assert File.exists?(app_path("public/bukkits/javascripts/foo.js")) + assert File.exists?(app_path("public/bukkits/stylesheets/foo.css")) + assert File.exists?(app_path("public/bukkits/images/img.png")) + end + end + def test_copying_migrations @plugin.write "db/migrate/1_create_users.rb", <<-RUBY class CreateUsers < ActiveRecord::Migration |