cells 3.11.3 → 4.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +15 -13
- data/Appraisals +23 -0
- data/CHANGES.md +20 -3
- data/Gemfile +5 -7
- data/README.md +317 -236
- data/Rakefile +1 -1
- data/TODO.md +3 -0
- data/cells.gemspec +19 -28
- data/gemfiles/rails3.2.gemfile +14 -0
- data/gemfiles/rails4.0.gemfile +14 -0
- data/gemfiles/rails4.1.gemfile +15 -0
- data/gemfiles/rails4.2.gemfile +14 -0
- data/lib/cell.rb +28 -21
- data/lib/cell/caching.rb +10 -22
- data/lib/cell/caching/notification.rb +15 -0
- data/lib/cell/concept.rb +4 -69
- data/lib/cell/development.rb +11 -0
- data/lib/{cells → cell}/engines.rb +1 -1
- data/lib/cell/layout.rb +20 -0
- data/lib/cell/partial.rb +17 -0
- data/lib/cell/{base/prefixes.rb → prefixes.rb} +1 -1
- data/lib/cell/rails.rb +58 -50
- data/lib/cell/railtie.rb +60 -0
- data/lib/cell/{base/self_contained.rb → self_contained.rb} +1 -1
- data/lib/cell/templates.rb +60 -0
- data/lib/cell/test_case.rb +4 -162
- data/lib/cell/testing.rb +15 -0
- data/lib/cell/twin.rb +11 -29
- data/lib/cell/version.rb +10 -0
- data/lib/cell/view_model.rb +196 -88
- data/lib/cells.rb +1 -20
- data/lib/rails/generators/cell/cell_generator.rb +43 -0
- data/lib/rails/generators/cell/templates/cell.rb.erb +8 -0
- data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.erb +0 -0
- data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.haml +0 -0
- data/lib/rails/generators/cell/templates/view.slim +2 -0
- data/lib/rails/generators/concept/concept_generator.rb +38 -0
- data/lib/{generators/templates/concept/cell.rb → rails/generators/concept/templates/concept.rb.erb} +2 -2
- data/lib/{generators → rails/generators/concept}/templates/view.erb +0 -0
- data/lib/{generators → rails/generators/concept}/templates/view.haml +0 -0
- data/lib/rails/generators/concept/templates/view.slim +2 -0
- data/lib/rails/generators/test_unit/cell/cell_generator.rb +21 -0
- data/lib/{generators/templates/cell_test.rb → rails/generators/test_unit/cell/templates/unit_test.rb.erb} +3 -3
- data/lib/rails/generators/test_unit/concept/concept_generator.rb +21 -0
- data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +11 -0
- data/lib/{cells → tasks}/cells.rake +0 -0
- data/test/builder_test.rb +58 -0
- data/test/caching_test.rb +298 -0
- data/test/cell_benchmark.rb +32 -0
- data/test/cell_generator_test.rb +51 -82
- data/test/cell_test.rb +8 -23
- data/test/concept_generator_test.rb +22 -13
- data/test/concept_test.rb +41 -75
- data/test/dummy/app/views/musician/hamlet.html.erb +1 -0
- data/test/dummy/config/application.rb +21 -8
- data/test/{app/cells/bassist/play.html.erb → fixtures/bassist/play.erb} +0 -0
- data/test/fixtures/concepts/record/views/layout.erb +1 -0
- data/test/{app → fixtures}/concepts/record/views/show.erb +0 -0
- data/test/{app → fixtures}/concepts/record/views/song.erb +0 -0
- data/test/fixtures/inherit_views_test/popper/tap.erb +1 -0
- data/test/fixtures/inherit_views_test/tapper/play.erb +1 -0
- data/test/fixtures/inherit_views_test/tapper/tap.erb +1 -0
- data/test/fixtures/partial_test/with_partial/show.erb +1 -0
- data/test/fixtures/partials/_show.html.erb +1 -0
- data/test/fixtures/partials/_show.xml.erb +1 -0
- data/test/fixtures/song/ivar.erb +1 -0
- data/test/fixtures/song/show.erb +1 -0
- data/test/fixtures/song/with_erb.erb +4 -0
- data/test/fixtures/song/with_html.erb +1 -0
- data/test/fixtures/song/with_locals.erb +2 -0
- data/test/fixtures/song_with_layout/happy.erb +1 -0
- data/test/fixtures/song_with_layout/merry.erb +1 -0
- data/test/fixtures/song_with_layout/show.erb +1 -0
- data/test/fixtures/song_with_layout/show_with_layout.erb +1 -0
- data/test/fixtures/templates_caching_test/song/show.erb +1 -0
- data/test/fixtures/url_helper_test/song/edit.erb +8 -0
- data/test/fixtures/url_helper_test/song/with_block.erb +2 -0
- data/test/fixtures/url_helper_test/song/with_capture.erb +4 -0
- data/test/fixtures/url_helper_test/song/with_content_tag.erb +6 -0
- data/test/fixtures/url_helper_test/song/with_form_for_block.erb +3 -0
- data/test/fixtures/url_helper_test/song/with_link_to.erb +3 -0
- data/test/layout_test.rb +57 -0
- data/test/partial_test.rb +27 -0
- data/test/prefixes_test.rb +36 -10
- data/test/public_test.rb +42 -0
- data/test/rails_extensions_test.rb +51 -0
- data/test/render_test.rb +103 -0
- data/test/templates_test.rb +45 -0
- data/test/test_case_test.rb +21 -122
- data/test/test_helper.rb +37 -33
- data/test/twin_test.rb +3 -7
- data/test/url_helper_test.rb +89 -0
- metadata +92 -357
- data/gemfiles/Gemfile.rails3-0 +0 -7
- data/gemfiles/Gemfile.rails3-1 +0 -7
- data/gemfiles/Gemfile.rails3-2 +0 -7
- data/gemfiles/Gemfile.rails4-0 +0 -12
- data/gemfiles/Gemfile.rails4-1 +0 -12
- data/lib/cell/base.rb +0 -82
- data/lib/cell/base/view.rb +0 -15
- data/lib/cell/builder.rb +0 -71
- data/lib/cell/deprecations.rb +0 -41
- data/lib/cell/dsl.rb +0 -7
- data/lib/cell/rack.rb +0 -32
- data/lib/cell/rails/helper_api.rb +0 -37
- data/lib/cell/rails/view_model.rb +0 -159
- data/lib/cell/rails3_0_strategy.rb +0 -82
- data/lib/cell/rails3_1_strategy.rb +0 -40
- data/lib/cell/rails4_0_strategy.rb +0 -39
- data/lib/cell/rails4_1_strategy.rb +0 -40
- data/lib/cell/rendering.rb +0 -109
- data/lib/cells/rails.rb +0 -86
- data/lib/cells/railtie.rb +0 -38
- data/lib/cells/version.rb +0 -3
- data/lib/generators/USAGE +0 -30
- data/lib/generators/cells/base.rb +0 -22
- data/lib/generators/cells/cell_generator.rb +0 -15
- data/lib/generators/cells/view_generator.rb +0 -18
- data/lib/generators/erb/cell_generator.rb +0 -15
- data/lib/generators/erb/concept_generator.rb +0 -17
- data/lib/generators/haml/cell_generator.rb +0 -17
- data/lib/generators/haml/concept_generator.rb +0 -17
- data/lib/generators/rails/cell_generator.rb +0 -16
- data/lib/generators/rails/concept_generator.rb +0 -16
- data/lib/generators/slim/cell_generator.rb +0 -17
- data/lib/generators/templates/cell.rb +0 -9
- data/lib/generators/templates/view.slim +0 -4
- data/lib/generators/test_unit/cell_generator.rb +0 -14
- data/lib/generators/trailblazer/base.rb +0 -21
- data/lib/generators/trailblazer/view_generator.rb +0 -18
- data/test/app/cells/album/views/cover.haml +0 -1
- data/test/app/cells/bad_guitarist/_dii.html.erb +0 -1
- data/test/app/cells/bad_guitarist_cell.rb +0 -2
- data/test/app/cells/bassist/_dii.html.erb +0 -1
- data/test/app/cells/bassist/ahem.html.erb +0 -1
- data/test/app/cells/bassist/compose.html.erb +0 -1
- data/test/app/cells/bassist/contact_form.html.erb +0 -1
- data/test/app/cells/bassist/form_for.erb +0 -3
- data/test/app/cells/bassist/form_for_in_haml.haml +0 -2
- data/test/app/cells/bassist/jam.html.erb +0 -3
- data/test/app/cells/bassist/play.js.erb +0 -1
- data/test/app/cells/bassist/pose.html.erb +0 -1
- data/test/app/cells/bassist/promote.html.erb +0 -1
- data/test/app/cells/bassist/provoke.html.erb +0 -1
- data/test/app/cells/bassist/shout.html.erb +0 -1
- data/test/app/cells/bassist/sing.html.haml +0 -1
- data/test/app/cells/bassist/slap.html.erb +0 -1
- data/test/app/cells/bassist/yell.en.html.erb +0 -1
- data/test/app/cells/bassist_cell.rb +0 -25
- data/test/app/cells/club_security.rb +0 -2
- data/test/app/cells/club_security/guard/help.html.erb +0 -1
- data/test/app/cells/club_security/guard_cell.rb +0 -6
- data/test/app/cells/club_security/medic/help.html.erb +0 -1
- data/test/app/cells/club_security/medic_cell.rb +0 -8
- data/test/app/cells/layouts/b.erb +0 -1
- data/test/app/cells/layouts/metal.html.erb +0 -1
- data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +0 -5
- data/test/app/cells/shouter/sing.html.erb +0 -1
- data/test/app/cells/song/dashboard.haml +0 -7
- data/test/app/cells/song/details.html.haml +0 -1
- data/test/app/cells/song/info.html.haml +0 -1
- data/test/app/cells/song/lyrics.html.haml +0 -6
- data/test/app/cells/song/plays.haml +0 -1
- data/test/app/cells/song/scale.haml +0 -1
- data/test/app/cells/song/show.html.haml +0 -3
- data/test/app/cells/song/title.html.haml +0 -1
- data/test/app/cells/trumpeter/promote.html.erb +0 -1
- data/test/app/cells/trumpeter_cell.rb +0 -8
- data/test/app/cells/view_model_test/comments/show.haml +0 -7
- data/test/app/concepts/record/views/layout.haml +0 -2
- data/test/app/views/shared/_dong.html.erb +0 -1
- data/test/cell_module_test.rb +0 -170
- data/test/cells_module_test.rb +0 -27
- data/test/deprecations_test.rb +0 -101
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/musician/hamlet.html.haml +0 -1
- data/test/dummy/config/environments/development.rb +0 -16
- data/test/dummy/config/environments/production.rb +0 -46
- data/test/dummy/config/environments/test.rb +0 -33
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/label/app/cells/label/show.erb +0 -1
- data/test/dummy/label/app/cells/label_cell.rb +0 -5
- data/test/dummy/label/label.gemspec +0 -20
- data/test/dummy/label/lib/label.rb +0 -4
- data/test/dummy/label/lib/label/version.rb +0 -3
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/helper_test.rb +0 -81
- data/test/rack_test.rb +0 -32
- data/test/rails/asset_pipeline_test.rb +0 -20
- data/test/rails/caching_test.rb +0 -456
- data/test/rails/cells_test.rb +0 -119
- data/test/rails/forms_test.rb +0 -75
- data/test/rails/integration_test.rb +0 -299
- data/test/rails/render_test.rb +0 -189
- data/test/rails/view_model_test.rb +0 -226
- data/test/rails/view_test.rb +0 -49
- data/test/rails_helper_api_test.rb +0 -58
- data/test/self_contained_test.rb +0 -31
data/gemfiles/Gemfile.rails3-0
DELETED
data/gemfiles/Gemfile.rails3-1
DELETED
data/gemfiles/Gemfile.rails3-2
DELETED
data/gemfiles/Gemfile.rails4-0
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in cells.gemspec
|
4
|
-
gemspec path: '../'
|
5
|
-
|
6
|
-
gem 'railties', '4.0.2'
|
7
|
-
gem 'activemodel', '4.0.2'
|
8
|
-
gem 'minitest', '4.7.5'
|
9
|
-
gem 'sprockets', '~> 2.1'
|
10
|
-
gem 'sprockets-rails', '~> 2.1.3', :require => 'sprockets/railtie'
|
11
|
-
|
12
|
-
gem 'label', :path => "../test/dummy/label"
|
data/gemfiles/Gemfile.rails4-1
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in cells.gemspec
|
4
|
-
gemspec path: '../'
|
5
|
-
|
6
|
-
gem 'railties', '4.1.1'
|
7
|
-
gem 'activemodel', '4.1.1'
|
8
|
-
gem 'minitest', '5.2.0'
|
9
|
-
gem 'sprockets', '~> 2.1'
|
10
|
-
gem 'sprockets-rails', '~> 2.1.3', :require => 'sprockets/railtie'
|
11
|
-
|
12
|
-
gem 'label', :path => "../test/dummy/label", :require => 'label'
|
data/lib/cell/base.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'abstract_controller'
|
2
|
-
require 'cell/builder'
|
3
|
-
require 'cell/caching'
|
4
|
-
require 'cell/rendering'
|
5
|
-
require 'cell/dsl'
|
6
|
-
|
7
|
-
module Cell
|
8
|
-
require 'uber/version'
|
9
|
-
def self.rails_version
|
10
|
-
Uber::Version.new(::ActionPack::VERSION::STRING)
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
class Base < AbstractController::Base
|
15
|
-
# TODO: deprecate Base in favour of Cell.
|
16
|
-
abstract!
|
17
|
-
|
18
|
-
include AbstractController
|
19
|
-
include AbstractController::Rendering, Helpers, Callbacks, Translation, Logger
|
20
|
-
|
21
|
-
self.view_paths = "app/cells"
|
22
|
-
|
23
|
-
|
24
|
-
require 'cell/rails3_0_strategy' if Cell.rails_version.~ "3.0"
|
25
|
-
require 'cell/rails3_1_strategy' if Cell.rails_version.~( "3.1", "3.2")
|
26
|
-
require 'cell/rails4_0_strategy' if Cell.rails_version.~ "4.0"
|
27
|
-
require 'cell/rails4_1_strategy' if Cell.rails_version >= "4.1"
|
28
|
-
include VersionStrategy
|
29
|
-
include Layouts
|
30
|
-
include Rendering
|
31
|
-
include Caching
|
32
|
-
include Cell::DSL
|
33
|
-
|
34
|
-
extend Builder::ClassMethods # ::build DSL method and ::builders.
|
35
|
-
|
36
|
-
|
37
|
-
def initialize(*args)
|
38
|
-
super() # AbC::Base.
|
39
|
-
process_args(*args)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.class_from_cell_name(name)
|
43
|
-
"#{name}_cell".classify.constantize
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
class << self
|
48
|
-
# Main entry point for instantiating cells.
|
49
|
-
def cell_for(name, *args)
|
50
|
-
Builder.new(class_from_cell_name(name), self).call(*args)
|
51
|
-
end
|
52
|
-
|
53
|
-
alias_method :create_cell_for, :cell_for # TODO: remove us in 3.12.
|
54
|
-
ActiveSupport::Deprecation.deprecate_methods(self, :create_cell_for => :cell_for)
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
def process_args(*)
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
def self.view_context_class # DISCUSS: this is only needed for non-vm cells.
|
63
|
-
@view_context_class ||= begin
|
64
|
-
Cell::Base::View.prepare(helper_modules)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.controller_path
|
69
|
-
@controller_path ||= name.sub(/Cell$/, '').underscore unless anonymous?
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
require 'cell/base/view'
|
74
|
-
require 'cell/base/prefixes'
|
75
|
-
include Prefixes
|
76
|
-
require 'cell/base/self_contained'
|
77
|
-
extend SelfContained
|
78
|
-
end
|
79
|
-
|
80
|
-
autoload :ViewModel, 'cell/view_model'
|
81
|
-
autoload :Concept, 'cell/concept'
|
82
|
-
end
|
data/lib/cell/base/view.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
class Cell::Base::View < ActionView::Base
|
2
|
-
def self.prepare(modules)
|
3
|
-
# TODO: remove for 4.0 if PR https://github.com/rails/rails/pull/6826 is merged.
|
4
|
-
Class.new(self) do # DISCUSS: why are we mixing that stuff into this _anonymous_ class at all? that makes things super complicated.
|
5
|
-
include *modules.reverse
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def render(*args, &block)
|
10
|
-
options = args.first.is_a?(::Hash) ? args.first : {} # this is copied from #render by intention.
|
11
|
-
|
12
|
-
return controller.render(*args, &block) if options[:state] or options[:view]
|
13
|
-
super
|
14
|
-
end
|
15
|
-
end
|
data/lib/cell/builder.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
module Cell
|
2
|
-
# Contains all methods for dynamically building a cell instance by using decider blocks.
|
3
|
-
#
|
4
|
-
# Design notes:
|
5
|
-
# * totally generic, doesn't know about parent_controller etc.
|
6
|
-
# * only dependency: constant.builders (I wanted to hide this from Cell::Base)
|
7
|
-
# * can easily be replaced or removed.
|
8
|
-
class Builder
|
9
|
-
def initialize(constant, exec_context) # TODO: evaluate usage of builders and implement using Uber::Options::Value.
|
10
|
-
@constant = constant
|
11
|
-
@exec_context = exec_context
|
12
|
-
@builders = @constant.builders # only dependency, must be a Cell::Base subclass.
|
13
|
-
end
|
14
|
-
|
15
|
-
# Creates a cell instance. Note that this method calls builders which were attached to the
|
16
|
-
# class with Cell::Base.build - this might lead to a different cell being returned.
|
17
|
-
def call(*args)
|
18
|
-
build_class_for(*args).
|
19
|
-
new(*args)
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
def build_class_for(*args)
|
24
|
-
@builders.each do |blk|
|
25
|
-
klass = run_builder_block(blk, *args) and return klass
|
26
|
-
end
|
27
|
-
@constant
|
28
|
-
end
|
29
|
-
|
30
|
-
def run_builder_block(block, *args)
|
31
|
-
@exec_context.instance_exec(*args, &block)
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
module ClassMethods
|
36
|
-
# Adds a builder to the cell class. Builders are used in #render_cell to find out the concrete
|
37
|
-
# class for rendering. This is helpful if you frequently want to render subclasses according
|
38
|
-
# to different circumstances (e.g. login situations) and you don't want to place these deciders in
|
39
|
-
# your view code.
|
40
|
-
#
|
41
|
-
# Passes the opts hash from #render_cell into the block. The block is executed in controller context.
|
42
|
-
# Multiple build blocks are ORed, if no builder matches the building cell is used.
|
43
|
-
#
|
44
|
-
# Example:
|
45
|
-
#
|
46
|
-
# Consider two different user box cells in your app.
|
47
|
-
#
|
48
|
-
# class AuthorizedUserBox < UserInfoBox
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# class AdminUserBox < UserInfoBox
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# Now you don't want to have deciders all over your views - use a declarative builder.
|
55
|
-
#
|
56
|
-
# UserInfoBox.build do |opts|
|
57
|
-
# AuthorizedUserBox if user_signed_in?
|
58
|
-
# AdminUserBox if admin_signed_in?
|
59
|
-
# end
|
60
|
-
#
|
61
|
-
# In your view #render_cell will instantiate the right cell for you now.
|
62
|
-
def build(&block)
|
63
|
-
builders << block
|
64
|
-
end
|
65
|
-
|
66
|
-
def builders
|
67
|
-
@builders ||= []
|
68
|
-
end
|
69
|
-
end # ClassMethods
|
70
|
-
end
|
71
|
-
end
|
data/lib/cell/deprecations.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Cell
|
2
|
-
# Makes #options available in Cells 3.7, which was removed in favor of state-args.
|
3
|
-
# Note that Deprecations are only available for Cell::Rails.
|
4
|
-
module Deprecations
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
attr_reader :options
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
def build_for(controller, *args)
|
14
|
-
build_class_for(controller, *args).
|
15
|
-
new(controller, *args)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def initialize(parent_controller, *args)
|
21
|
-
super(parent_controller) # the real Rails.new.
|
22
|
-
setup_backwardibility(*args)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Some people still like #options and assume it's a hash.
|
26
|
-
def setup_backwardibility(*args)
|
27
|
-
@_options = (args.first.is_a?(Hash) and args.size == 1) ? args.first : args
|
28
|
-
@options = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(@_options, "#options is deprecated and was removed in Cells 3.7. Please use state-args.")
|
29
|
-
end
|
30
|
-
|
31
|
-
def render_state(state, *args)
|
32
|
-
return super(state, *args) if state_accepts_args?(state)
|
33
|
-
super(state) # backward-compat.
|
34
|
-
end
|
35
|
-
|
36
|
-
def state_accepts_args?(state)
|
37
|
-
method(state).arity != 0
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
data/lib/cell/dsl.rb
DELETED
data/lib/cell/rack.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'cell/base'
|
2
|
-
|
3
|
-
module Cell
|
4
|
-
# Use Cell::Rack to mount your cell to a rack-route with a working +session+ and +params+ reference
|
5
|
-
# in the cell. This is especially useful when using gems like devise with your cell, without the
|
6
|
-
# entire Cell::Rails overhead.
|
7
|
-
#
|
8
|
-
# The only dependency these kinds of cells have is a Rack-compatible request object.
|
9
|
-
#
|
10
|
-
# Example:
|
11
|
-
#
|
12
|
-
# match "/dashboard/comments" => proc { |env|
|
13
|
-
# request = ActionDispatch::Request.new(env)
|
14
|
-
# [ 200, {}, [ Cell::Rack.render_cell_for(:comments, :show, request) ]]
|
15
|
-
# }
|
16
|
-
class Rack < Base
|
17
|
-
attr_reader :request
|
18
|
-
delegate :session, :params, :to => :request
|
19
|
-
|
20
|
-
class << self
|
21
|
-
# DISCUSS: i don't like these class methods. maybe a RenderingStrategy?
|
22
|
-
def render_cell_state(cell, state, request, *args) # defined in Rendering.
|
23
|
-
super(cell, state, *args)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize(request, *args)
|
28
|
-
super(*args)
|
29
|
-
@request = request
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Cell
|
2
|
-
# Allows using many Rails gem in your cells outside of a Rails environment.
|
3
|
-
class Rails
|
4
|
-
module HelperAPI
|
5
|
-
module InternalHelpers
|
6
|
-
def protect_against_forgery? # used in form_tag_helper.rb:651
|
7
|
-
false
|
8
|
-
end
|
9
|
-
|
10
|
-
def _routes # FIXME: where is this set in rails?
|
11
|
-
self.class._routes
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
extend ActiveSupport::Concern
|
16
|
-
|
17
|
-
module ClassMethods
|
18
|
-
attr_accessor :_routes
|
19
|
-
|
20
|
-
def helper_modules
|
21
|
-
[_helpers, InternalHelpers]
|
22
|
-
end
|
23
|
-
|
24
|
-
def view_context_class
|
25
|
-
super
|
26
|
-
@view_context_class._routes = _routes
|
27
|
-
@view_context_class
|
28
|
-
end
|
29
|
-
|
30
|
-
def action_methods
|
31
|
-
# DISCUSS: we have to overwrite this to avoid a stupid dependency in AbstractController::UrlFor where _routes.named_routes.helper_names is accessed.
|
32
|
-
public_instance_methods(true).map { |x| x.to_s }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,159 +0,0 @@
|
|
1
|
-
# no helper_method calls
|
2
|
-
# no instance variables
|
3
|
-
# no locals
|
4
|
-
# options are automatically made instance methods via constructor.
|
5
|
-
# call "helpers" in class
|
6
|
-
|
7
|
-
# TODO: warn when using ::property but not passing in model in constructor.
|
8
|
-
|
9
|
-
class Cell::Rails
|
10
|
-
module ViewModel
|
11
|
-
include Cell::OptionsConstructor
|
12
|
-
#include ActionView::Helpers::UrlHelper
|
13
|
-
include ActionView::Context # this includes CompiledTemplates, too.
|
14
|
-
# properties :title, :body
|
15
|
-
attr_reader :model
|
16
|
-
|
17
|
-
|
18
|
-
def self.included(*)
|
19
|
-
ActiveSupport::Deprecation.warn("The Cell::Rails::ViewModel module is deprecated and will be removed in Cells 4.0. Please inherit: `class SongCell < Cell::ViewModel`. Thanks and don't forget to smile.")
|
20
|
-
super
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
module Helpers
|
26
|
-
# DISCUSS: highest level API method. add #cell here.
|
27
|
-
def collection(name, controller, array, method=:show, builder=Cell::Rails)
|
28
|
-
# FIXME: this is the problem in Concept cells, we don't wanna call Cell::Rails.cell_for here.
|
29
|
-
array.collect { |model| builder.cell_for(name, controller, model).call(method) }.join("\n").html_safe
|
30
|
-
end
|
31
|
-
|
32
|
-
# TODO: this should be in Helper or something. this should be the only entry point from controller/view.
|
33
|
-
def cell(name, controller, *args, &block) # classic Rails fuzzy API.
|
34
|
-
if args.first.is_a?(Hash) and array = args.first[:collection]
|
35
|
-
return collection(name, controller, array)
|
36
|
-
end
|
37
|
-
|
38
|
-
Cell::Rails.cell_for(name, controller, *args, &block)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
extend Helpers # FIXME: do we really need ViewModel::cell/::collection ?
|
42
|
-
|
43
|
-
|
44
|
-
module ClassMethods
|
45
|
-
def property(*names)
|
46
|
-
delegate *names, :to => :model
|
47
|
-
end
|
48
|
-
|
49
|
-
include Helpers
|
50
|
-
end
|
51
|
-
extend ActiveSupport::Concern
|
52
|
-
|
53
|
-
|
54
|
-
def cell(name, *args)
|
55
|
-
self.class.cell(name, parent_controller, *args)
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
def initialize(*args)
|
60
|
-
super
|
61
|
-
_prepare_context # happens in AV::Base at the bottom.
|
62
|
-
end
|
63
|
-
|
64
|
-
def render(options={})
|
65
|
-
if options.is_a?(Hash)
|
66
|
-
options.reverse_merge!(:view => state_for_implicit_render)
|
67
|
-
else
|
68
|
-
options = {:view => options.to_s}
|
69
|
-
end
|
70
|
-
|
71
|
-
super
|
72
|
-
end
|
73
|
-
|
74
|
-
def call(state=:show)
|
75
|
-
# it is ok to call to_s.html_safe here as #call is a defined rendering method.
|
76
|
-
# DISCUSS: IN CONCEPT: render( view: implicit_state)
|
77
|
-
render_state(state).to_s.html_safe
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
def view_context
|
82
|
-
self
|
83
|
-
end
|
84
|
-
|
85
|
-
def state_for_implicit_render()
|
86
|
-
caller[1].match(/`(\w+)/)[1]
|
87
|
-
end
|
88
|
-
|
89
|
-
# def implicit_state
|
90
|
-
# controller_path.split("/").last
|
91
|
-
# end
|
92
|
-
end
|
93
|
-
|
94
|
-
|
95
|
-
# FIXME: this module is to fix a design flaw in Rails 4.0. the problem is that AV::UrlHelper mixes in the wrong #url_for.
|
96
|
-
# if we could mix in everything else from the helper except for the #url_for, it would be fine.
|
97
|
-
module LinkToHelper
|
98
|
-
include ActionView::Helpers::TagHelper
|
99
|
-
|
100
|
-
def link_to(name = nil, options = nil, html_options = nil, &block)
|
101
|
-
html_options, options, name = options, name, block if block_given?
|
102
|
-
options ||= {}
|
103
|
-
|
104
|
-
html_options = convert_options_to_data_attributes(options, html_options)
|
105
|
-
|
106
|
-
url = url_for(options)
|
107
|
-
html_options['href'] ||= url
|
108
|
-
|
109
|
-
content_tag(:a, name || url, html_options, &block)
|
110
|
-
end
|
111
|
-
|
112
|
-
def convert_options_to_data_attributes(options, html_options)
|
113
|
-
if html_options
|
114
|
-
html_options = html_options.stringify_keys
|
115
|
-
html_options['data-remote'] = 'true' if link_to_remote_options?(options) || link_to_remote_options?(html_options)
|
116
|
-
|
117
|
-
disable_with = html_options.delete("disable_with")
|
118
|
-
confirm = html_options.delete('confirm')
|
119
|
-
method = html_options.delete('method')
|
120
|
-
|
121
|
-
if confirm
|
122
|
-
message = ":confirm option is deprecated and will be removed from Rails 4.1. " \
|
123
|
-
"Use 'data: { confirm: \'Text\' }' instead."
|
124
|
-
ActiveSupport::Deprecation.warn message
|
125
|
-
|
126
|
-
html_options["data-confirm"] = confirm
|
127
|
-
end
|
128
|
-
|
129
|
-
add_method_to_attributes!(html_options, method) if method
|
130
|
-
|
131
|
-
if disable_with
|
132
|
-
message = ":disable_with option is deprecated and will be removed from Rails 4.1. " \
|
133
|
-
"Use 'data: { disable_with: \'Text\' }' instead."
|
134
|
-
ActiveSupport::Deprecation.warn message
|
135
|
-
|
136
|
-
html_options["data-disable-with"] = disable_with
|
137
|
-
end
|
138
|
-
|
139
|
-
html_options
|
140
|
-
else
|
141
|
-
link_to_remote_options?(options) ? {'data-remote' => 'true'} : {}
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def link_to_remote_options?(options)
|
146
|
-
if options.is_a?(Hash)
|
147
|
-
options.delete('remote') || options.delete(:remote)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
# FIXME: fix that in rails core.
|
153
|
-
if Cell.rails_version.~("4.0", "4.1")
|
154
|
-
include LinkToHelper
|
155
|
-
else
|
156
|
-
include ActionView::Helpers::UrlHelper
|
157
|
-
end
|
158
|
-
|
159
|
-
end
|