cells 4.0.5 → 4.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -14
  3. data/CHANGES.md +34 -7
  4. data/Gemfile +2 -2
  5. data/README.md +18 -88
  6. data/benchmarks/class_builder.rb +37 -0
  7. data/benchmarks/collection.rb +47 -0
  8. data/cells.gemspec +5 -7
  9. data/lib/cell.rb +2 -11
  10. data/lib/cell/builder.rb +16 -0
  11. data/lib/cell/collection.rb +54 -0
  12. data/lib/cell/concept.rb +6 -7
  13. data/lib/cell/escaped.rb +1 -0
  14. data/lib/cell/layout.rb +50 -14
  15. data/lib/cell/testing.rb +6 -5
  16. data/lib/cell/util.rb +10 -1
  17. data/lib/cell/version.rb +1 -1
  18. data/lib/cell/view_model.rb +27 -56
  19. data/lib/cells.rb +1 -1
  20. data/test/builder_test.rb +4 -2
  21. data/test/cell_test.rb +9 -2
  22. data/test/concept_test.rb +9 -16
  23. data/test/context_test.rb +33 -0
  24. data/test/fixtures/cell_test/song/show_with_block.erb +1 -0
  25. data/test/fixtures/comment/layout/show.erb +1 -0
  26. data/test/fixtures/comment/show/show.erb +1 -0
  27. data/test/fixtures/song/with_block.erb +1 -0
  28. data/test/layout_test.rb +34 -1
  29. data/test/prefixes_test.rb +3 -3
  30. data/test/public_test.rb +43 -9
  31. data/test/render_test.rb +7 -3
  32. data/test/test_helper.rb +2 -38
  33. data/test/{test_case_test.rb → testing_test.rb} +2 -2
  34. metadata +16 -159
  35. data/gemfiles/rails3.2.gemfile +0 -16
  36. data/gemfiles/rails4.0.gemfile +0 -12
  37. data/gemfiles/rails4.1.gemfile +0 -12
  38. data/gemfiles/rails4.2.gemfile +0 -10
  39. data/lib/cell/caching/notification.rb +0 -15
  40. data/lib/cell/rails.rb +0 -98
  41. data/lib/cell/railtie.rb +0 -69
  42. data/lib/cell/test_case.rb +0 -12
  43. data/lib/cell/translation.rb +0 -19
  44. data/lib/rails/generators/cell/cell_generator.rb +0 -43
  45. data/lib/rails/generators/cell/templates/cell.rb.erb +0 -8
  46. data/lib/rails/generators/cell/templates/view.erb +0 -7
  47. data/lib/rails/generators/cell/templates/view.haml +0 -4
  48. data/lib/rails/generators/cell/templates/view.slim +0 -2
  49. data/lib/rails/generators/concept/concept_generator.rb +0 -38
  50. data/lib/rails/generators/concept/templates/concept.rb.erb +0 -7
  51. data/lib/rails/generators/concept/templates/view.erb +0 -7
  52. data/lib/rails/generators/concept/templates/view.haml +0 -4
  53. data/lib/rails/generators/concept/templates/view.slim +0 -2
  54. data/lib/rails/generators/test_unit/cell/cell_generator.rb +0 -21
  55. data/lib/rails/generators/test_unit/cell/templates/unit_test.rb.erb +0 -11
  56. data/lib/rails/generators/test_unit/concept/concept_generator.rb +0 -21
  57. data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +0 -11
  58. data/test/caching_test.rb +0 -305
  59. data/test/cell_generator_test.rb +0 -90
  60. data/test/concept_generator_test.rb +0 -40
  61. data/test/dummy/Rakefile +0 -7
  62. data/test/dummy/app/assets/javascripts/application.js +0 -2
  63. data/test/dummy/app/cells/album/assets/album.js +0 -1
  64. data/test/dummy/app/concepts/song/assets/songs.js +0 -1
  65. data/test/dummy/app/controllers/application_controller.rb +0 -4
  66. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  67. data/test/dummy/app/views/musician/featured.html.erb +0 -1
  68. data/test/dummy/app/views/musician/featured_with_block.html.erb +0 -4
  69. data/test/dummy/app/views/musician/hamlet.html.erb +0 -1
  70. data/test/dummy/app/views/musician/title.erb +0 -1
  71. data/test/dummy/config.ru +0 -4
  72. data/test/dummy/config/application.rb +0 -41
  73. data/test/dummy/config/boot.rb +0 -10
  74. data/test/dummy/config/database.yml +0 -22
  75. data/test/dummy/config/environment.rb +0 -5
  76. data/test/dummy/config/locales/en.yml +0 -5
  77. data/test/dummy/config/routes.rb +0 -5
  78. data/test/dummy/script/rails +0 -6
  79. data/test/rails/translation_test.rb +0 -45
  80. data/test/rails4.2/.gitignore +0 -13
  81. data/test/rails4.2/Gemfile +0 -18
  82. data/test/rails4.2/README.rdoc +0 -3
  83. data/test/rails4.2/Rakefile +0 -6
  84. data/test/rails4.2/app/assets/images/.keep +0 -0
  85. data/test/rails4.2/app/assets/stylesheets/application.css.erb +0 -19
  86. data/test/rails4.2/app/cells/form_for/show.erb +0 -7
  87. data/test/rails4.2/app/cells/form_for_cell.rb +0 -7
  88. data/test/rails4.2/app/cells/form_tag/show.erb +0 -5
  89. data/test/rails4.2/app/cells/form_tag_cell.rb +0 -5
  90. data/test/rails4.2/app/cells/formtastic/show.erb +0 -12
  91. data/test/rails4.2/app/cells/formtastic_cell.rb +0 -9
  92. data/test/rails4.2/app/cells/simple_form/show.erb +0 -7
  93. data/test/rails4.2/app/cells/simple_form_cell.rb +0 -11
  94. data/test/rails4.2/app/cells/song/song.css +0 -1
  95. data/test/rails4.2/app/cells/song/with_escaped.erb +0 -1
  96. data/test/rails4.2/app/cells/song_cell.rb +0 -18
  97. data/test/rails4.2/app/controllers/application_controller.rb +0 -5
  98. data/test/rails4.2/app/controllers/concerns/.keep +0 -0
  99. data/test/rails4.2/app/controllers/index_controller.rb +0 -7
  100. data/test/rails4.2/app/controllers/songs_controller.rb +0 -25
  101. data/test/rails4.2/app/helpers/application_helper.rb +0 -2
  102. data/test/rails4.2/app/mailers/.keep +0 -0
  103. data/test/rails4.2/app/models/.keep +0 -0
  104. data/test/rails4.2/app/models/artist.rb +0 -25
  105. data/test/rails4.2/app/models/concerns/.keep +0 -0
  106. data/test/rails4.2/app/models/song.rb +0 -25
  107. data/test/rails4.2/app/views/index/index.html.erb +0 -6
  108. data/test/rails4.2/app/views/layouts/application.html.erb +0 -13
  109. data/test/rails4.2/app/views/songs/show.html.erb +0 -1
  110. data/test/rails4.2/app/views/songs/with_escaped.html.erb +0 -1
  111. data/test/rails4.2/bin/bundle +0 -3
  112. data/test/rails4.2/bin/rails +0 -4
  113. data/test/rails4.2/bin/rake +0 -4
  114. data/test/rails4.2/bin/setup +0 -29
  115. data/test/rails4.2/config.ru +0 -4
  116. data/test/rails4.2/config/application.rb +0 -38
  117. data/test/rails4.2/config/boot.rb +0 -3
  118. data/test/rails4.2/config/environment.rb +0 -5
  119. data/test/rails4.2/config/environments/development.rb +0 -25
  120. data/test/rails4.2/config/environments/production.rb +0 -64
  121. data/test/rails4.2/config/environments/test.rb +0 -42
  122. data/test/rails4.2/config/initializers/backtrace_silencers.rb +0 -7
  123. data/test/rails4.2/config/initializers/cookies_serializer.rb +0 -3
  124. data/test/rails4.2/config/initializers/filter_parameter_logging.rb +0 -4
  125. data/test/rails4.2/config/initializers/formtastic.rb +0 -2
  126. data/test/rails4.2/config/initializers/inflections.rb +0 -16
  127. data/test/rails4.2/config/initializers/mime_types.rb +0 -4
  128. data/test/rails4.2/config/initializers/session_store.rb +0 -3
  129. data/test/rails4.2/config/initializers/wrap_parameters.rb +0 -9
  130. data/test/rails4.2/config/locales/en.yml +0 -23
  131. data/test/rails4.2/config/routes.rb +0 -9
  132. data/test/rails4.2/config/secrets.yml +0 -22
  133. data/test/rails4.2/db/seeds.rb +0 -7
  134. data/test/rails4.2/engines/my_engine/.gitignore +0 -3
  135. data/test/rails4.2/engines/my_engine/Gemfile +0 -15
  136. data/test/rails4.2/engines/my_engine/MIT-LICENSE +0 -20
  137. data/test/rails4.2/engines/my_engine/README.rdoc +0 -3
  138. data/test/rails4.2/engines/my_engine/Rakefile +0 -24
  139. data/test/rails4.2/engines/my_engine/app/assets/images/my_engine/.keep +0 -0
  140. data/test/rails4.2/engines/my_engine/app/assets/stylesheets/my_engine/application.css +0 -15
  141. data/test/rails4.2/engines/my_engine/app/concepts/user/cell.rb +0 -8
  142. data/test/rails4.2/engines/my_engine/app/concepts/user/views/show.erb +0 -1
  143. data/test/rails4.2/engines/my_engine/app/concepts/user/views/user.scss +0 -3
  144. data/test/rails4.2/engines/my_engine/app/controllers/my_engine/application_controller.rb +0 -4
  145. data/test/rails4.2/engines/my_engine/app/controllers/my_engine/user_controller.rb +0 -7
  146. data/test/rails4.2/engines/my_engine/app/helpers/my_engine/application_helper.rb +0 -4
  147. data/test/rails4.2/engines/my_engine/app/models/my_engine/user.rb +0 -4
  148. data/test/rails4.2/engines/my_engine/app/views/layouts/my_engine/application.html.erb +0 -14
  149. data/test/rails4.2/engines/my_engine/app/views/my_engine/user/show.html.erb +0 -3
  150. data/test/rails4.2/engines/my_engine/bin/rails +0 -12
  151. data/test/rails4.2/engines/my_engine/config/routes.rb +0 -3
  152. data/test/rails4.2/engines/my_engine/db/migrate/20150530135920_create_my_engine_users.rb +0 -8
  153. data/test/rails4.2/engines/my_engine/lib/my_engine.rb +0 -6
  154. data/test/rails4.2/engines/my_engine/lib/my_engine/engine.rb +0 -9
  155. data/test/rails4.2/engines/my_engine/lib/my_engine/version.rb +0 -3
  156. data/test/rails4.2/engines/my_engine/lib/tasks/my_engine_tasks.rake +0 -4
  157. data/test/rails4.2/engines/my_engine/my_engine.gemspec +0 -24
  158. data/test/rails4.2/engines/my_engine/test/fixtures/my_engine/users.yml +0 -11
  159. data/test/rails4.2/engines/my_engine/test/models/my_engine/user_test.rb +0 -9
  160. data/test/rails4.2/lib/assets/.keep +0 -0
  161. data/test/rails4.2/lib/tasks/.keep +0 -0
  162. data/test/rails4.2/log/.keep +0 -0
  163. data/test/rails4.2/test/integration/asset_pipeline_test.rb +0 -17
  164. data/test/rails4.2/test/integration/controller_test.rb +0 -16
  165. data/test/rails4.2/test/integration/form_for_test.rb +0 -10
  166. data/test/rails4.2/test/integration/form_tag_test.rb +0 -11
  167. data/test/rails4.2/test/integration/formtastic_test.rb +0 -12
  168. data/test/rails4.2/test/integration/simple_form_test.rb +0 -11
  169. data/test/rails4.2/test/integration/url_helper_test.rb +0 -47
  170. data/test/rails4.2/test/test_helper.rb +0 -14
  171. data/test/rails4.2/vendor/assets/stylesheets/.keep +0 -0
  172. data/test/rails_extensions_test.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ef7b3e4ead686e4d02d8e9baf632e8333fae1bf
