cells 3.8.3 → 3.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.textile +6 -0
- data/README.rdoc +12 -0
- data/lib/cell/base.rb +19 -4
- data/lib/cell/rack.rb +36 -0
- data/lib/cell/rails.rb +4 -19
- data/lib/cell/rails3_1_strategy.rb +5 -4
- data/lib/cell/test_case.rb +3 -4
- data/lib/cells.rb +1 -11
- data/lib/cells/version.rb +1 -1
- data/lib/generators/cells/base.rb +1 -0
- data/lib/generators/templates/cell.rb +1 -1
- data/test/cell_generator_test.rb +5 -0
- data/test/cell_module_test.rb +3 -3
- data/test/rack_test.rb +32 -0
- data/test/test_case_test.rb +0 -6
- metadata +20 -18
data/CHANGES.textile
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
h2. 3.8.4
|
2
|
+
|
3
|
+
* Added @Cell::Rack@ for request-dependent Cells. This is also the new base class for @Cells::Rails@.
|
4
|
+
* Removed deprecation warning from @TestCase#cell@ as it's signature is not deprecated.
|
5
|
+
* Added the @base_cell_class@ config option to generator for specifying an alternative base class.
|
6
|
+
|
1
7
|
h2. 3.8.3
|
2
8
|
|
3
9
|
* Added @Engines.existent_directories_for@ to prevent Rails 3.0 from crashing when it detects engines.
|
data/README.rdoc
CHANGED
@@ -190,6 +190,18 @@ In your <tt>routes.rb</tt> file, mount the cell like a Rack app.
|
|
190
190
|
|
191
191
|
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. If you need to, you can customize the view paths changing/appending to the <tt>'app/cell_views'</tt> path configuration. See the @Cell::EngineIntegration@ for more details.
|
192
192
|
|
193
|
+
== Custom base class
|
194
|
+
|
195
|
+
By default, generated cells inherit from <code>Cell::Rails</code>. If you want to change this, specify your new class name in <code>config/application.rb</code>:
|
196
|
+
|
197
|
+
module MyApp
|
198
|
+
class Application < Rails::Application
|
199
|
+
config.generators do |g|
|
200
|
+
g.base_cell_class "ApplicationCell"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
193
205
|
== Rails 2.3 note
|
194
206
|
|
195
207
|
In order to copy the cells rake tasks to your app, run
|
data/lib/cell/base.rb
CHANGED
@@ -2,21 +2,36 @@ require 'abstract_controller'
|
|
2
2
|
require 'cell/builder'
|
3
3
|
require 'cell/caching'
|
4
4
|
require 'cell/rendering'
|
5
|
-
require 'cell/rails3_0_strategy' if Cells.rails3_0?
|
6
|
-
require 'cell/rails3_1_strategy' if Cells.rails3_1_or_more?
|
7
5
|
|
8
6
|
module Cell
|
9
7
|
class Base < AbstractController::Base
|
8
|
+
module Utils # TODO: Move to separate file.
|
9
|
+
def rails3_0?
|
10
|
+
::ActionPack::VERSION::MINOR == 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def rails3_1_or_more?
|
14
|
+
::ActionPack::VERSION::MINOR >= 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def rails3_2_or_more? # FIXME: move to tests.
|
18
|
+
::ActionPack::VERSION::MINOR >= 2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
abstract!
|
11
23
|
DEFAULT_VIEW_PATHS = [File.join('app', 'cells')]
|
12
24
|
|
13
|
-
extend Builder
|
25
|
+
extend Builder, Utils
|
14
26
|
include AbstractController
|
15
27
|
include AbstractController::Rendering, Layouts, Helpers, Callbacks, Translation, Logger
|
16
28
|
|
29
|
+
require 'cell/rails3_0_strategy' if rails3_0?
|
30
|
+
require 'cell/rails3_1_strategy' if rails3_1_or_more?
|
17
31
|
include VersionStrategy
|
18
32
|
include Rendering
|
19
|
-
include Caching
|
33
|
+
#include Caching
|
34
|
+
|
20
35
|
|
21
36
|
class View < ActionView::Base
|
22
37
|
def render(*args, &block)
|
data/lib/cell/rack.rb
ADDED
@@ -0,0 +1,36 @@
|
|
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 create_cell(request, *args) # defined in Builder.
|
23
|
+
new(request)
|
24
|
+
end
|
25
|
+
|
26
|
+
def render_cell_state(cell, state, request, *args) # defined in Rendering.
|
27
|
+
super(cell, state, *args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(request)
|
32
|
+
super()
|
33
|
+
@request = request
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/cell/rails.rb
CHANGED
@@ -1,39 +1,24 @@
|
|
1
|
-
require 'cell/
|
1
|
+
require 'cell/rack'
|
2
2
|
|
3
3
|
module Cell
|
4
|
-
class Rails <
|
4
|
+
class Rails < Rack
|
5
5
|
include ActionController::RequestForgeryProtection
|
6
6
|
|
7
7
|
abstract!
|
8
|
-
|
9
|
-
module Metal
|
10
|
-
delegate :session, :params, :request, :config, :env, :url_options, :to => :parent_controller
|
11
|
-
end
|
12
|
-
|
13
|
-
include Metal
|
14
|
-
|
8
|
+
delegate :session, :params, :request, :config, :env, :url_options, :to => :parent_controller
|
15
9
|
|
16
10
|
class << self
|
17
|
-
def create_cell(controller, *args)
|
18
|
-
new(controller)
|
19
|
-
end
|
20
|
-
|
21
11
|
private
|
22
12
|
# Run builder block in controller instance context.
|
23
13
|
def run_builder_block(block, controller, *args)
|
24
14
|
controller.instance_exec(*args, &block)
|
25
15
|
end
|
26
|
-
|
27
|
-
def render_cell_state(cell, state, *args)
|
28
|
-
args.shift # remove the controller instance.
|
29
|
-
cell.render_state(state, *args)
|
30
|
-
end
|
31
16
|
end
|
32
17
|
|
33
18
|
attr_reader :parent_controller
|
34
19
|
|
35
20
|
def initialize(parent_controller)
|
36
|
-
super
|
21
|
+
super
|
37
22
|
@parent_controller = parent_controller
|
38
23
|
end
|
39
24
|
end
|
@@ -4,15 +4,16 @@ module Cell
|
|
4
4
|
module VersionStrategy
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
include AbstractController::UrlFor # must be included before _routes is set in Railstie.
|
7
|
+
#include AbstractController::UrlFor # must be included before _routes is set in Railstie.
|
8
8
|
|
9
9
|
|
10
10
|
module ClassMethods
|
11
11
|
def view_context_class
|
12
12
|
@view_context_class ||= begin
|
13
|
-
routes = _routes
|
14
|
-
helpers = _helpers
|
15
|
-
|
13
|
+
routes = _routes # if respond_to?(:_routes)
|
14
|
+
helpers = _helpers# if respond_to?(:_helpers)
|
15
|
+
|
16
|
+
Cell::Base::View.prepare(routes, helpers)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
data/lib/cell/test_case.rb
CHANGED
@@ -110,10 +110,9 @@ module Cell
|
|
110
110
|
# Example:
|
111
111
|
# assert_equal "Doo Dumm Dumm..." cell(:bassist).play
|
112
112
|
def cell(name, *args, &block)
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
cell
|
113
|
+
Cell::Rails.create_cell_for(name, @controller, *args).tap do |cell|
|
114
|
+
cell.instance_eval &block if block_given?
|
115
|
+
end
|
117
116
|
end
|
118
117
|
|
119
118
|
# Execute the passed +block+ in a real view context of +cell_class+.
|
data/lib/cells.rb
CHANGED
@@ -64,24 +64,14 @@ module Cells
|
|
64
64
|
# Example:
|
65
65
|
#
|
66
66
|
# Cells.setup do |config|
|
67
|
-
# config.append_view_path
|
67
|
+
# config.append_view_path "app/view_models"
|
68
68
|
# end
|
69
69
|
#
|
70
70
|
def self.setup
|
71
71
|
yield(Cell::Rails)
|
72
72
|
end
|
73
73
|
|
74
|
-
def self.rails3_0?
|
75
|
-
::Rails::VERSION::MINOR == 0
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.rails3_1_or_more?
|
79
|
-
::Rails::VERSION::MINOR >= 1
|
80
|
-
end
|
81
74
|
|
82
|
-
def self.rails3_2_or_more? # FIXME: move to tests.
|
83
|
-
::Rails::VERSION::MINOR >= 2
|
84
|
-
end
|
85
75
|
end
|
86
76
|
|
87
77
|
require 'cell/rails'
|
data/lib/cells/version.rb
CHANGED
@@ -6,6 +6,7 @@ module Cells
|
|
6
6
|
class Base < ::Rails::Generators::NamedBase
|
7
7
|
class_option :template_engine
|
8
8
|
class_option :test_framework
|
9
|
+
class_option :base_cell_class, :type => :string, :default => "Cell::Rails"
|
9
10
|
|
10
11
|
argument :actions, :type => :array, :default => [], :banner => "action action"
|
11
12
|
check_class_collision :suffix => "Cell"
|
data/test/cell_generator_test.rb
CHANGED
@@ -26,6 +26,11 @@ class CellGeneratorTest < Rails::Generators::TestCase
|
|
26
26
|
assert_no_file "app/cells/blog/post.html.slim"
|
27
27
|
assert_no_file "app/cells/blog/latest.html.slim"
|
28
28
|
end
|
29
|
+
|
30
|
+
should "create cell that inherits from custom cell class if specified" do
|
31
|
+
run_generator %w(Blog --base-cell-class=ApplicationCell)
|
32
|
+
assert_file "app/cells/blog_cell.rb", /class BlogCell < ApplicationCell/
|
33
|
+
end
|
29
34
|
|
30
35
|
should "work with namespaces" do
|
31
36
|
run_generator %w(Blog::Post latest)
|
data/test/cell_module_test.rb
CHANGED
@@ -11,8 +11,8 @@ end
|
|
11
11
|
|
12
12
|
# Used in CellBaseTest.
|
13
13
|
class ShouterCell < Cell::Base
|
14
|
-
def sing
|
15
|
-
render
|
14
|
+
def sing(first)
|
15
|
+
first + render
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -35,7 +35,7 @@ class CellBaseTest < MiniTest::Spec
|
|
35
35
|
describe ".render_cell_for" do
|
36
36
|
it "invokes controller-less cell" do
|
37
37
|
Cell::Base.view_paths= ["test/app/cells"]
|
38
|
-
assert_equal "
|
38
|
+
assert_equal "YAAAaaargh!\n", Cell::Base.render_cell_for(:shouter, :sing, "Y")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/test/rack_test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RackTest < MiniTest::Spec
|
4
|
+
class BassistCell < Cell::Rack
|
5
|
+
def play
|
6
|
+
render :text => request.class
|
7
|
+
end
|
8
|
+
|
9
|
+
def sing
|
10
|
+
render :text => session[:what]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Cell::Rack" do
|
15
|
+
before do
|
16
|
+
@request = ActionDispatch::TestRequest.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it "allows accessing the request object" do
|
20
|
+
assert_equal "ActionDispatch::TestRequest", BassistCell.new(@request).render_state(:play)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "allows accessing the session object" do
|
24
|
+
@request.session[:what] = "Yo!"
|
25
|
+
assert_equal "Yo!", BassistCell.new(@request).render_state(:sing)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "works with #render_cell_for" do
|
29
|
+
assert_equal "ActionDispatch::TestRequest", Cell::Rack.render_cell_for("rack_test/bassist", :play, @request)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/test_case_test.rb
CHANGED
@@ -34,12 +34,6 @@ class TestCaseTest < Cell::TestCase
|
|
34
34
|
should "accept a block" do
|
35
35
|
assert_respond_to cell(:bassist){ def whatever; end }, :whatever
|
36
36
|
end
|
37
|
-
|
38
|
-
should "mark options as deprecated" do
|
39
|
-
assert_deprecated do
|
40
|
-
res = cell(:bassist, :song => "Lockdown")
|
41
|
-
end
|
42
|
-
end
|
43
37
|
end
|
44
38
|
|
45
39
|
context "#subject_cell" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cells
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.8.
|
4
|
+
version: 3.8.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &79267830 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *79267830
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: railties
|
27
|
-
requirement: &
|
27
|
+
requirement: &79266900 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *79266900
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &79266060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *79266060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: shoulda
|
49
|
-
requirement: &
|
49
|
+
requirement: &79264770 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *79264770
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: haml
|
60
|
-
requirement: &
|
60
|
+
requirement: &79264410 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *79264410
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: slim
|
71
|
-
requirement: &
|
71
|
+
requirement: &79263450 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *79263450
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: tzinfo
|
82
|
-
requirement: &
|
82
|
+
requirement: &79261530 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *79261530
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: minitest
|
93
|
-
requirement: &
|
93
|
+
requirement: &79258660 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: 2.8.1
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *79258660
|
102
102
|
description: Cells are view components for Rails. They are lightweight controllers,
|
103
103
|
can be rendered in views and thus provide an elegant and fast way for encapsulation
|
104
104
|
and component-orientation.
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/cell/builder.rb
|
125
125
|
- lib/cell/caching.rb
|
126
126
|
- lib/cell/deprecations.rb
|
127
|
+
- lib/cell/rack.rb
|
127
128
|
- lib/cell/rails.rb
|
128
129
|
- lib/cell/rails3_0_strategy.rb
|
129
130
|
- lib/cell/rails3_1_strategy.rb
|
@@ -216,6 +217,7 @@ files:
|
|
216
217
|
- test/dummy/public/stylesheets/.gitkeep
|
217
218
|
- test/dummy/script/rails
|
218
219
|
- test/helper_test.rb
|
220
|
+
- test/rack_test.rb
|
219
221
|
- test/rails/caching_test.rb
|
220
222
|
- test/rails/capture_test.rb
|
221
223
|
- test/rails/cells_test.rb
|