/
base.rb
66 lines (52 loc) · 1.81 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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