4
- data.tar.gz: 6971a3c4628a18d399011179b922f5423ffed4d2
3
+ metadata.gz: d5b5b3fb59b494665fdfbed8d2f584451fbfcdaf
4
+ data.tar.gz: 2f803c45dcf7e60a5ce760ba62bf27a206c671e2
5
5
  SHA512:
6
- metadata.gz: 786ee96506dc6cf01ec325c3b06ea78b8543f33207b756db8c18a1c96230a8eedf2394ffce08a8baa08d354a3388a3b6c4ca6a227c4bf9a237be1930265eca91
7
- data.tar.gz: 58b053d459be2071faa1e09f872fb1c5b894e8a5bb14180f40f130c626fca9072750158c8894eb6e2810da44b7f6188f566c44e260b660129ea7aa59497a1ffc
6
+ metadata.gz: f36438868b22eac626e664baeb82bc88693a88dfaf681e7185f7636299139311c39ca05d7f1166f8768dcd2f0058ee7289d0a196b2d7d0fc1b81ce7484d68934
7
+ data.tar.gz: a853d11bdbb5c1b1120e085662a5ea4af833b6aac9289cba46a555ee472a3eda57e2c0ab6733ea2cd454e883c5facb4cafdd1305420a75e834f15dd833807fe4
@@ -1,26 +1,14 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - ruby-head
4
+ # - 2.3
4
5
  - 2.2
