cells 4.1.1 → 4.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 594c3ef475df5cd6314031f24fb23547dbfb83bd
4
- data.tar.gz: 44c82d7a1ef65bee33d4f4ff5c6500e92c7fba17
3
+ metadata.gz: 564e33d0ca30ee7280dd4362eca2cf8f57298836
4
+ data.tar.gz: 3178f06f6211191be74553cf806ae98f5e3017b9
5
5
  SHA512:
6
- metadata.gz: cfb07287f0368594d464bab2850e0bd750c5366cd5658e0f23ace4654a1971a2352d9344c91ff9d7024b772df9a25db65788a95f9bc8ff220a9d41b1ca7ecbb8
7
- data.tar.gz: 126977b1b2887691aaa13863de4f53404f38f0819a518f5acb74c5d6eb6c2d98fb9100ffa47d4a8a42d255cf8d8f0cba24009902fc869315a7a5cde427a04643
6
+ metadata.gz: af0bdc4bf3a5c1b69e94ca1527cc476f836f309eff8d607645204f37cbabe86f612423ba25706328a3f7655dcee054fb575b96a9f9595ee7eada52fb61d4f569
7
+ data.tar.gz: 41098667ace56a3ce85bf588577c7ef7e7e3567804ea64d3df316d48d78b0855f3f32ef81774d075586c24c2ec9d23ddcce0e483708c83ddb9966a1d14a1b5d3
@@ -1,10 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - ruby-head
4
- # - 2.3
5
- - 2.2
6
- - 2.1
7
- - 2.0
3
+ #- ruby-head
4
+ - 2.3.1
5
+ - 2.2.2
8
6
 
9
7
  sudo: false
10
8
  cache: bundler
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 4.1.2
2
+
3
+ * Testing with Rails 5 now works, by removing code the last piece of Rails-code (I know, it sounds bizarre).
4
+
1
5
  ## 4.1.1
2
6
 
3
7
  * Fix rendering of `Collection` where in some environments (Rails), the overridden `#call` method wouldn't work and strings would be escaped.
data/README.md CHANGED
@@ -149,7 +149,7 @@ It is completely up to you how you test, whether it's RSpec, MiniTest or whateve
149
149
 
150
150
  ## Properties
151
151
 
152
- The cell's model is available via the `model` reader. You can have automatic readers to the model's fields by uing `::property`.
152
+ The cell's model is available via the `model` reader. You can have automatic readers to the model's fields by using `::property`.
153
153
 
154
154
  ```ruby
155
155
  class CommentCell < Cell::ViewModel
@@ -349,22 +349,14 @@ comments = Comment.all #=> three comments.
349
349
  cell(:comment, collection: comments).()
350
350
  ```
351
351
 
352
- This will invoke `cell(:comment, comment).()` three times and concatenate the rendered output automatically. In case you don't want `show` but another state rendered, pass the `:method` name to `call`.
352
+ This will invoke `cell(:comment, comment).()` three times and concatenate the rendered output automatically.
353
353
 
