Skip to content

Commit

Permalink
moved engines support to Cells::Engines.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Feb 6, 2012
1 parent 6102e99 commit 65ca314
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 71 deletions.
3 changes: 0 additions & 3 deletions lib/cell/base.rb
Expand Up @@ -4,7 +4,6 @@
require 'cell/rendering'
require 'cell/rails3_0_strategy' if Cells.rails3_0?
require 'cell/rails3_1_strategy' if Cells.rails3_1_or_more?
require 'cell/engine_integration'

module Cell
class Base < AbstractController::Base
Expand All @@ -18,7 +17,6 @@ class Base < AbstractController::Base
include VersionStrategy
include Rendering
include Caching
include EngineIntegration

class View < ActionView::Base
def render(*args, &block)
Expand All @@ -33,7 +31,6 @@ def render(*args, &block)
# Called in Railtie at initialization time.
def self.setup_view_paths!
self.view_paths = self::DEFAULT_VIEW_PATHS
self.append_engines_to_view_path!
end

def self.controller_path
Expand Down
66 changes: 0 additions & 66 deletions lib/cell/engine_integration.rb

This file was deleted.

3 changes: 2 additions & 1 deletion lib/cells.rb
Expand Up @@ -81,6 +81,7 @@ def self.rails3_1_or_more?
end

require 'cell/rails'
require 'cells/railtie'
require 'cells/rails'
require 'cell/deprecations'
require 'cells/engines'
require 'cells/railtie'
59 changes: 59 additions & 0 deletions lib/cells/engines.rb
@@ -0,0 +1,59 @@
require 'rails/application/railties'

module Cells
# Now <tt>Rails::Engine</tt>s 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 <tt>'app/cell_views'</tt> 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
# Appends all <tt>Rails::Engine</tt>s cell-views path to Cell::Base#view_paths
#
# All <tt>Rails::Engine</tt>s specified at <tt>config.view_path_engines</tt> will have its cell-views path appended to Cell::Base#view_paths
#
# Defaults <tt>config.view_path_engines</tt> to all loaded <tt>Rails::Engine</tt>s.
#
def self.append_engines_view_paths_for(config)
return if config.view_path_engines == false

engines = config.view_path_engines || ::Rails::Application::Railties.engines
engines.each {|engine| append_engine_view_path!(engine) }
end

# Appends a <tt>Rails::Engine</tt> cell-views path to @Cell::Base@
#
# The <tt>Rails::Engine</tt> cell-views path is obtained from the <tt>paths['app/cell_views']</tt> configuration.
# All existing directories specified at cell-views path will be appended do Cell::Base#view_paths
#
# Defaults <tt>paths['app/cell_views']</tt> 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(engine.paths["app/cell_views"].existent_directories)
end
end
end
6 changes: 5 additions & 1 deletion lib/cells/railtie.rb
@@ -1,7 +1,7 @@
require "rails/railtie"

module Cells
class Railtie < Rails::Railtie
class Railtie < ::Rails::Railtie
initializer "cells.attach_router" do |app|
Cell::Base.class_eval do
include app.routes.url_helpers
Expand All @@ -12,6 +12,10 @@ class Railtie < Rails::Railtie
Cell::Base.setup_view_paths!
end

initializer "cells.setup_engines_view_paths" do |app|
Cells::Engines.append_engines_view_paths_for(app.config.action_controller)
end

rake_tasks do
load "cells/cells.rake"
end
Expand Down

0 comments on commit 65ca314

Please sign in to comment.