Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moved engines support to Cells::Engines.

  • Loading branch information...
commit 65ca314163138d9e45b4ecc07ce3cb15fbd46de9 1 parent 6102e99
@apotonick apotonick authored
View
3  lib/cell/base.rb
@@ -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
@@ -18,7 +17,6 @@ class Base < AbstractController::Base
include VersionStrategy
include Rendering
include Caching
- include EngineIntegration
class View < ActionView::Base
def render(*args, &block)
@@ -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
View
66 lib/cell/engine_integration.rb
@@ -1,66 +0,0 @@
-require 'active_support/concern'
-require 'rails/application/railties'
-
-module Cell
- # 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 EngineIntegration
- extend ActiveSupport::Concern
-
- module ClassMethods
-
- # 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 append_engines_to_view_path!
- return if config.view_path_engines == false
-
- engines = config.view_path_engines || ::Rails::Application::Railties.engines
- engines.each {|engine| self.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 append_engine_view_path!(engine)
- engine.paths['app/cell_views'] || engine.paths.add('app/cell_views', :with => 'app/cells')
- append_view_path engine.paths["app/cell_views"].existent_directories
- end
-
- end
- end
-end
View
3  lib/cells.rb
@@ -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'
View
59 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
View
6 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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.