Changeset 344
- Timestamp:
- 04/06/06 16:16:01 (3 years ago)
- Files:
-
- plugins/engines/CHANGELOG (modified) (2 diffs)
- plugins/engines/generators/engine/engine_generator.rb (modified) (3 diffs)
- plugins/engines/generators/engine/templates/init_engine.erb (copied) (copied from engines/tags/rel_1.1.1/generators/engine/templates/init_engine.erb)
- plugins/engines/generators/engine/templates/init_engine.rb (deleted)
- plugins/engines/generators/engine/templates/install.erb (copied) (copied from engines/tags/rel_1.1.1/generators/engine/templates/install.erb)
- plugins/engines/generators/engine/templates/lib/engine.erb (copied) (copied from engines/tags/rel_1.1.1/generators/engine/templates/lib/engine.erb)
- plugins/engines/generators/engine/templates/lib/engine.rb (deleted)
- plugins/engines/generators/engine/templates/test/test_helper.erb (copied) (copied from engines/tags/rel_1.1.1/generators/engine/templates/test/test_helper.erb)
- plugins/engines/generators/engine/templates/test/test_helper.rb (deleted)
- plugins/engines/lib/engines.rb (modified) (6 diffs)
- plugins/engines/lib/engines/action_mailer_extensions.rb (modified) (2 diffs)
- plugins/engines/lib/engines/active_record_extensions.rb (modified) (1 diff)
- plugins/engines/lib/engines/dependencies_extensions.rb (modified) (3 diffs)
- plugins/engines/tasks/engines.rake (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/engines/CHANGELOG
r307 r344 1 1 *SVN* 2 2 3 ----- 4 1.1.1 5 6 - Fixed migration rake task failing when given a specific version (Ticket #115) 7 - Added new rake task "test:engines" which will test engines (and other plugins) but ensure that the test database is cloned from development beforehand (Ticket #125) 8 - Fixed issue where 'engine_schema_info' table was included in schema dumps (Ticket #87) 9 - Fixed multi-part emails (Ticket #121) 10 - Added an 'install.rb' file to new engines created by the bundled generator, which installs the engines plugin automatically if it doesn't already exist (Ticket #122) 11 - Added a default VERSION module to generated engines (Ticket #123) 12 - Refactored copying of engine's public files to a method of an Engine instance. You can now call Engines.get(:engine_name).copy_public_files (Ticket #108) 13 - Changed engine generator templates from .rb files to .erb files (Ticket #106) 14 - Fixed the test_helper.erb file to use the correct testing extensions and not load any schema - the schema will be cloned automatically via rake test:engines 15 - Fixed problem when running with Rails 1.1.1 where version wasn't determined correctly (Ticket #129) 16 17 ----- 18 1.1.0 19 3 20 - Improved regexp matching for Rails 1.0 engines with peculiar paths 4 - Engine instance objects can be accessed via Engines[:name], an alias 5 for Engines.get(:name) (Ticket #99) 6 - init_engine.rb is now processed as the final step in the Engine.start 7 process, so it can access files within the lib directory, which is now 8 in the $LOAD_PATH at that point. (Ticket #99) 21 - Engine instance objects can be accessed via Engines[:name], an alias for Engines.get(:name) (Ticket #99) 22 - init_engine.rb is now processed as the final step in the Engine.start process, so it can access files within the lib directory, which is now in the $LOAD_PATH at that point. (Ticket #99) 9 23 - Clarified MIT license (Ticket #98) 10 24 - Updated Rake tasks to integrate smoothly with Rails 1.1 namespaces 11 25 - Changed the version to "1.1.0 (svn)" 12 26 - Added more information about using the plugin with Edge Rails to the README 13 - moved extensions into lib/engines/ directory to enable use of 14 Engines module in extension code. 15 - Added conditional require_or_load method which attempts to detect 16 the current Rails version. To use the Edge Rails version of the loading 17 mechanism, add the line: 27 - moved extensions into lib/engines/ directory to enable use of Engines module in extension code. 28 - Added conditional require_or_load method which attempts to detect the current Rails version. To use the Edge Rails version of the loading mechanism, add the line: 18 29 Engines.config :edge, true 19 30 to your environment.rb file. 20 31 - Merged changes from /branches/edge and /branches/rb_1.0 into /trunk 21 - engine_schema_info now respects the prefix/suffixes set for 22 ActiveRecord::Base (Ticket #67) 23 - added ActiveRecord::Base.wrapped_table_name(name) method to assist 24 in determining the correct table name 32 - engine_schema_info now respects the prefix/suffixes set for ActiveRecord::Base (Ticket #67) 33 - added ActiveRecord::Base.wrapped_table_name(name) method to assist in determining the correct table name 34 25 35 26 36 ----- … … 28 38 29 39 - Added ability to determine version information for engines: rake engine_info 30 - Added a custom logger for the Engines module, to stop pollution of the Rails 31 logs. 40 - Added a custom logger for the Engines module, to stop pollution of the Rails logs. 32 41 - Added some more tests (in particular, see rails_engines/applications/engines_test). 33 - Another attempt at solving Ticket #53 - controllers and helpers should now 34 be loadable from modules, and if a full path (including 35 RAILS_ROOT/ENGINES_ROOT) is given, it should be safely stripped from the 36 require filename such that corresponding files can be located in any active 37 engines. In other words, controller/helper overloading should now completely 38 work, even if the controllers/helpers are in modules. 42 - Another attempt at solving Ticket #53 - controllers and helpers should now be loadable from modules, and if a full path (including RAILS_ROOT/ENGINES_ROOT) is given, it should be safely stripped from the require filename such that corresponding files can be located in any active engines. In other words, controller/helper overloading should now completely work, even if the controllers/helpers are in modules. 39 43 - Added (finally) patch from Ticket #22 - ActionMailer helpers should now load 40 - Removed support for Engines.start :engine, :engine_name => 'whatever'. It 41 was pointless. 42 - Fixed engine name referencing; engine_stylesheet/engine_javascript can now 43 happily use shorthand engine names (i.e. :test == :test_engine) (Ticket #45) 44 - Fixed minor documentation error ('Engine.start' ==> 'Engines.start') 45 (Ticket #57) 46 - Fixed double inclusion of RAILS_ROOT in engine_migrate rake task 47 (Ticket #61) 44 - Removed support for Engines.start :engine, :engine_name => 'whatever'. It was pointless. 45 - Fixed engine name referencing; engine_stylesheet/engine_javascript can now happily use shorthand engine names (i.e. :test == :test_engine) (Ticket #45) 46 - Fixed minor documentation error ('Engine.start' ==> 'Engines.start') (Ticket #57) 47 - Fixed double inclusion of RAILS_ROOT in engine_migrate rake task (Ticket #61) 48 48 - Added ability to force config values even if given as a hash (Ticket #62) 49 49 plugins/engines/generators/engine/engine_generator.rb
r273 r344 148 148 :insert => @license.to_s 149 149 150 m.complex_template 'init_engine.rb', 150 m.file 'install.erb', File.join('vendor', 'plugins', @engine_underscored_name, 'install.rb') 151 152 m.complex_template 'init_engine.erb', 151 153 File.join('vendor', 'plugins', @engine_underscored_name, 'init_engine.rb'), 152 154 :sandbox => lambda {create_sandbox}, … … 162 164 m.directory File.join('vendor', 'plugins', @engine_underscored_name, 'db', 'migrate') 163 165 m.directory File.join('vendor', 'plugins', @engine_underscored_name, 'lib') 164 m.complex_template File.join('lib', 'engine. rb'),166 m.complex_template File.join('lib', 'engine.erb'), 165 167 File.join('vendor', 'plugins', @engine_underscored_name, 'lib', "#{@engine_underscored_name}.rb"), 166 168 :sandbox => lambda {create_sandbox}, … … 177 179 m.template File.join('tasks', 'engine.rake'), File.join('vendor', 'plugins', @engine_underscored_name, 'tasks', "#{@engine_underscored_name}.rake") 178 180 m.directory File.join('vendor', 'plugins', @engine_underscored_name, 'test') 179 m.template File.join('test', 'test_helper. rb'), File.join('vendor', 'plugins', @engine_underscored_name, 'test', 'test_helper.rb')181 m.template File.join('test', 'test_helper.erb'), File.join('vendor', 'plugins', @engine_underscored_name, 'test', 'test_helper.rb') 180 182 m.directory File.join('vendor', 'plugins', @engine_underscored_name, 'test', 'fixtures') 181 183 m.directory File.join('vendor', 'plugins', @engine_underscored_name, 'test', 'functional') plugins/engines/lib/engines.rb
r308 r344 1 1 require 'logger' 2 2 3 require 'rails_version' # load this before doing ANYTHING freaky with the reloading. 3 # load this before doing ANYTHING freaky with the reloading. 4 begin 5 require 'rails_version' # Rails 1.0, 1.1.0 6 rescue LoadError 7 require 'rails/version' # renamed as of Rails 1.1.1 8 end 9 4 10 require 'engines/ruby_extensions' 5 11 # ... further files are required at the bottom of this file … … 129 135 130 136 # This mechanism is no longer required in Rails trunk 131 if Rails::VERSION::STRING = = "1.0.0"&& !Engines.config(:edge)137 if Rails::VERSION::STRING =~ /^1.0/ && !Engines.config(:edge) 132 138 Controllers.add_path(engine_controllers) if File.exist?(engine_controllers) 133 139 Controllers.add_path(engine_components) if File.exist?(engine_components) … … 136 142 # copy the files unless indicated otherwise 137 143 if options[:copy_files] != false 138 c opy_engine_files(current_engine)144 current_engine.mirror_engine_files 139 145 end 140 146 … … 196 202 end 197 203 198 # Replicates the subdirectories under the engine's /public directory into 199 # the corresponding public directory. 200 def copy_engine_files(engine) 201 202 begin 203 # create the /public/frameworks directory if it doesn't exist 204 public_engine_dir = File.expand_path(File.join(RAILS_ROOT, "public", Engines.config(:public_dir))) 205 206 if !File.exists?(public_engine_dir) 207 # create the public/engines directory, with a warning message in it. 208 Engines.log.debug "Creating public engine files directory '#{public_engine_dir}'" 209 FileUtils.mkdir(public_engine_dir) 210 File.open(File.join(public_engine_dir, "README"), "w") do |f| 211 f.puts <<EOS 204 # Returns the directory in which all engine public assets are mirrored. 205 def public_engine_dir 206 File.expand_path(File.join(RAILS_ROOT, "public", Engines.config(:public_dir))) 207 end 208 209 # create the /public/engine_files directory if it doesn't exist 210 def create_base_public_directory 211 if !File.exists?(public_engine_dir) 212 # create the public/engines directory, with a warning message in it. 213 Engines.log.debug "Creating public engine files directory '#{public_engine_dir}'" 214 FileUtils.mkdir(public_engine_dir) 215 File.open(File.join(public_engine_dir, "README"), "w") do |f| 216 f.puts <<EOS 212 217 Files in this directory are automatically generated from your Rails Engines. 213 218 They are copied from the 'public' directories of each engine into this directory … … 216 221 should edit the files within the <engine_name>/public/ directory itself. 217 222 EOS 218 end 219 end 220 221 source = File.join(engine.root, "public") 222 Engines.log.debug "Attempting to copy public engine files from '#{source}'" 223 224 # if there is no public directory, just return after this file 225 return if !File.exist?(source) 226 227 source_files = Dir[source + "/**/*"] 228 source_dirs = source_files.select { |d| File.directory?(d) } 229 source_files -= source_dirs 230 231 Engines.log.debug "source dirs: #{source_dirs.inspect}" 232 233 # Create the engine_files/<something>_engine dir if it doesn't exist 234 new_engine_dir = File.join(RAILS_ROOT, "public", engine.public_dir) 235 if !File.exists?(new_engine_dir) 236 # Create <something>_engine dir with a message 237 Engines.log.debug "Creating #{engine.public_dir} public dir" 238 FileUtils.mkdir_p(new_engine_dir) 239 end 240 241 # create all the directories, transforming the old path into the new path 242 source_dirs.uniq.each { |dir| 243 begin 244 # strip out the base path and add the result to the public path, i.e. replace 245 # ../script/../vendor/plugins/engine_name/public/javascript 246 # with 247 # engine_name/javascript 248 # 249 relative_dir = dir.gsub(File.join(engine.root, "public"), engine.name) 250 target_dir = File.join(public_engine_dir, relative_dir) 251 unless File.exist?(target_dir) 252 Engines.log.debug "creating directory '#{target_dir}'" 253 FileUtils.mkdir_p(target_dir) 254 end 255 rescue Exception => e 256 raise "Could not create directory #{target_dir}: \n" + e 257 end 258 } 259 260 # copy all the files, transforming the old path into the new path 261 source_files.uniq.each { |file| 262 begin 263 # change the path from the ENGINE ROOT to the public directory root for this engine 264 target = file.gsub(File.join(engine.root, "public"), 265 File.join(public_engine_dir, engine.name)) 266 unless File.exist?(target) && FileUtils.identical?(file, target) 267 Engines.log.debug "copying file '#{file}' to '#{target}'" 268 FileUtils.cp(file, target) 269 end 270 rescue Exception => e 271 raise "Could not copy #{file} to #{target}: \n" + e 272 end 273 } 274 rescue Exception => e 275 Engines.log.warn "WARNING: Couldn't create the engine public file structure for engine '#{engine.name}'; Error follows:" 276 Engines.log.warn e 223 end 277 224 end 278 225 end … … 378 325 File.join("/", Engines.config(:public_dir), name) 379 326 end 327 328 # Replicates the subdirectories under the engine's /public directory into 329 # the corresponding public directory. 330 def mirror_engine_files 331 332 begin 333 Engines.create_base_public_directory 334 335 source = File.join(root, "public") 336 Engines.log.debug "Attempting to copy public engine files from '#{source}'" 337 338 # if there is no public directory, just return after this file 339 return if !File.exist?(source) 340 341 source_files = Dir[source + "/**/*"] 342 source_dirs = source_files.select { |d| File.directory?(d) } 343 source_files -= source_dirs 344 345 Engines.log.debug "source dirs: #{source_dirs.inspect}" 346 347 # Create the engine_files/<something>_engine dir if it doesn't exist 348 new_engine_dir = File.join(RAILS_ROOT, "public", public_dir) 349 if !File.exists?(new_engine_dir) 350 # Create <something>_engine dir with a message 351 Engines.log.debug "Creating #{public_dir} public dir" 352 FileUtils.mkdir_p(new_engine_dir) 353 end 354 355 # create all the directories, transforming the old path into the new path 356 source_dirs.uniq.each { |dir| 357 begin 358 # strip out the base path and add the result to the public path, i.e. replace 359 # ../script/../vendor/plugins/engine_name/public/javascript 360 # with 361 # engine_name/javascript 362 # 363 relative_dir = dir.gsub(File.join(root, "public"), name) 364 target_dir = File.join(Engines.public_engine_dir, relative_dir) 365 unless File.exist?(target_dir) 366 Engines.log.debug "creating directory '#{target_dir}'" 367 FileUtils.mkdir_p(target_dir) 368 end 369 rescue Exception => e 370 raise "Could not create directory #{target_dir}: \n" + e 371 end 372 } 373 374 # copy all the files, transforming the old path into the new path 375 source_files.uniq.each { |file| 376 begin 377 # change the path from the ENGINE ROOT to the public directory root for this engine 378 target = file.gsub(File.join(root, "public"), 379 File.join(Engines.public_engine_dir, name)) 380 unless File.exist?(target) && FileUtils.identical?(file, target) 381 Engines.log.debug "copying file '#{file}' to '#{target}'" 382 FileUtils.cp(file, target) 383 end 384 rescue Exception => e 385 raise "Could not copy #{file} to #{target}: \n" + e 386 end 387 } 388 rescue Exception => e 389 Engines.log.warn "WARNING: Couldn't create the engine public file structure for engine '#{name}'; Error follows:" 390 Engines.log.warn e 391 end 392 end 380 393 end 381 394 plugins/engines/lib/engines/action_mailer_extensions.rb
r304 r344 30 30 # the given action name 31 31 templates.each do |path| 32 type = (File.basename(path).split(".")[1..-2] || []).join("/") 33 #RAILS_DEFAULT_LOGGER.debug "type: #{type}" 34 next if type.empty? 35 #RAILS_DEFAULT_LOGGER.debug "other bit: #{File.basename(path).split(".")[0..-2].join('.')}" 36 @parts << Part.new(:content_type => type, 32 # TODO: don't hardcode rhtml|rxml 33 basename = File.basename(path) 34 next unless md = /^([^\.]+)\.([^\.]+\.[^\+]+)\.(rhtml|rxml)$/.match(basename) 35 36 template_name = basename 37 content_type = md.captures[1].gsub('.', '/') 38 39 @parts << Part.new(:content_type => content_type, 37 40 :disposition => "inline", :charset => charset, 38 :body => render_message( File.basename(path).split(".")[0..-2].join('.'), @body))41 :body => render_message(template_name, @body)) 39 42 end 40 43 unless @parts.empty? 41 44 @content_type = "multipart/alternative" 42 @charset = nil43 45 @parts = sort_parts(@parts, @implicit_parts_order) 44 46 end … … 100 102 seen_names = [] 101 103 template_paths.each { |path| 102 all_templates_for_path = Dir.glob(File.join(path, "#{action} .*"))104 all_templates_for_path = Dir.glob(File.join(path, "#{action}*")) 103 105 all_templates_for_path.each { |template| 104 106 name = File.basename(template) plugins/engines/lib/engines/active_record_extensions.rb
r275 r344 15 15 end 16 16 end 17 18 # Set ActiveRecord to ignore the engine_schema_info table by default 19 ::ActiveRecord::SchemaDumper.ignore_tables << 'engine_schema_info' plugins/engines/lib/engines/dependencies_extensions.rb
r311 r344 25 25 file_name = $1 if file_name =~ /^(.*)\.rb$/ 26 26 27 Engines.log.debug("E DGErequire_or_load: #{file_name}")27 Engines.log.debug("Engines 1.1 require_or_load: #{file_name}") 28 28 29 29 # try and load the engine code first … … 57 57 file_name = $1 if file_name =~ /^(.*)\.rb$/ 58 58 59 Engines.log.debug " 1.0.0 require_or_load for'#{file_name}'"59 Engines.log.debug "Engines 1.0.0 require_or_load '#{file_name}'" 60 60 61 61 # if the file_name ends in "_controller" or "_controller.rb", strip all … … 105 105 106 106 # We only need to deal with LoadingModules in Rails 1.0.0 107 if Rails::VERSION::STRING =~ /^1.0/ 107 if Rails::VERSION::STRING =~ /^1.0/ && !Engines.config(:edge) 108 108 module ::Dependencies 109 109 class RootLoadingModule < LoadingModule plugins/engines/tasks/engines.rake
r304 r344 67 67 puts "Couldn't find an engine called '#{ENV["ENGINE"]}'" 68 68 else 69 if ENV["VERSION"] 69 if ENV["VERSION"] && !ENV["ENGINE"] 70 70 # ignore the VERSION, since it makes no sense in this context; we wouldn't 71 71 # want to revert ALL engines to the same version because of a misttype … … 83 83 puts "Should be: #{migration_directory}" 84 84 end 85 Rake::Task['db:schema:dump'].invoke if ActiveRecord::Base.schema_format == :ruby 85 end 86 if ActiveRecord::Base.schema_format == :ruby && !engines_to_migrate.empty? 87 Rake::Task[:db_schema_dump].invoke 86 88 end 87 89 end … … 140 142 end 141 143 end 144 145 namespace :test do 146 desc "Run the engine tests in vendor/plugins/**/test (or specify with ENGINE=name)" 147 # NOTE: we're using the Rails 1.0 non-namespaced task here, just to maintain 148 # compatibility with Rails 1.0 149 # TODO: make this work with Engines.config(:root) 150 Rake::TestTask.new(:engines => :prepare_test_database) do |t| 151 t.libs << "test" 152 153 if ENV['ENGINE'] 154 t.pattern = "vendor/plugins/#{ENV['ENGINE']}/test/**/*_test.rb" 155 else 156 t.pattern = 'vendor/plugins/**/test/**/*_test.rb' 157 end 158 159 t.verbose = true 160 end 161 end
