Sha256: 3e0d9e22cff25ba5f43d8a6624d3911a46cbc8fa3aef0a465db2b3a5686c364e

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'abstract_controller'
require 'cell/builder'
require 'cell/caching'
require 'cell/rendering'

module Cell
  def self.rails3_0?
    ::ActionPack::VERSION::MINOR == 0
  end
  
  def self.rails3_1_or_more?
    ::ActionPack::VERSION::MINOR >= 1
  end
  
  def self.rails3_2_or_more?  # FIXME: move to tests.
    ::ActionPack::VERSION::MINOR >= 2
  end
  
  
  class Base < AbstractController::Base
    abstract!
    DEFAULT_VIEW_PATHS = [File.join('app', 'cells')]
    
    extend Builder
    include AbstractController
    include AbstractController::Rendering, Layouts, Helpers, Callbacks, Translation, Logger
    
    require 'cell/rails3_0_strategy' if Cell.rails3_0?
    require 'cell/rails3_1_strategy' if Cell.rails3_1_or_more?
    include VersionStrategy
    include Rendering
    include Caching
    
    class View < ActionView::Base
      def self.prepare(modules)
        # TODO: remove for 4.0 if PR https://github.com/rails/rails/pull/6826 is merged.
        Class.new(self) do  # DISCUSS: why are we mixing that stuff into this _anonymous_ class at all? that makes things super complicated.
          include *modules.reverse
        end
      end
      
      def render(*args, &block)
        options = args.first.is_a?(::Hash) ? args.first : {}  # this is copied from #render by intention.
        
        return controller.render(*args, &block) if options[:state] or options[:view]
        super
      end
    end
    
    
    def self.view_context_class
      @view_context_class ||= begin
        Cell::Base::View.prepare(helper_modules)
      end
    end
      
    # Called in Railtie at initialization time.
    def self.setup_view_paths!
      self.view_paths = self::DEFAULT_VIEW_PATHS
    end
    
    def self.controller_path
      @controller_path ||= name.sub(/Cell$/, '').underscore unless anonymous?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cells-3.8.6 lib/cell/base.rb