Changeset 344

Show
Ignore:
Timestamp:
04/06/06 16:16:01 (3 years ago)
Author:
lazyatom
Message:

Releasing Engines plugin 1.1.1 to the public

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/engines/CHANGELOG

    r307 r344  
    11*SVN* 
    22 
     3----- 
     41.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----- 
     181.1.0 
     19 
    320- 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) 
    923- Clarified MIT license (Ticket #98) 
    1024- Updated Rake tasks to integrate smoothly with Rails 1.1 namespaces 
    1125- Changed the version to "1.1.0 (svn)" 
    1226- 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: 
    1829    Engines.config :edge, true 
    1930  to your environment.rb file. 
    2031- 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 
    2535 
    2636----- 
     
    2838 
    2939- 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. 
    3241- 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. 
    3943- 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) 
    4848- Added ability to force config values even if given as a hash (Ticket #62) 
    4949 
  • plugins/engines/generators/engine/engine_generator.rb

    r273 r344  
    148148        :insert => @license.to_s 
    149149 
    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', 
    151153        File.join('vendor', 'plugins', @engine_underscored_name, 'init_engine.rb'), 
    152154        :sandbox => lambda {create_sandbox}, 
     
    162164      m.directory File.join('vendor', 'plugins', @engine_underscored_name, 'db', 'migrate') 
    163165      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'), 
    165167        File.join('vendor', 'plugins', @engine_underscored_name, 'lib', "#{@engine_underscored_name}.rb"), 
    166168        :sandbox => lambda {create_sandbox}, 
     
    177179      m.template File.join('tasks', 'engine.rake'), File.join('vendor', 'plugins', @engine_underscored_name, 'tasks', "#{@engine_underscored_name}.rake") 
    178180      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') 
    180182      m.directory File.join('vendor', 'plugins', @engine_underscored_name, 'test', 'fixtures') 
    181183      m.directory File.join('vendor', 'plugins', @engine_underscored_name, 'test', 'functional') 
  • plugins/engines/lib/engines.rb

    r308 r344  
    11require 'logger' 
    22 
    3 require 'rails_version' # load this before doing ANYTHING freaky with the reloading. 
     3 # load this before doing ANYTHING freaky with the reloading. 
     4begin 
     5  require 'rails_version' # Rails 1.0, 1.1.0 
     6rescue LoadError 
     7  require 'rails/version' # renamed as of Rails 1.1.1 
     8end 
     9 
    410require 'engines/ruby_extensions' 
    511# ... further files are required at the bottom of this file 
     
    129135 
    130136      # 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) 
    132138        Controllers.add_path(engine_controllers) if File.exist?(engine_controllers) 
    133139        Controllers.add_path(engine_components) if File.exist?(engine_components) 
     
    136142      # copy the files unless indicated otherwise 
    137143      if options[:copy_files] != false 
    138         copy_engine_files(current_engine) 
     144        current_engine.mirror_engine_files 
    139145      end 
    140146 
     
    196202    end 
    197203 
    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 
    212217Files in this directory are automatically generated from your Rails Engines. 
    213218They are copied from the 'public' directories of each engine into this directory 
     
    216221should edit the files within the <engine_name>/public/ directory itself. 
    217222EOS 
    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 
    277224      end 
    278225    end 
     
    378325    File.join("/", Engines.config(:public_dir), name) 
    379326  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   
    380393end 
    381394 
  • plugins/engines/lib/engines/action_mailer_extensions.rb

    r304 r344  
    3030          # the given action name 
    3131          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,             
    3740              :disposition => "inline", :charset => charset, 
    38               :body => render_message(File.basename(path).split(".")[0..-2].join('.'), @body)) 
     41              :body => render_message(template_name, @body)) 
    3942          end 
    4043          unless @parts.empty? 
    4144            @content_type = "multipart/alternative" 
    42             @charset = nil 
    4345            @parts = sort_parts(@parts, @implicit_parts_order) 
    4446          end 
     
    100102        seen_names = [] 
    101103        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}*")) 
    103105          all_templates_for_path.each { |template| 
    104106            name = File.basename(template) 
  • plugins/engines/lib/engines/active_record_extensions.rb

    r275 r344  
    1515  end 
    1616end 
     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  
    2525    file_name = $1 if file_name =~ /^(.*)\.rb$/ 
    2626     
    27     Engines.log.debug("EDGE require_or_load: #{file_name}") 
     27    Engines.log.debug("Engines 1.1 require_or_load: #{file_name}") 
    2828 
    2929    # try and load the engine code first 
     
    5757    file_name = $1 if file_name =~ /^(.*)\.rb$/ 
    5858 
    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}'" 
    6060 
    6161    # if the file_name ends in "_controller" or "_controller.rb", strip all 
     
    105105 
    106106# We only need to deal with LoadingModules in Rails 1.0.0 
    107 if Rails::VERSION::STRING =~ /^1.0/ 
     107if Rails::VERSION::STRING =~ /^1.0/ && !Engines.config(:edge) 
    108108  module ::Dependencies 
    109109    class RootLoadingModule < LoadingModule 
  • plugins/engines/tasks/engines.rake

    r304 r344  
    6767        puts "Couldn't find an engine called '#{ENV["ENGINE"]}'" 
    6868      else 
    69         if ENV["VERSION"] 
     69        if ENV["VERSION"] && !ENV["ENGINE"] 
    7070          # ignore the VERSION, since it makes no sense in this context; we wouldn't 
    7171          # want to revert ALL engines to the same version because of a misttype 
     
    8383              puts "Should be: #{migration_directory}" 
    8484            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 
    8688          end 
    8789        end 
     
    140142  end 
    141143end 
     144 
     145namespace :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   
     161end