require 'rails/application/railties' module Cells # Now Rails::Engines can contribute to Cells view paths. # By default, any 'app/cells' found inside any Engine is automatically included into Cells view paths. # # You can customize the view paths changing/appending to the 'app/cell_views' path configuration: # # module MyAwesome # class Engine < Rails::Engine # # loads views from 'cell/views' and NOT from 'app/cells' # config.paths.add 'app/cell_views', :with => 'cell/views' # # # appends 'lib/my_cells_view_path' to this Railtie view path contribution # config.paths['app/cell_views'] << 'lib/my_cells_view_path' # end # end # # You can manually specify which Engines will be added to Cell view paths # # Cell::Base.config.view_path_engines = [MyAwesome::Engine] # # And even disable the automatic loading # # Cell::Base.config.view_path_engines = false # # You can programatically append a Rails::Engine to Cell view path # # Cells.setup do |config| # config.append_engine_view_path!(MyEngine::Engine) # end # module Engines extend VersionStrategy # adds #registered_engines and #existent_directories_for. # Appends all Rails::Engines cell-views path to Cell::Base#view_paths # # All Rails::Engines specified at config.view_path_engines will have its cell-views path appended to Cell::Base#view_paths # # Defaults config.view_path_engines to all loaded Rails::Engines. # def self.append_engines_view_paths_for(config) return if config.view_path_engines == false engines = config.view_path_engines || registered_engines #::Rails::Application::Railties.engines engines.each {|engine| append_engine_view_path!(engine) } end # Appends a Rails::Engine cell-views path to @Cell::Base@ # # The Rails::Engine cell-views path is obtained from the paths['app/cell_views'] configuration. # All existing directories specified at cell-views path will be appended do Cell::Base#view_paths # # Defaults paths['app/cell_views'] to 'app/cells' # def self.append_engine_view_path!(engine) engine.paths['app/cell_views'] || engine.paths.add('app/cell_views', :with => 'app/cells') Cell::Rails.append_view_path(existent_directories_for(engine.paths["app/cell_views"])) end end end