5
6
  - 2.1
6
- - 2.0.0
7
- - 1.9.3
8
- - jruby-19mode
7
+ - 2.0
9
8
 
10
9
  sudo: false
11
-
12
10
  cache: bundler
13
11
 
14
- bundler_args: '--without local_development --jobs 3 --retry 3'
15
-
16
- script: bundle exec rake
17
-
18
- gemfile:
19
- - gemfiles/rails4.2.gemfile
20
- - gemfiles/rails4.1.gemfile
21
- - gemfiles/rails4.0.gemfile
22
- - gemfiles/rails3.2.gemfile
23
-
24
12
  matrix:
25
13
  fast_finish: true
26
14
  allow_failures:
data/CHANGES.md CHANGED
@@ -1,20 +1,30 @@
1
1
  ## 4.1.0
2
2
 
3
- TODO: extract internal :layout, extract builder
4
-
5
3
  ### API Fix/Changes
6
4
 
7
- * You can no longer pass a block to `ViewModel#call`. Use `tap` if you want the same behavior.
5
+ * All Rails code removed. Make sure to use [Cells-rails](https://github.com/trailblazer/cells-rails) if you want the old Rails behavior.
6
+ * A basic, rendering `#show` method is now provided automatically.
7
+ * `ViewModel#render` now accepts a block that can be `yield`ed in the view.
8
+ * Passing a block to `ViewModel#call` changed. Use `tap` if you want the "old" behavior (which was never official or documented).
8
9
  ```ruby
9
10
  Comment::Cell.new(comment).().tap { |cell| }
10
11
  ```
12
+ The new behavior is to pass that block to your state method. You can pass it on to `render`, and then `yield` it in the template.
13
+
14
+ ```ruby
15
+ def show(&block)
16
+ render &block # yield in show.haml
17
+ end
18
+ ```
19
+
20
+ Note that this happens automatically in the default `ViewModel#show` method.
11
21
  * `Concept#cell` now will resolve a concept cell (`Song::Cell`), and not the old-style suffix cell (`SongCell`). The same applies to `Concept#concept`.
12
22
 
13
23
  ```ruby
14
24
  concept("song/cell", song).cell("song/cell/composer") #=> resolves to Song::Cell::Composer
15
25
  ```
16
- This decision has been made in regards of the upcoming, ass-kicking Cells 5. It simplifies code dramatically, and we consider it unnatural to mix concept and suffix cells in applications.
17
- * In case you were using `@parent_controller`, this doesn't exist anymore (and was never documented, either). Use `options[:context][:controller]`.
26
+ This decision has been made in regards of the upcoming Cells 5. It simplifies code dramatically, and we consider it unnatural to mix concept and suffix cells in applications.
27
+ * In case you were using `@parent_controller`, this doesn't exist anymore (and was never documented, either). Use `context[:controller]`.
18
28
  * `::self_contained!` is no longer included into `ViewModel`. Please try using `Trailblazer::Cell` instead. If you still need it, here's how.
19
29
 
20
30
  ```ruby
@@ -22,11 +32,12 @@ TODO: extract internal :layout, extract builder
22
32
  extend SelfContained
23
33
  self_contained!
24
34
  ```
25
-
26
- * `Cell::Concept` is deprecated and you should be using the excellent `Trailblazer::Cell` class instead, because that's what a concept cell tries to be in an awkward way. The latter is usable without Trailblazer.
35
+ * `Cell::Concept` is deprecated and you should be using the excellent [`Trailblazer::Cell`](https://github.com/trailblazer/trailblazer-cells) class instead, because that's what a concept cell tries to be in an awkward way. The latter is usable without Trailblazer.
27
36
 
28
37
  We are hereby dropping support for `Cell::Concept` (it still works).
29
38
 
39
+ * Deprecating `:collection_join` and `:method` for collections.
40
+
30
41
  ### Awesomeness
31
42
 
32
43
  * Introduced the concept of a context object that is being passed to all nested cells. This object is supposed to contain dependencies such as `current_user`, in Rails it contains the "parent_controller" under the `context[:controller]` key.
@@ -49,6 +60,22 @@ TODO: extract internal :layout, extract builder
49
60
  ```ruby
50
61
  cell(Song::Cell, song)
51
62
  ```
63
+ * New API for `:collection`. If used in views, this happens automatically, but here's how it works now.
64
+
65
+ ```ruby
66
+ cell(:comment, collection: Comment.all).() # will invoke show.
67
+ cell(:comment, collection: Comment.all).(:item) # will invoke item.
68
+ cell(:comment, collection: Comment.all).join { |cell, i| cell.show(index: i) }
69
+ ```
70
+ Basically, a `Collection` instance is returned that optionally allows to invoke each cell manually.
71
+ * Layout cells can now be injected to wrap the original content.
72
+ ```ruby
73
+ cell(:comment, Comment.find(1), layout: LayoutCell)
74
+ ```
75
+
76
+ The LayoutCell will be instantiated and the `show` state invoked. The content cell's content is passed as a block, allowing the layout's view to `yield`.
77
+
78
+ This works with `:collection`, too.
52
79
 
53
80
  ## 4.0.5
54
81
 
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "railties", "~> 4.2.0"
4
- gem "activemodel", "~> 4.2.0"
5
3
  gem "minitest", "~> 5.2"
6
4
  gem "cells-erb"#, path: "../cells-erb"
5
+ gem "benchmark-ips"
6
+ gem "minitest-line"
7
7
 
8
8
  gemspec
data/README.md CHANGED
@@ -2,16 +2,23 @@
2
2
 
3
3
  *View Components for Ruby and Rails.*
4
4
 
5
+ [![Gitter Chat](https://badges.gitter.im/trailblazer/chat.svg)](https://gitter.im/trailblazer/chat)
6
+ [![TRB Newsletter](https://img.shields.io/badge/TRB-newsletter-lightgrey.svg)](http://trailblazer.to/newsletter/)
7
+ [![Build
8
+ Status](https://travis-ci.org/apotonick/cells.svg)](https://travis-ci.org/apotonick/cells)
9
+ [![Gem Version](https://badge.fury.io/rb/cells.svg)](http://badge.fury.io/rb/cells)
10
+
5
11
  ## Overview
6
12
 
7
13
  Cells allow you to encapsulate parts of your UI into components into _view models_. View models, or cells, are simple ruby classes that can render templates.
8
14
 
9
15
  Nevertheless, a cell gives you more than just a template renderer. They allow proper OOP, polymorphic builders, [nesting](#nested-cells), view inheritance, using Rails helpers, [asset packaging](http://trailblazer.to/gems/cells/rails.html#asset-pipeline) to bundle JS, CSS or images, simple distribution via gems or Rails engines, encapsulated testing, [caching](#caching), and [integrate with Trailblazer](#concept-cells).
10
16
 
11
- ## This is not Cells 3.x!
17
+ ## Full Documentation
12
18
 
13
- Temporary note: This is the README and API for Cells 4. Many things have improved. If you want to upgrade, [follow this guide](https://github.com/apotonick/cells/wiki/From-Cells-3-to-Cells-4---Upgrading-Guide). When in trouble, join us on the IRC (Freenode) #trailblazer channel.
19
+ Cells is part of the Trailblazer framework. [Full documentation](http://trailblazer.to/gems/cells) is available on the project site.
14
20
 
21
+ Cells is completely decoupled from Rails. However, Rails-specific functionality is to be found [here](http://trailblazer.to/gems/cells/rails.html).
15
22
 
16
23
  ## Rendering Cells
17
24
 
@@ -184,7 +191,8 @@ gem 'cells', "~> 4.0.0"
184
191
  Various template engines are supported but need to be added to your Gemfile.
185
192
 
186
193
  * [cells-erb](https://github.com/trailblazer/cells-erb)
187
- * [cells-haml](https://github.com/trailblazer/cells-haml) Make sure to bundle Haml 4.1: `gem "haml", github: "haml/haml", ref: "7c7c169"`.
194
+ * [cells-hamlit](https://github.com/trailblazer/cells-hamlit) We strongly recommend using [Hamlit](https://github.com/k0kubun/hamlit) as a Haml replacement.
195
+ * [cells-haml](https://github.com/trailblazer/cells-haml) Make sure to bundle Haml 4.1: `gem "haml", github: "haml/haml", ref: "7c7c169"`. Use `cells-hamlit` instead.
188
196
  * [cells-slim](https://github.com/trailblazer/cells-slim)
189
197
 
190
198
  ```ruby
@@ -195,25 +203,10 @@ In Rails, this is all you need to do. In other environments, you need to include
195
203
 
196
204
  ```ruby
197
205
  class CommentCell < Cell::ViewModel
198
- include ::Cell::Erb # or Cell::Haml, or Cell::Slim
206
+ include ::Cell::Erb # or Cell::Hamlit, or Cell::Haml, or Cell::Slim
199
207
  end
200
208
  ```
201
209
 
202
- ## Generators
203
-
204
- In Rails, you can generate cells and concept cells.
205
-
206
- ```shell
207
- rails generate cell comment
208
- ```
209
-
210
- Or.
211
-
212
- ```shell
213
- rails generate concept comment
214
- ```
215
-
216
-
217
210
  ## Concept Cells
218
211
 
219
212
  To have real self-contained cells you should use the new _concept cell_ which follows the [Trailblazer](http://trailblazerb.org) naming style. Concept cells need to be derived from `Cell::Concept`, sit in a namespace and are usually named `Cell`.
@@ -370,33 +363,7 @@ This works both in cell views and on the instance, in states.
370
363
 
371
364
  ## View Inheritance
372
365
 
373
- Cells can inherit code from each other with Ruby's inheritance.
374
-
375
- ```ruby
376
- class CommentCell < Cell::ViewModel
377
- end
378
-
379
- class PostCell < CommentCell
380
- end
381
- ```
382
-
383
- Even cooler, `PostCell` will now inherit views from `CommentCell`.
384
-
385
- ```ruby
386
- PostCell.prefixes #=> ["app/cells/post", "app/cells/comment"]
387
- ```
388
-
389
- When views can be found in the local `post` directory, they will be looked up in `comment`. This starts to become helpful when using [composed cells](#nested-cells).
390
-
391
- If you only want to inherit views, not the entire class, use `::inherit_views`.
392
-
393
- ```ruby
394
- class PostCell < Cell::ViewModel
395
- inherit_views Comment::Cell
396
- end
397
-
398
- PostCell.prefixes #=> ["app/cells/post", "app/cells/comment"]
399
- ```
366
+ You can not only inherit code across cell classes, but also views. This is extremely helpful if you want to override parts of your UI, only. It's [documented here](http://trailblazer.to/gems/cells/api.html#view-inheritance).
400
367
 
401
368
  ## Collections
402
369
 
@@ -407,7 +374,7 @@ comments = Comment.all #=> three comments.
407
374
  cell(:comment, collection: comments)
408
375
  ```
409
376
 
410
- This will invoke `cell(:comment, song).()` three times and concatenate the rendered output automatically. In case you don't want `show` but another state rendered, use `:method`.
377
+ 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, use `:method`.
411
378
 
412
379
  ```ruby
413
380
  cell(:comment, collection: comments, method: :list)
@@ -457,7 +424,6 @@ For every cell class you can define caching per state. Without any configuration
457
424
  ```ruby
458
425
  class CommentCell < Cell::ViewModel
459
426
  cache :show
460
-
461
427
  # ..
462
428
  end
463
429
  ```
@@ -468,20 +434,12 @@ The `::cache` method will forward options to the caching engine.
468
434
  cache :show, expires_in: 10.minutes
469
435
  ```
470
436
 
471
- You can also compute your own cache key, use dynamic keys, cache tags, and so on.
472
-
473
- ```ruby
474
- cache :show { |model, options| "comment/#{model.id}/#{model.updated_at}" }
475
- cache :show, :if => lambda { |*| has_changed? }
476
- cache :show, :tags: lambda { |model, options| "comment-#{model.id}" }
477
- ```
478
-
479
- Caching is documented [here](http://trailblazer.to/gems/cells/caching.html) and in chapter 8 of the [Trailblazer book](http://leanpub.com/trailblazer).
437
+ You can also compute your own cache key, use dynamic keys, cache tags, and conditionals using `:if`. Caching is documented [here](http://trailblazer.to/gems/cells/api.html#caching) and in chapter 8 of the [Trailblazer book](http://leanpub.com/trailblazer).
480
438
 
481
439
 
482
440
  ## The Book
483
441
 
484
- Cells is part of the [Trailblazer project](https://github.com/apotonick/trailblazer). Please [buy my book](https://leanpub.com/trailblazer) to support the development and to learn all the cool stuff about Cells. The book discusses the following.
442
+ Cells is part of the [Trailblazer project](https://github.com/apotonick/trailblazer). Please [buy my book](https://leanpub.com/trailblazer) to support the development and to learn all the cool stuff about Cells. The book discusses many use cases of Cells.
485
443
 
486
444
  <a href="https://leanpub.com/trailblazer">
487
445
  ![](https://raw.githubusercontent.com/apotonick/trailblazer/master/doc/trb.jpg)
@@ -493,39 +451,11 @@ Cells is part of the [Trailblazer project](https://github.com/apotonick/trailbla
493
451
  * Cells Pagination with AJAX (chapter 6).
494
452
  * View Caching and Expiring (chapter 8).
495
453
 
496
- More chapters are coming.
497
-
498
454
  The book picks up where the README leaves off. Go grab a copy and support us - it talks about object- and view design and covers all aspects of the API.
499
455
 
456
+ ## This is not Cells 3.x!
500
457
 
501
- ## Undocumented Features
502
-
503
- *(Please don't read this section!)*
504
-
505
- ### Rendering Global Partials
506
-
507
- Although not recommended, you can also render global partials from a cell. Be warned, though, that they will be rendered using our stack, and you might have to include helpers into your view model.
508
-
509
- This works by including `Partial` and the corresponding `:partial` option.
510
-
511
- ```ruby
512
- class Cell < Cell::ViewModel
513
- include Partial
514
-
515
- def show
516
- render partial: "../views/shared/map.html" # app/views/shared/map.html.haml
517
- end
518
- ```
519
-
520
- The provided path is relative to your cell's `::view_paths` directory. The format has to be added to the file name, the template engine suffix will be used from the cell.
521
-
522
- You can provide the format in the `render` call, too.
523
-
524
- ```ruby
525
- render partial: "../views/shared/map", formats: [:html]
526
- ```
527
-
528
- This was mainly added to provide compatibility with 3rd-party gems like [Kaminari and Cells](https://github.com/apotonick/kaminari-cells) that rely on rendering partials within a cell.
458
+ Temporary note: This is the README and API for Cells 4. Many things have improved. If you want to upgrade, [follow this guide](https://github.com/apotonick/cells/wiki/From-Cells-3-to-Cells-4---Upgrading-Guide). When in trouble, join us on the IRC (Freenode) #trailblazer channel.
529
459
 
530
460
  ## LICENSE
531
461
 
@@ -0,0 +1,37 @@
1
+ require 'bundler/setup'
2
+ require 'benchmark/ips'
3
+ require "cells"
4
+ require 'cell/view_model'
5
+
6
+ class ACell < Cell::ViewModel
7
+ def show
8
+ ""
9
+ end
10
+ end
11
+
12
+ class ACellWithBuilder < Cell::ViewModel
13
+ include Cell::Builder
14
+
15
+ def show
16
+ ""
17
+ end
18
+ end
19
+
20
+ Benchmark.ips do |x|
21
+ x.report("ACell") { ACell.().() }
22
+ x.report("ACellWithBuilder") { ACellWithBuilder.().() }
23
+ x.compare!
24
+ end
25
+
26
+ __END__
27
+
28
+ Calculating -------------------------------------
29
+ ACell 25.710k i/100ms
30
+ ACellWithBuilder 19.948k i/100ms
31
+ -------------------------------------------------
32
+ ACell 419.631k (± 5.0%) i/s - 2.108M
33
+ ACellWithBuilder 291.924k (± 5.7%) i/s - 1.476M
34
+
35
+ Comparison:
36
+ ACell: 419630.8 i/s
37
+ ACellWithBuilder: 291923.5 i/s - 1.44x slower
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+ require 'benchmark'
3
+ require 'benchmark/ips'
4
+
5
+ Song = Struct.new(:title)
6
+
7
+
8
+ class SongCell < Cell::ViewModel
9
+ self.view_paths = ['test/fixtures']
10
+ property :title
11
+
12
+ def show
13
+ render
14
+ end
15
+ end
16
+
17
+ ary = 1000.times.collect { |i| Song.new(i) }
18
+
19
+ Benchmark.ips do |x|
20
+ x.report("collection, call") { SongCell.(collection: ary).() }
21
+ x.report("collection, join") { SongCell.(collection: ary).join { |cell, i| cell.() } }
22
+ # x.report("collection, joinstr") { SongCell.(collection: ary).joinstr { |cell, i| cell.() } }
23
+ # x.report("collection, joincollect") { SongCell.(collection: ary).joincollect { |cell, i| cell.() } }
24
+ # x.report("ACellWithBuilder") { ACellWithBuilder.().() }
25
+ x.compare!
26
+ end
27
+
28
+ __END__
29
+
30
+ Calculating -------------------------------------
31
+ collection, call 3.000 i/100ms
32
+ collection, join 3.000 i/100ms
33
+ -------------------------------------------------
34
+ collection, call 33.403 (± 3.0%) i/s - 168.000
35
+ collection, join 33.248 (± 3.0%) i/s - 168.000
36
+
37
+ Comparison:
38
+ collection, call: 33.4 i/s
39
+ collection, join: 33.2 i/s - 1.00x slower
40
+
41
+
42
+
43
+ Comparison:
44
+ collection, join: 32.8 i/s
45
+ collection, call: 32.6 i/s - 1.01x slower
46
+ collection, joinstr: 32.6 i/s - 1.01x slower
47
+ collection, joincollect: 32.4 i/s - 1.01x slower # each_with_index.collect.join
@@ -1,7 +1,7 @@
1
- lib = File.expand_path('../lib/', __FILE__)
1
+ lib = File.expand_path("../lib/", __FILE__)
2
2
  $:.unshift lib unless $:.include?(lib)
3
3
 
4
- require 'cell/version'
4
+ require "cell/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "cells"
@@ -12,19 +12,17 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = "https://github.com/apotonick/cells"
13
13
  spec.summary = %q{View Models for Ruby and Rails.}
14
14
  spec.description = %q{Cells replaces partials and helpers with OOP view models, giving you proper encapsulation, inheritance, testability and a cleaner view architecture.}
15
- spec.license = 'MIT'
15
+ spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files`.split("\n")
18
18
  spec.test_files = `git ls-files -- {test}/*`.split("\n")
19
19
  spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "uber", "~> 0.0.9"
23
- spec.add_dependency 'tilt', '>= 1.4', '< 3'
22
+ spec.add_dependency "uber", ">= 0.0.9"
23
+ spec.add_dependency "tilt", ">= 1.4", "< 3"
24
24
 
25
25
  spec.add_development_dependency "rake"
26
- spec.add_development_dependency "minitest-reporters"
27
26
  spec.add_development_dependency "capybara"
28
-
29
27
  spec.add_development_dependency "cells-erb", ">= 0.0.4"
30
28
  end
@@ -4,13 +4,8 @@ require "uber/delegates"
4
4
  require "cell/version"
5
5
 
6
6
  module Cell
7
- autoload :TestCase, "cell/test_case"
8
7
  autoload :Testing, "cell/testing"
9
8
 
10
- def self.rails_version
11
- Gem::Version.new(ActionPack::VERSION::STRING)
12
- end
13
-
14
9
  class TemplateMissingError < RuntimeError
15
10
  def initialize(prefixes, view)
16
11
  super("Template missing: view: `#{view.to_s}` prefixes: #{prefixes.inspect}")
@@ -19,10 +14,7 @@ module Cell
19
14
  end
20
15
 
21
16
  require "cell/caching"
22
- require "cell/caching/notification"
23
- require "uber/builder"
24
17
  require "cell/prefixes"
25
- require "cell/self_contained"
26
18
  require "cell/layout"
27
19
  require "cell/templates"
28
20
  require "cell/abstract"
@@ -30,6 +22,5 @@ require "cell/util"
30
22
  require "cell/view_model"
31
23
  require "cell/concept"
32
24
  require "cell/escaped"
33
-
34
-
35
- require "cell/railtie" if defined?(Rails)
25
+ require "cell/builder"
26
+ require "cell/collection"