cells 2.3.0

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/CHANGES ADDED
@@ -0,0 +1,30 @@
1
+ - 2.3
2
+ * Cell::Base#new(controller, opts={})
3
+ We got rid of the second argument cell_name, since it was completely useless.
4
+ * when a state view couldn't be found there's no longer a warning message, but an exception.
5
+ * moved Cell::Base to lib/cell/base.rb
6
+ * moved Rails extension code to lib/rails_extensions.rb
7
+ * removed all the boot code since we don't need it anymore
8
+
9
+
10
+ - trunk
11
+ * Remove dependency on Engines
12
+ * Improved support for helpers
13
+
14
+ - cells-1.0
15
+ * view rendering rewritten, we now use a separate ActionView::Base instance
16
+ that fixes bug #1
17
+ * introduced view inheritance, so derived cells inherit view files from their
18
+ superclass
19
+ * introduced automatic view file finding, Cell::Base#path is no longer needed
20
+ * added support for helpers in cell views
21
+ * removed Cell::Registry in favor or a new cells autoloading mechanism
22
+
23
+ - zells-0.1
24
+ * partly fixed bug #1 where cell instance variables could not be accessed
25
+ when calling #render_cell under special circumstances
26
+ * added lots of tests
27
+ * tests use #assert_select now
28
+
29
+ - zells-0.1-rc1
30
+ * first release into an unsuspecting world
data/README ADDED
@@ -0,0 +1,150 @@
1
+ = Overview
2
+
3
+ Cells are like controllers in Rails - they have methods and corresponding views.
4
+ However, their big advantage to controllers is their <em>modularity</em>: you can have
5
+ as many cells on a page as you want. That's as if you had multiple controllers in one
6
+ page, where each "controller" renders only a certain part of the page.
7
+ As if this wasn't enough, cells are superfast and lightweight.
8
+
9
+ They perfectly work together with AJAX/JavaScript, but also run fine without it,
10
+ Michael.
11
+
12
+ == Give me code!
13
+
14
+ To quickly create the necessary files for an example cell run the generator:
15
+
16
+ script/generate cell Article newest top_article
17
+
18
+
19
+ The generated cell class located in <tt>app/cells/article_cell.rb</tt> could look like
20
+ this, after some editing:
21
+
22
+ class ArticleCell < Cell::Base
23
+ helper :my_formatting_and_escaping_helper # you can use helpers in cell views!
24
+
25
+ def newest
26
+ @articles = Article.get_newest
27
+ render # will render the view named newest.html.[erb|haml|...]".
28
+ end
29
+
30
+ def top_article
31
+ @article = Article.top_article
32
+ render :view => :top_article_v2, # renders top_article_v2.html.[erb|haml|...]
33
+ :layout => :box # and put it in the layout "box.html".
34
+ end
35
+ end
36
+
37
+ The corresponding views are in <tt>app/cells/article/newest.html.erb</tt>:
38
+
39
+ <h2>Hot stuff!</h2>
40
+ <ul>
41
+ <% @articles.each do |article| %>
42
+ <li><%= article.title %></li>
43
+ <% end %>
44
+ </ul>
45
+
46
+ The other view would be in <tt>app/cells/article/top_article_v2.html.haml</tt>:
47
+
48
+ %h2
49
+ = @article.title
50
+ = format_and_escape(@article.text)
51
+
52
+ You already know that from controllers, don't you? Speaking of controllers, here's
53
+ how you could plug the cells into the page. In <tt>app/controllers/blog_controller.rb</tt>
54
+ there could be an action
55
+
56
+ class BlogController < ApplicationController
57
+ def top_page
58
+ ...
59
+ end
60
+ end
61
+
62
+ where the rendered action view could be <tt>app/views/blog/top_page.html.erb</tt>:
63
+
64
+ <%= yield %>
65
+
66
+ <div><%= render_cell(:article, :newest) %></div>
67
+ <div><%= render_cell(:article, :top_article) %></div>
68
+
69
+ The "top page" would consist of the controller action's content, and two additional
70
+ independent boxes with interesting content. These two boxes are <em>cells</em> and could
71
+ be used on another page, too.
72
+
73
+ = Caching
74
+
75
+ To improve performance rendered state views can be cached using Rails' caching mechanism.
76
+ If this it configured (e.g. using our fast friend memcached) all you have to do is to
77
+ tell Cells which state you want to cache. You can further attach a proc for deciding
78
+ versions or to instruct re-rendering.
79
+
80
+ cache :my_cached_state, Proc.new{|cell| Version.for(User.find(1)}
81
+
82
+ This would result in re-rendering the state <tt>:my_cached_state</tt> only if the
83
+ version of the user instance changes.
84
+
85
+ = Compatibility with other rails plugins
86
+
87
+ Cells uses the rails rendering code and thus stays completely compatible with (most?) plugins.
88
+
89
+ === I18N
90
+
91
+ All of Rails' new i18n features work with Cells. For example
92
+
93
+ t("Translate me, I'm a lonesome string in a cell state view!")
94
+
95
+ from the i18n helper can also be used in cell views.
96
+
97
+ === Haml
98
+
99
+ Alternative templating engines will work seamlessly with Cells, too. Usem the markup language
100
+ of your choice (.erb, .haml, ...) to write your cell views.
101
+
102
+ === Engines
103
+
104
+ You can even put cells in plugins and thus maximize the modularity of your code.
105
+ As soon as the plugin has an app/cells/ directory your cells will be added automatically
106
+ and can be used everywhere in your application.
107
+
108
+ = Installation
109
+
110
+ To install, simply cd to your rails app directory and run
111
+
112
+ script/plugin install git://github.com/apotonick/cells.git
113
+
114
+ This release is tested and runs with Rails 2.3.
115
+
116
+
117
+ = Documentation
118
+
119
+ Reference documentation is found in the documentation of the Cell::Base class.
120
+
121
+ See http://cells.rubyforge.org for documentation targeted at cells
122
+ newbies, including an overview of what you can do with cells and a
123
+ tutorial.
124
+
125
+ = LICENSE
126
+
127
+ Copyright (c) 2007-2009, Nick Sutterer
128
+
129
+ Copyright (c) 2007-2008, Solide ICT by Peter Bex and Bob Leers
130
+
131
+ The MIT License
132
+
133
+ Permission is hereby granted, free of charge, to any person obtaining a copy
134
+ of this software and associated documentation files (the "Software"), to deal
135
+ in the Software without restriction, including without limitation the rights
136
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
137
+ copies of the Software, and to permit persons to whom the Software is
138
+ furnished to do so, subject to the following conditions:
139
+
140
+ The above copyright notice and this permission notice shall be included in
141
+ all copies or substantial portions of the Software.
142
+
143
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
144
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
145
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
146
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
147
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
148
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
149
+ THE SOFTWARE.
150
+
data/README.rdoc ADDED
@@ -0,0 +1,150 @@
1
+ = Overview
2
+
3
+ Cells are like controllers in Rails - they have methods and corresponding views.
4
+ However, their big advantage to controllers is their <em>modularity</em>: you can have
5
+ as many cells on a page as you want. That's as if you had multiple controllers in one
6
+ page, where each "controller" renders only a certain part of the page.
7
+ As if this wasn't enough, cells are superfast and lightweight.
8
+
9
+ They perfectly work together with AJAX/JavaScript, but also run fine without it,
10
+ Michael.
11
+
12
+ == Give me code!
13
+
14
+ To quickly create the necessary files for an example cell run the generator:
15
+
16
+ script/generate cell Article newest top_article
17
+
18
+
19
+ The generated cell class located in <tt>app/cells/article_cell.rb</tt> could look like
20
+ this, after some editing:
21
+
22
+ class ArticleCell < Cell::Base
23
+ helper :my_formatting_and_escaping_helper # you can use helpers in cell views!
24
+
25
+ def newest
26
+ @articles = Article.get_newest
27
+ render # will render the view named newest.html.[erb|haml|...]".
28
+ end
29
+
30
+ def top_article
31
+ @article = Article.top_article
32
+ render :view => :top_article_v2, # renders top_article_v2.html.[erb|haml|...]
33
+ :layout => :box # and put it in the layout "box.html".
34
+ end
35
+ end
36
+
37
+ The corresponding views are in <tt>app/cells/article/newest.html.erb</tt>:
38
+
39
+ <h2>Hot stuff!</h2>
40
+ <ul>
41
+ <% @articles.each do |article| %>
42
+ <li><%= article.title %></li>
43
+ <% end %>
44
+ </ul>
45
+
46
+ The other view would be in <tt>app/cells/article/top_article_v2.html.haml</tt>:
47
+
48
+ %h2
49
+ = @article.title
50
+ = format_and_escape(@article.text)
51
+
52
+ You already know that from controllers, don't you? Speaking of controllers, here's
53
+ how you could plug the cells into the page. In <tt>app/controllers/blog_controller.rb</tt>
54
+ there could be an action
55
+
56
+ class BlogController < ApplicationController
57
+ def top_page
58
+ ...
59
+ end
60
+ end
61
+
62
+ where the rendered action view could be <tt>app/views/blog/top_page.html.erb</tt>:
63
+
64
+ <%= yield %>
65
+
66
+ <div><%= render_cell(:article, :newest) %></div>
67
+ <div><%= render_cell(:article, :top_article) %></div>
68
+
69
+ The "top page" would consist of the controller action's content, and two additional
70
+ independent boxes with interesting content. These two boxes are <em>cells</em> and could
71
+ be used on another page, too.
72
+
73
+ = Caching
74
+
75
+ To improve performance rendered state views can be cached using Rails' caching mechanism.
76
+ If this it configured (e.g. using our fast friend memcached) all you have to do is to
77
+ tell Cells which state you want to cache. You can further attach a proc for deciding
78
+ versions or to instruct re-rendering.
79
+
80
+ cache :my_cached_state, Proc.new{|cell| Version.for(User.find(1)}
81
+
82
+ This would result in re-rendering the state <tt>:my_cached_state</tt> only if the
83
+ version of the user instance changes.
84
+
85
+ = Compatibility with other rails plugins
86
+
87
+ Cells uses the rails rendering code and thus stays completely compatible with (most?) plugins.
88
+
89
+ === I18N
90
+
91
+ All of Rails' new i18n features work with Cells. For example
92
+
93
+ t("Translate me, I'm a lonesome string in a cell state view!")
94
+
95
+ from the i18n helper can also be used in cell views.
96
+
97
+ === Haml
98
+
99
+ Alternative templating engines will work seamlessly with Cells, too. Usem the markup language
100
+ of your choice (.erb, .haml, ...) to write your cell views.
101
+
102
+ === Engines
103
+
104
+ You can even put cells in plugins and thus maximize the modularity of your code.
105
+ As soon as the plugin has an app/cells/ directory your cells will be added automatically
106
+ and can be used everywhere in your application.
107
+
108
+ = Installation
109
+
110
+ To install, simply cd to your rails app directory and run
111
+
112
+ script/plugin install git://github.com/apotonick/cells.git
113
+
114
+ This release is tested and runs with Rails 2.3.
115
+
116
+
117
+ = Documentation
118
+
119
+ Reference documentation is found in the documentation of the Cell::Base class.
120
+
121
+ See http://cells.rubyforge.org for documentation targeted at cells
122
+ newbies, including an overview of what you can do with cells and a
123
+ tutorial.
124
+
125
+ = LICENSE
126
+
127
+ Copyright (c) 2007-2009, Nick Sutterer
128
+
129
+ Copyright (c) 2007-2008, Solide ICT by Peter Bex and Bob Leers
130
+
131
+ The MIT License
132
+
133
+ Permission is hereby granted, free of charge, to any person obtaining a copy
134
+ of this software and associated documentation files (the "Software"), to deal
135
+ in the Software without restriction, including without limitation the rights
136
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
137
+ copies of the Software, and to permit persons to whom the Software is
138
+ furnished to do so, subject to the following conditions:
139
+
140
+ The above copyright notice and this permission notice shall be included in
141
+ all copies or substantial portions of the Software.
142
+
143
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
144
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
145
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
146
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
147
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
148
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
149
+ THE SOFTWARE.
150
+
data/Rakefile ADDED
@@ -0,0 +1,77 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ NAME = "cells"
6
+ SUMMARY = %{Cells are lightweight controllers for Rails and can be rendered in controllers and views, providing an elegant and fast way for encapsulation and component-orientation.}
7
+ HOMEPAGE = "http://cells.rubyforge.org"
8
+ AUTHORS = ["Nick Sutterer"]
9
+ EMAIL = "apotonick@gmail.com"
10
+ SUPPORT_FILES = %w[README CHANGES]
11
+
12
+ desc 'Default: run unit tests.'
13
+ task :default => :test
14
+
15
+ desc 'Test the cells plugin.'
16
+ Rake::TestTask.new(:test) do |t|
17
+ t.libs << 'lib'
18
+ t.pattern = 'test/**/*_test.rb'
19
+ t.verbose = true
20
+ end
21
+
22
+ desc 'Generate documentation for the cells plugin.'
23
+ Rake::RDocTask.new(:rdoc) do |rdoc|
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = 'Cells Documentation'
26
+ rdoc.options << '--line-numbers' << '--inline-source'
27
+ rdoc.rdoc_files.include('README')
28
+ rdoc.rdoc_files.include('init.rb')
29
+ rdoc.rdoc_files.include('lib/**/*.rb')
30
+ end
31
+
32
+ # rdoc -m "README.rdoc" init.rb lib/ generators/ README.rdoc
33
+
34
+ # Gem managment tasks.
35
+ #
36
+ # == Bump gem version (any):
37
+ #
38
+ # rake version:bump:major
39
+ # rake version:bump:minor
40
+ # rake version:bump:patch
41
+ #
42
+ # == Generate gemspec, build & install locally:
43
+ #
44
+ # rake gemspec
45
+ # rake build
46
+ # sudo rake install
47
+ #
48
+ # == Git tag & push to origin/master
49
+ #
50
+ # rake release
51
+ #
52
+ # == Release to Gemcutter.org:
53
+ #
54
+ # rake gemcutter:release
55
+ #
56
+ begin
57
+ gem 'jeweler'
58
+ require 'jeweler'
59
+ Jeweler::Tasks.new do |gemspec|
60
+ gemspec.name = NAME
61
+ gemspec.summary = SUMMARY
62
+ gemspec.description = SUMMARY
63
+ gemspec.homepage = HOMEPAGE
64
+ gemspec.authors = AUTHORS
65
+ gemspec.email = EMAIL
66
+
67
+ gemspec.require_paths = %w{lib}
68
+ gemspec.files = FileList["[A-Z]*", File.join(*%w[{generators,lib} ** *]).to_s, "init.rb"]
69
+ gemspec.extra_rdoc_files = SUPPORT_FILES
70
+
71
+ # gemspec.add_dependency 'activesupport', '>= 2.3.0' # Dependencies and minimum versions?
72
+ end
73
+ Jeweler::GemcutterTasks.new
74
+ rescue LoadError
75
+ puts "Jeweler - or one of its dependencies - is not available. " <<
76
+ "Install it with: sudo gem install jeweler -s http://gemcutter.org"
77
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -0,0 +1,26 @@
1
+ Description:
2
+ Stubs out a new cell and its views. Pass the cell name, either
3
+ CamelCased or under_scored, and a list of views as arguments.
4
+
5
+ This generates a cell class in app/cells and view templates in
6
+ app/cells/cell_name.
7
+
8
+ Examples:
9
+
10
+ ./script/generate cell Announcements index
11
+
12
+ This will create an Announcements cell:
13
+ Cell:
14
+ app/cells/announcements_cell.rb
15
+ Views:
16
+ app/cells/announcements/index.html.erb
17
+
18
+
19
+ ./script/generate cell Articles popular recent --haml
20
+
21
+ This will create an Articles cell:
22
+ Cell:
23
+ app/cells/articles_cell.rb
24
+ Views:
25
+ app/cells/articles/popular.html.haml
26
+ app/cells/articles/recent.html.haml
@@ -0,0 +1,48 @@
1
+ require 'rails_generator/generators/components/controller/controller_generator'
2
+
3
+ class CellGenerator < ControllerGenerator
4
+
5
+ attr_reader :template_type
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ super
9
+ @template_type = options[:haml] ? :haml : :erb
10
+ end
11
+
12
+ def manifest
13
+ record do |m|
14
+ # Check for class naming collisions.
15
+ m.class_collisions class_path, "#{class_name}Cell"
16
+
17
+ # Directories
18
+ m.directory File.join('app/cells', class_path)
19
+ m.directory File.join('app/cells', class_path, file_name)
20
+
21
+ # Cell
22
+ m.template 'cell.rb', File.join('app/cells', class_path, "#{file_name}_cell.rb")
23
+
24
+ # View template for each action.
25
+ actions.each do |action|
26
+ path = File.join('app/cells', class_path, file_name, "#{action}.html.#{template_type}")
27
+ m.template "view.html.#{template_type}", path,
28
+ :assigns => { :action => action, :path => path }
29
+ end
30
+ end
31
+ end
32
+
33
+ def add_options!(opt)
34
+ opt.separator ''
35
+ opt.separator 'Options:'
36
+
37
+ # Allow option to generate HAML views instead of ERB.
38
+ opt.on('--haml',
39
+ "Generate HAML output instead of the default ERB.") do |v|
40
+ options[:haml] = v
41
+ end
42
+ end
43
+
44
+ def banner
45
+ "Usage: #{$0} cell NAME a_view another_view ... [--haml]"
46
+ end
47
+
48
+ end