Changeset 691

Show
Ignore:
Timestamp:
01/08/08 09:49:18 (6 months ago)
Author:
jlong
Message:

rails2: ActionController::Base.view_paths is now set correctly for extensions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/rails2/lib/plugins/extension_patches/lib/mailer_view_paths_extension.rb

    r555 r691  
    2121        return full_path unless Dir["#{full_path}.*"].empty? 
    2222      end 
     23      nil 
    2324    end 
    2425     
    2526    def create_with_view_paths!(method_name, *parameters) #:nodoc: 
    2627      initialize_defaults(method_name) 
    27       send(method_name, *parameters) 
     28      __send__(method_name, *parameters) 
    2829 
    2930      # If an explicit, textual body has not been set, we check assumptions. 
     
    3132        # First, we look to see if there are any likely templates that match, 
    3233        # which include the content-type in their file name (i.e., 
    33         # "the_template_file.text.html.rhtml", etc.). Only do this if parts 
     34        # "the_template_file.text.html.erb", etc.). Only do this if parts 
    3435        # have not already been specified manually. 
    3536        if @parts.empty? 
     
    3940          # JWL: end modifications 
    4041          templates.each do |path| 
    41             # TODO: don't hardcode rhtml|rxml 
    4242            basename = File.basename(path) 
    43             next unless md = /^([^\.]+)\.([^\.]+\.[^\+]+)\.(rhtml|rxml)$/.match(basename) 
     43            template_regex = Regexp.new("^([^\\\.]+)\\\.([^\\\.]+\\\.[^\\\.]+)\\\.(" + template_extensions.join('|') + ")$") 
     44            next unless md = template_regex.match(basename) 
    4445            template_name = basename 
    4546            content_type = md.captures[1].gsub('.', '/') 
    46             @parts << ActionMailer::Part.new(:content_type => content_type, 
     47            @parts << Part.new(:content_type => content_type, 
    4748              :disposition => "inline", :charset => charset, 
    4849              :body => render_message(template_name, @body)) 
     
    6667        # that create_mail doesn't try to render it in addition to the parts). 
    6768        if !@parts.empty? && String === @body 
    68           @parts.unshift ActionMailer::Part.new(:charset => charset, :body => @body) 
     69          @parts.unshift Part.new(:charset => charset, :body => @body) 
    6970          @body = nil 
    7071        end 
  • branches/rails2/lib/radiant/extension_loader.rb

    r682 r691  
    4242      load_extension_roots.each do |ext_path| 
    4343        configuration.load_paths.concat load_paths_for(ext_path)         
     44        # TODO: use Dependencies.load_paths instead of $LOAD_PATH 
    4445        $LOAD_PATH.concat load_paths_for(ext_path) 
    4546        configuration.controller_paths << "#{ext_path}/app/controllers" 
    46         ActionController::Base.view_paths << "#{ext_path}/app/views" 
     47        configuration.view_paths << "#{ext_path}/app/views" 
    4748        @extension_roots << ext_path 
    4849      end 
     
    9495        extension if enabled 
    9596      end 
    96  
     97       
    9798      def load_paths_for(ext_path) 
    9899        load_paths = %w(lib app/models app/controllers app/helpers test/helpers).collect { |p| "#{ext_path}/#{p}" } 
    99100        load_paths << ext_path           
    100101      end 
    101  
     102       
    102103      def load_extension_roots 
    103104        @load_extension_roots ||= configuration.extensions ? select_extension_roots : all_extension_roots 
     
    122123        end.flatten 
    123124      end 
    124  
     125       
    125126      def all_extension_roots 
    126127        @all_extension_roots ||= configuration.extension_paths.map do |path| 
  • branches/rails2/lib/radiant/initializer.rb

    r682 r691  
    77    attr_accessor :extension_paths 
    88    attr_accessor :extensions 
     9    attr_accessor :view_paths 
    910     
    1011    def initialize 
     12      self.view_paths = [] 
    1113      self.extension_paths = default_extension_paths 
    1214      self.extensions = nil 
     
    3133    def after_initialize 
    3234      initialize_extensions 
     35      initialize_framework_views 
    3336      super 
    3437    end 
     
    3740      ActiveRecord::Base.connection.execute("select count(*) from #{ExtensionMeta.table_name}") 
    3841    rescue 
    39       $stderr.puts "Extensions cannot be used until Radiant migrations are up to date." 
     42      $stderr.puts "Extensions cannot be used until Radiant migrations are updated." 
    4043    else 
    4144      require 'radiant/extension_loader' 
     
    5053    end 
    5154     
     55    def initialize_framework_views 
     56      view_path = configuration.view_path 
     57      configuration.view_paths << view_path if view_path and not configuration.view_paths.include?(view_path) 
     58      view_paths = configuration.view_paths.reverse 
     59      ActionMailer::Base.view_paths = view_paths if configuration.frameworks.include?(:action_mailer) 
     60      ActionController::Base.view_paths = view_paths if configuration.frameworks.include?(:action_controller) 
     61    end 
     62     
    5263    def admin 
    5364      configuration.admin 
  • branches/rails2/test/functional/extension_initialization_test.rb

    r542 r691  
    3838    Dependencies.clear 
    3939    Dependencies.explicitly_unloadable_constants = old_list 
    40  
     40     
    4141    assert_basic_extension_annotations 
    4242    assert_view_paths 
    4343    assert_admin_tabs "Basic Extension Tab" 
    44  
    4544  end 
    4645   
     
    6665    assert_basic_extension_annotations 
    6766  end 
    68  
     67   
    6968  def test_should_load_plugin_from_vendor_plugin 
    7069    assert_nothing_raised { Radiant::Extension.const_get(:PLUGIN_PLUGIN_NORMAL) } 
     
    8887    assert !Dependencies.load_once_paths.include?(OverridingExtension.root + "/vendor/plugins/multiple/lib")     
    8988  end 
    90  
     89   
    9190  def test_should_add_extension_load_paths_to_requirable_load_path 
    9291    assert_nothing_raised { require 'new_module' } 
     
    9796   
    9897    def assert_admin_tabs(more_tabs = []) 
    99       tabnames = [] 
     98      tab_names = [] 
    10099      Radiant::AdminUI.tabs.each do |tab| 
    101         assert "Duplicate Tab", !tabnames.include?(tab.name) 
    102         tabnames << tab.name 
     100        assert !tab_names.include?(tab.name), "duplicate tab #{tab.name.inspect}" 
     101        tab_names << tab.name 
    103102      end 
    104       more_tabs.each do |tabname| 
    105         assert Radiant::AdminUI.tabs.any? {|tab| tab.name == tabname } 
     103      more_tabs.each do |tab_name| 
     104        assert Radiant::AdminUI.tabs.any? {|tab| tab.name == tab_name } 
    106105      end 
    107106    end 
     
    112111      assert_equal "http://test.com", BasicExtension.url 
    113112    end 
    114    
    115     def assert_view_paths(expected = {}, message = nil) 
    116       expected.reverse_merge!({ 
     113     
     114    def assert_view_paths(expected_messages = {}, message = nil) 
     115      expected_messages.reverse_merge!( 
    117116        :index    => /Hello, Extension World/, 
    118117        :override => /Hello, Overridden Extension World/, 
    119         :routing  => /You're routing works/, 
    120       }
    121          
     118        :routing  => /You're routing works/ 
     119     
     120       
    122121      @controller = BasicExtensionController.new 
    123122      @request    = ActionController::TestRequest.new 
     
    126125      [:index, :override, :routing].each do |action| 
    127126        get action 
    128         assert_match expected[action], @response.body, message 
     127        assert_match expected_messages[action], @response.body, message 
    129128      end 
    130129    end