354
- ```ruby
355
- cell(:comment, collection: comments).(:list)
356
- ```
357
- Additional options are passed to every cell constructor.
354
+ Learn more [about collections here](http://trailblazer.to/gems/cells/api.html#collection).
358
355
 
359
- ```ruby
360
- cell(:comment, collection: comments, style: "awesome", volume: "loud").()
361
- ```
362
356
 
363
357
  ## Builder
364
358
 
365
- Often, it is good practice to replace decider code from views or classes into separate sub-cells. Or in case you want to render a polymorphic collection, builders come in handy.
366
-
367
- Builders allow instantiating different cell classes for different models and options.
359
+ Builders allow instantiating different cell classes for different models and options. They introduce polymorphism into cells.
368
360
 
369
361
  ```ruby
370
362
  class CommentCell < Cell::ViewModel
@@ -380,14 +372,7 @@ The `#cell` helper takes care of instantiating the right cell class for you.
380
372
  cell(:comment, Post.find(1)) #=> creates a PostCell.
381
373
  ```
382
374
 
383
- This also works with collections.
384
-
385
- ```ruby
386
- cell(:comment, collection: [@post, @comment]) #=> renders PostCell, then CommentCell.
387
- ```
388
-
389
- Multiple calls to `::builds` will be ORed. If no block returns a class, the original class will be used (`CommentCell`). Builders are inherited.
390
-
375
+ Learn more [about builders here](http://trailblazer.to/gems/cells/api.html#builder).
391
376
 
392
377
  ## Caching
393
378
 
data/Rakefile CHANGED
@@ -10,6 +10,10 @@ Rake::TestTask.new(:test) do |test|
10
10
  test.libs << 'test'
11
11
  test.pattern = 'test/*_test.rb'
12
12
  test.verbose = true
13
+ # Ruby built-in warnings contain way too much noise to be useful. Consider turning them on again when the following issues are accepted in ruby:
14
+ # * https://bugs.ruby-lang.org/issues/10967 (remove warning: private attribute?)
15
+ # * https://bugs.ruby-lang.org/issues/12299 (customized warning handling)
16
+ test.warning = false
13
17
  end
14
18
 
15
19
  # Rake::TestTask.new(:rails) do |test|
@@ -21,4 +25,4 @@ end
21
25
  # rails_task = Rake::Task["rails"]
22
26
  # test_task = Rake::Task["test"]
23
27
  # default_task.enhance { test_task.invoke }
24
- # default_task.enhance { rails_task.invoke }
28
+ # default_task.enhance { rails_task.invoke }
@@ -2,25 +2,23 @@ module Cell
2
2
  class Collection
3
3
  def initialize(ary, options, cell_class)
4
4
  options.delete(:collection)
5
- @method = options.delete(:method) # TODO: remove in 5.0.
6
- @join = options.delete(:collection_join) # TODO: remove in 5.0.
5
+ set_deprecated_options(options) # TODO: remove in 5.0.
7
6
 
8
7
  @ary = ary
9
8
  @options = options
10
9
  @cell_class = cell_class
11
-
12
- deprecate_options!
13
10
  end
14
11
 
15
- def deprecate_options! # TODO: remove in 5.0.
16
- warn "[Cells] The :method option is deprecated. Please use `call(method)` as documented here: http://trailblazer.to/gems/cells/api.html#collection" if @method
17
- warn "[Cells] The :collection_join option is deprecated. Please use `join(\"<br>\")` as documented here: http://trailblazer.to/gems/cells/api.html#collection" if @collection_join
12
+ def set_deprecated_options(options) # TODO: remove in 5.0.
13
+ self.method = options.delete(:method) if options.include?(:method)
14
+ self.collection_join = options.delete(:collection_join) if options.include?(:collection_join)
18
15
  end
19
16
 
20
17
  module Call
21
18
  def call(state=:show)
22
- join(@join) { |cell, i| cell.(@method || state) }
19
+ join(collection_join) { |cell, i| cell.(method || state) }
23
20
  end
21
+
24
22
  end
25
23
  include Call
26
24
 
@@ -48,6 +46,13 @@ module Cell
48
46
  end
49
47
  include Layout
50
48
 
49
+ # TODO: remove in 5.0.
50
+ private
51
+ attr_accessor :collection_join, :method
52
+
53
+ extend Gem::Deprecate
54
+ deprecate :method=, "`call(method)` as documented here: http://trailblazer.to/gems/cells/api.html#collection", 2016, 7
55
+ deprecate :collection_join=, "`join(\"<br>\")` as documented here: http://trailblazer.to/gems/cells/api.html#collection", 2016, 7
51
56
  end
52
57
  end
53
58
 
@@ -21,7 +21,7 @@ module Cell
21
21
 
22
22
  def create(prefix, view, options)
23
23
  # puts "...checking #{prefix}/#{view}"
24
- return unless File.exists?("#{prefix}/#{view}") # DISCUSS: can we use Tilt.new here?
24
+ return unless File.exist?("#{prefix}/#{view}") # DISCUSS: can we use Tilt.new here?
25
25
 
26
26
  template_class = options.delete(:template_class)
27
27
  template_class.new("#{prefix}/#{view}", options) # Tilt.new()
@@ -46,17 +46,13 @@ module Cell
46
46
  end
47
47
  end
48
48
 
49
-
50
- # Rails specific.
51
- def controller_for(controller_class)
52
- # TODO: test without controller.
53
- return unless controller_class
54
-
55
- controller_class.new.tap do |ctl|
56
- ctl.request = ::ActionController::TestRequest.new
57
- ctl.instance_variable_set :@routes, ::Rails.application.routes.url_helpers
49
+ module ControllerFor
50
+ # This method is provided by the cells-rails gem.
51
+ def controller_for(controller_class)
52
+ # raise "[Cells] Please install (or update?) the cells-rails gem."
58
53
  end
59
54
  end
55
+ include ControllerFor
60
56
 
61
57
  def controller # FIXME: this won't allow us using let(:controller) in MiniTest.
62
58
  controller_for(self.class.controller_class)
@@ -72,6 +68,5 @@ module Cell
72
68
  end
73
69
  end
74
70
  end
75
-
76
- end
71
+ end # Testing
77
72
  end
@@ -15,11 +15,11 @@ module Cell::Util
15
15
 
16
16
  # WARNING: this API might change.
17
17
  def self.constant_for(name)
18
- constant = Object
19
- name.split("/").each do |part|
20
- constant = constant.const_get(part.split('_').collect(&:capitalize).join)
21
- end
22
- constant
18
+ class_name = name.split("/").collect do |part|
19
+ part.split('_').collect(&:capitalize).join
20
+ end.join('::')
21
+
22
+ Object.const_get(class_name)
23
23
  end
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Cell
2
- VERSION = "4.1.1"
2
+ VERSION = "4.1.2"
3
3
  end
@@ -79,7 +79,9 @@ class ConceptTest < MiniTest::Spec
79
79
  it { Cell::Concept.cell("record/cell", nil, context: { controller: Object }).cell("record/cell", nil).must_be_instance_of Record::Cell }
80
80
  it { Cell::Concept.cell("record/cell", nil, context: { controller: Object }).concept("record/cell", nil, tracks: 24).(:description).must_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]" }
81
81
  # concept(.., collection: ..)
82
- it { Cell::Concept.cell("record/cell", nil, context: { controller: Object }).
83
- concept("record/cell", collection: [1,2], tracks: 24, method: :description).().must_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]A Tribute To Rancid, with 24 songs! [{:controller=>Object}]" }
82
+ it do
83
+ Cell::Concept.cell("record/cell", nil, context: { controller: Object }).
84
+ concept("record/cell", collection: [1,2], tracks: 24).(:description).must_equal "A Tribute To Rancid, with 24 songs! [{:controller=>Object}]A Tribute To Rancid, with 24 songs! [{:controller=>Object}]"
85
+ end
84
86
  end
85
87
  end
@@ -34,15 +34,26 @@ class PublicTest < MiniTest::Spec
34
34
  # ViewModel.cell(collection: []) renders cells.
35
35
  it { Cell::ViewModel.cell("public_test/song", collection: [Object, Module]).to_s.must_equal '[Object, {}][Module, {}]' }
36
36
 
37
+ # DISCUSS: should cell.() be the default?
37
38
  # ViewModel.cell(collection: []) renders cells with custom join.
38
- it { Cell::ViewModel.cell("public_test/song", collection: [Object, Module], collection_join: '<br/>').to_s.must_equal '[Object, {}]<br/>[Module, {}]' }
39
+ it do
40
+ Gem::Deprecate::skip_during do
41
+ Cell::ViewModel.cell("public_test/song", collection: [Object, Module]).join('<br/>') do |cell|
42
+ cell.()
43
+ end.must_equal '[Object, {}]<br/>[Module, {}]'
44
+ end
45
+ end
39
46
 
40
47
  # ViewModel.cell(collection: []) passes generic options to cell.
41
48
  it { Cell::ViewModel.cell("public_test/song", collection: [Object, Module], genre: 'Metal', context: { ready: true }).to_s.must_equal "[Object, {:genre=>\"Metal\", :context=>{:ready=>true}}][Module, {:genre=>\"Metal\", :context=>{:ready=>true}}]" }
42
49
 
43
50
  # ViewModel.cell(collection: [], method: :detail) invokes #detail instead of #show.
44
51
  # TODO: remove in 5.0.
45
- it { Cell::ViewModel.cell("public_test/song", collection: [Object, Module], method: :detail).to_s.must_equal '* [Object, {}]* [Module, {}]' }
52
+ it do
53
+ Gem::Deprecate::skip_during do
54
+ Cell::ViewModel.cell("public_test/song", collection: [Object, Module], method: :detail).to_s.must_equal '* [Object, {}]* [Module, {}]'
55
+ end
56
+ end
46
57
 
47
58
  # ViewModel.cell(collection: []).() invokes #show.
48
59
  it { Cell::ViewModel.cell("public_test/song", collection: [Object, Module]).().must_equal '[Object, {}][Module, {}]' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cells
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-08 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber