cells 3.8.0 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/.travis.yml +5 -1
- data/CHANGES.textile +4 -0
- data/README.rdoc +6 -2
- data/cells.gemspec +1 -1
- data/gemfiles/Gemfile.rails3-0 +6 -0
- data/gemfiles/Gemfile.rails3-1 +6 -0
- data/gemfiles/Gemfile.rails3-2 +7 -0
- data/lib/cell/base.rb +1 -2
- data/lib/cell/deprecations.rb +24 -26
- data/lib/cells.rb +6 -1
- data/lib/cells/engines.rb +59 -0
- data/lib/cells/railtie.rb +5 -1
- data/lib/cells/version.rb +1 -1
- data/test/app/cells/bassist/promote.html.erb +1 -1
- data/test/app/cells/trumpeter/promote.html.erb +1 -1
- data/test/cells_module_test.rb +5 -1
- data/test/dummy/config/routes.rb +1 -1
- data/test/rails/caching_test.rb +25 -12
- data/test/rails/cells_test.rb +5 -1
- data/test/rails/render_test.rb +2 -2
- data/test/rails/router_test.rb +4 -4
- data/test/test_helper.rb +0 -7
- metadata +11 -5
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGES.textile
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
h2. 3.8.1
|
2
|
+
|
3
|
+
* Make it work with Rails 3.2 by removing deprecated stuff.
|
4
|
+
|
1
5
|
h2. 3.8.0
|
2
6
|
|
3
7
|
* @Cell::Base@ got rid of the controller dependency. If you want the @ActionController@ instance around in your cell, use @Cell::Rails@ - this should be the default in a standard Rails setup. However, if you plan on using a Cell in a Rack middleware or don't need the controller, use @Cell::Base@.
|
data/README.rdoc
CHANGED
@@ -175,17 +175,21 @@ To run your specs we got a rake task, too!
|
|
175
175
|
|
176
176
|
== Mountable Cells
|
177
177
|
|
178
|
-
Cells 3.8 got rid of the ActionController dependency. This essentially means you can mount Cells to routes or use them like a Rack middleware. All you need to do is derive from
|
178
|
+
Cells 3.8 got rid of the ActionController dependency. This essentially means you can mount Cells to routes or use them like a Rack middleware. All you need to do is derive from Cell::Base.
|
179
179
|
|
180
180
|
class PostCell < Cell::Base
|
181
181
|
..
|
182
182
|
|
183
|
-
In your
|
183
|
+
In your <tt>routes.rb</tt> file, mount the cell like a Rack app.
|
184
184
|
|
185
185
|
match "/posts" => proc { |env|
|
186
186
|
[ 200, {}, [ Cell::Base.render_cell_for(:post, :show) ]]
|
187
187
|
}
|
188
188
|
|
189
|
+
== Cells is Rails::Engine aware!
|
190
|
+
|
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
|
+
|
189
193
|
== Rails 2.3 note
|
190
194
|
|
191
195
|
In order to copy the cells rake tasks to your app, run
|
data/cells.gemspec
CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_development_dependency "haml"
|
28
28
|
s.add_development_dependency "slim"
|
29
29
|
s.add_development_dependency "tzinfo" # FIXME: why the hell do we need this for 3.1?
|
30
|
-
s.add_development_dependency "minitest"
|
30
|
+
s.add_development_dependency "minitest", ">= 2.8.1"
|
31
31
|
end
|
data/lib/cell/base.rb
CHANGED
@@ -4,7 +4,7 @@ require 'cell/caching'
|
|
4
4
|
require 'cell/rendering'
|
5
5
|
require 'cell/rails3_0_strategy' if Cells.rails3_0?
|
6
6
|
require 'cell/rails3_1_strategy' if Cells.rails3_1_or_more?
|
7
|
-
|
7
|
+
|
8
8
|
module Cell
|
9
9
|
class Base < AbstractController::Base
|
10
10
|
abstract!
|
@@ -18,7 +18,6 @@ module Cell
|
|
18
18
|
include Rendering
|
19
19
|
include Caching
|
20
20
|
|
21
|
-
|
22
21
|
class View < ActionView::Base
|
23
22
|
def render(*args, &block)
|
24
23
|
options = args.first.is_a?(::Hash) ? args.first : {} # this is copied from #render by intention.
|
data/lib/cell/deprecations.rb
CHANGED
@@ -3,41 +3,39 @@ module Cell
|
|
3
3
|
# Note that Deprecations are only available for Cell::Rails.
|
4
4
|
module Deprecations
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
6
|
+
|
7
7
|
included do
|
8
8
|
attr_reader :options
|
9
9
|
end
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
|
12
12
|
module ClassMethods
|
13
13
|
def build_for(controller, *args)
|
14
14
|
build_class_for(controller, *args).
|
15
15
|
new(controller, *args)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
method(state).arity != 0
|
39
|
-
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
|
40
38
|
end
|
41
|
-
|
39
|
+
|
42
40
|
end
|
43
41
|
end
|
data/lib/cells.rb
CHANGED
@@ -78,9 +78,14 @@ module Cells
|
|
78
78
|
def self.rails3_1_or_more?
|
79
79
|
::Rails::VERSION::MINOR >= 1
|
80
80
|
end
|
81
|
+
|
82
|
+
def self.rails3_2_or_more? # FIXME: move to tests.
|
83
|
+
::Rails::VERSION::MINOR >= 2
|
84
|
+
end
|
81
85
|
end
|
82
86
|
|
83
87
|
require 'cell/rails'
|
84
|
-
require 'cells/railtie'
|
85
88
|
require 'cells/rails'
|
86
89
|
require 'cell/deprecations'
|
90
|
+
require 'cells/engines'
|
91
|
+
require 'cells/railtie'
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rails/application/railties'
|
2
|
+
|
3
|
+
module Cells
|
4
|
+
# Now <tt>Rails::Engine</tt>s can contribute to Cells view paths.
|
5
|
+
# By default, any 'app/cells' found inside any Engine is automatically included into Cells view paths.
|
6
|
+
#
|
7
|
+
# You can customize the view paths changing/appending to the <tt>'app/cell_views'</tt> path configuration:
|
8
|
+
#
|
9
|
+
# module MyAwesome
|
10
|
+
# class Engine < Rails::Engine
|
11
|
+
# # loads views from 'cell/views' and NOT from 'app/cells'
|
12
|
+
# config.paths.add 'app/cell_views', :with => 'cell/views'
|
13
|
+
#
|
14
|
+
# # appends 'lib/my_cells_view_path' to this Railtie view path contribution
|
15
|
+
# config.paths['app/cell_views'] << 'lib/my_cells_view_path'
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# You can manually specify which Engines will be added to Cell view paths
|
20
|
+
#
|
21
|
+
# Cell::Base.config.view_path_engines = [MyAwesome::Engine]
|
22
|
+
#
|
23
|
+
# And even disable the automatic loading
|
24
|
+
#
|
25
|
+
# Cell::Base.config.view_path_engines = false
|
26
|
+
#
|
27
|
+
# You can programatically append a Rails::Engine to Cell view path
|
28
|
+
#
|
29
|
+
# Cells.setup do |config|
|
30
|
+
# config.append_engine_view_path!(MyEngine::Engine)
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
module Engines
|
34
|
+
# Appends all <tt>Rails::Engine</tt>s cell-views path to Cell::Base#view_paths
|
35
|
+
#
|
36
|
+
# 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
|
37
|
+
#
|
38
|
+
# Defaults <tt>config.view_path_engines</tt> to all loaded <tt>Rails::Engine</tt>s.
|
39
|
+
#
|
40
|
+
def self.append_engines_view_paths_for(config)
|
41
|
+
return if config.view_path_engines == false
|
42
|
+
|
43
|
+
engines = config.view_path_engines || ::Rails::Application::Railties.engines
|
44
|
+
engines.each {|engine| append_engine_view_path!(engine) }
|
45
|
+
end
|
46
|
+
|
47
|
+
# Appends a <tt>Rails::Engine</tt> cell-views path to @Cell::Base@
|
48
|
+
#
|
49
|
+
# The <tt>Rails::Engine</tt> cell-views path is obtained from the <tt>paths['app/cell_views']</tt> configuration.
|
50
|
+
# All existing directories specified at cell-views path will be appended do Cell::Base#view_paths
|
51
|
+
#
|
52
|
+
# Defaults <tt>paths['app/cell_views']</tt> to 'app/cells'
|
53
|
+
#
|
54
|
+
def self.append_engine_view_path!(engine)
|
55
|
+
engine.paths['app/cell_views'] || engine.paths.add('app/cell_views', :with => 'app/cells')
|
56
|
+
Cell::Rails.append_view_path(engine.paths["app/cell_views"].existent_directories)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/cells/railtie.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rails/railtie"
|
2
2
|
|
3
3
|
module Cells
|
4
|
-
class Railtie < Rails::Railtie
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
5
|
initializer "cells.attach_router" do |app|
|
6
6
|
Cell::Base.class_eval do
|
7
7
|
include app.routes.url_helpers
|
@@ -12,6 +12,10 @@ module Cells
|
|
12
12
|
Cell::Base.setup_view_paths!
|
13
13
|
end
|
14
14
|
|
15
|
+
initializer "cells.setup_engines_view_paths" do |app|
|
16
|
+
Cells::Engines.append_engines_view_paths_for(app.config.action_controller)
|
17
|
+
end
|
18
|
+
|
15
19
|
rake_tasks do
|
16
20
|
load "cells/cells.rake"
|
17
21
|
end
|
data/lib/cells/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Find me at <%= link_to "vd.com",
|
1
|
+
Find me at <%= link_to "vd.com", musicians_path %>
|
@@ -1 +1 @@
|
|
1
|
-
Find me at <%= link_to "vd.com",
|
1
|
+
Find me at <%= link_to "vd.com", musicians_url %>
|
data/test/cells_module_test.rb
CHANGED
@@ -16,7 +16,11 @@ class CellsModuleTest < ActiveSupport::TestCase
|
|
16
16
|
c.append_view_path "/road/to/nowhere"
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
if Cells.rails3_2_or_more?
|
20
|
+
assert_equal "/road/to/nowhere", Cell::Rails.view_paths.paths.last.to_s
|
21
|
+
else
|
22
|
+
assert_equal "/road/to/nowhere", Cell::Rails.view_paths.last.to_s
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
data/test/dummy/config/routes.rb
CHANGED
data/test/rails/caching_test.rb
CHANGED
@@ -28,30 +28,43 @@ class CachingUnitTest < ActiveSupport::TestCase
|
|
28
28
|
|
29
29
|
context ".state_cache_key" do
|
30
30
|
should "accept state only" do
|
31
|
-
|
31
|
+
if Cells.rails3_2_or_more?
|
32
|
+
assert_equal "cells/Array/director/count/", @class.state_cache_key(:count)
|
33
|
+
else
|
34
|
+
assert_equal "cells/director/count/", @class.state_cache_key(:count)
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
should "accept hash as key parts" do
|
35
|
-
|
39
|
+
if Cells.rails3_2_or_more?
|
40
|
+
assert_equal "cells/Array/director/count/a=1&b=2", @class.state_cache_key(:count, :b=>2, :a=>1)
|
41
|
+
else
|
42
|
+
assert_equal "cells/director/count/a=1&b=2", @class.state_cache_key(:count, :b=>2, :a=>1)
|
43
|
+
end
|
36
44
|
end
|
37
45
|
|
38
46
|
should "accept array as key parts" do
|
39
|
-
|
47
|
+
if Cells.rails3_2_or_more?
|
48
|
+
assert_equal "cells/Array/director/count/Array/1/2/3", @class.state_cache_key(:count, [1,2,3])
|
49
|
+
else
|
50
|
+
assert_equal "cells/director/count/1/2/3", @class.state_cache_key(:count, [1,2,3])
|
51
|
+
end
|
40
52
|
end
|
41
53
|
|
42
54
|
should "accept string as key parts" do
|
43
|
-
|
55
|
+
if Cells.rails3_2_or_more?
|
56
|
+
assert_equal "cells/Array/director/count/1/2", @class.state_cache_key(:count, "1/2")
|
57
|
+
else
|
58
|
+
assert_equal "cells/director/count/1/2", @class.state_cache_key(:count, "1/2")
|
59
|
+
end
|
44
60
|
end
|
45
61
|
|
46
62
|
should "accept nil as key parts" do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
context ".expand_cache_key" do
|
53
|
-
should "add :cells namespace" do
|
54
|
-
assert_equal "cells/director/count", @class.send(:expand_cache_key, [:director, :count])
|
63
|
+
if Cells.rails3_2_or_more?
|
64
|
+
assert_equal "cells/Array/director/count/", @class.state_cache_key(:count, nil)
|
65
|
+
else
|
66
|
+
assert_equal "cells/director/count/", @class.state_cache_key(:count, nil)
|
67
|
+
end
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
data/test/rails/cells_test.rb
CHANGED
@@ -54,7 +54,11 @@ class RailsCellsTest < ActiveSupport::TestCase
|
|
54
54
|
should "respond to .setup_view_paths!" do
|
55
55
|
swap( Cell::Rails, :view_paths => []) do
|
56
56
|
Cell::Rails.setup_view_paths!
|
57
|
-
|
57
|
+
if Cells.rails3_2_or_more?
|
58
|
+
assert_equal ActionView::PathSet.new(Cell::Rails::DEFAULT_VIEW_PATHS).paths, Cell::Rails.view_paths.paths
|
59
|
+
else
|
60
|
+
assert_equal ActionView::PathSet.new(Cell::Rails::DEFAULT_VIEW_PATHS), Cell::Rails.view_paths
|
61
|
+
end
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
data/test/rails/render_test.rb
CHANGED
@@ -134,12 +134,12 @@ class RailsRenderTest < ActiveSupport::TestCase
|
|
134
134
|
end
|
135
135
|
|
136
136
|
assert_includes e.message, "Missing template cell/rails/groove with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml, :haml], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]} in view paths"
|
137
|
-
else # 3.1
|
137
|
+
else # >= 3.1
|
138
138
|
e = assert_raise ActionView::MissingTemplate do
|
139
139
|
render_cell(:bad_guitarist, :groove)
|
140
140
|
end
|
141
141
|
|
142
|
-
assert_includes e.message, "Missing template bad_guitarist/groove, bassist/groove with
|
142
|
+
assert_includes e.message, "Missing template bad_guitarist/groove, bassist/groove with"
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
data/test/rails/router_test.rb
CHANGED
@@ -6,7 +6,7 @@ module ApplicationTests
|
|
6
6
|
|
7
7
|
context "A Rails app" do
|
8
8
|
should "pass url_helpers to the cell instance" do
|
9
|
-
assert_equal "/", BassistCell.new(@controller).
|
9
|
+
assert_equal "/musicians", BassistCell.new(@controller).musicians_path
|
10
10
|
end
|
11
11
|
|
12
12
|
should "allow cells to use url_helpers" do
|
@@ -16,7 +16,7 @@ module ApplicationTests
|
|
16
16
|
|
17
17
|
get "index"
|
18
18
|
assert_response :success
|
19
|
-
assert_equal "Find me at <a href=\"/
|
19
|
+
assert_equal "Find me at <a href=\"/musicians\">vd.com</a>\n", @response.body
|
20
20
|
end
|
21
21
|
|
22
22
|
should "delegate #url_options to the parent_controller" do
|
@@ -27,13 +27,13 @@ module ApplicationTests
|
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
-
assert_equal "http://cells.rails.org/", BassistCell.new(@controller).
|
30
|
+
assert_equal "http://cells.rails.org/musicians", BassistCell.new(@controller).musicians_url
|
31
31
|
end
|
32
32
|
|
33
33
|
should "allow cells to use *_url helpers when mixing in AC::UrlFor" do
|
34
34
|
get "promote"
|
35
35
|
assert_response :success
|
36
|
-
assert_equal "Find me at <a href=\"http://test.host
|
36
|
+
assert_equal "Find me at <a href=\"http://test.host/musicians\">vd.com</a>\n", @response.body
|
37
37
|
end
|
38
38
|
|
39
39
|
should "allow cells to use #config" do
|
data/test/test_helper.rb
CHANGED
@@ -4,15 +4,8 @@ require 'test/unit'
|
|
4
4
|
require 'shoulda'
|
5
5
|
require 'minitest/spec'
|
6
6
|
|
7
|
-
# wycats says...
|
8
|
-
require 'bundler'
|
9
|
-
Bundler.setup
|
10
|
-
|
11
|
-
|
12
7
|
ENV['RAILS_ENV'] = 'test'
|
13
8
|
|
14
|
-
$:.unshift File.dirname(__FILE__) # add current dir to LOAD_PATHS
|
15
|
-
|
16
9
|
require "dummy/config/environment"
|
17
10
|
require "rails/test_help" # adds stuff like @routes, etc.
|
18
11
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 8
|
8
|
-
-
|
9
|
-
version: 3.8.
|
8
|
+
- 1
|
9
|
+
version: 3.8.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nick Sutterer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2012-02-07 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -119,8 +119,10 @@ dependencies:
|
|
119
119
|
- - ">="
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
segments:
|
122
|
-
-
|
123
|
-
|
122
|
+
- 2
|
123
|
+
- 8
|
124
|
+
- 1
|
125
|
+
version: 2.8.1
|
124
126
|
type: :development
|
125
127
|
version_requirements: *id008
|
126
128
|
description: Cells are view components for Rails. They are lightweight controllers, can be rendered in views and thus provide an elegant and fast way for encapsulation and component-orientation.
|
@@ -141,6 +143,9 @@ files:
|
|
141
143
|
- Rakefile
|
142
144
|
- about.yml
|
143
145
|
- cells.gemspec
|
146
|
+
- gemfiles/Gemfile.rails3-0
|
147
|
+
- gemfiles/Gemfile.rails3-1
|
148
|
+
- gemfiles/Gemfile.rails3-2
|
144
149
|
- lib/cell.rb
|
145
150
|
- lib/cell/base.rb
|
146
151
|
- lib/cell/builder.rb
|
@@ -153,6 +158,7 @@ files:
|
|
153
158
|
- lib/cell/test_case.rb
|
154
159
|
- lib/cells.rb
|
155
160
|
- lib/cells/cells.rake
|
161
|
+
- lib/cells/engines.rb
|
156
162
|
- lib/cells/rails.rb
|
157
163
|
- lib/cells/railtie.rb
|
158
164
|
- lib/cells/version.rb
|