cells 3.11.3 → 4.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +15 -13
- data/Appraisals +23 -0
- data/CHANGES.md +20 -3
- data/Gemfile +5 -7
- data/README.md +317 -236
- data/Rakefile +1 -1
- data/TODO.md +3 -0
- data/cells.gemspec +19 -28
- data/gemfiles/rails3.2.gemfile +14 -0
- data/gemfiles/rails4.0.gemfile +14 -0
- data/gemfiles/rails4.1.gemfile +15 -0
- data/gemfiles/rails4.2.gemfile +14 -0
- data/lib/cell.rb +28 -21
- data/lib/cell/caching.rb +10 -22
- data/lib/cell/caching/notification.rb +15 -0
- data/lib/cell/concept.rb +4 -69
- data/lib/cell/development.rb +11 -0
- data/lib/{cells → cell}/engines.rb +1 -1
- data/lib/cell/layout.rb +20 -0
- data/lib/cell/partial.rb +17 -0
- data/lib/cell/{base/prefixes.rb → prefixes.rb} +1 -1
- data/lib/cell/rails.rb +58 -50
- data/lib/cell/railtie.rb +60 -0
- data/lib/cell/{base/self_contained.rb → self_contained.rb} +1 -1
- data/lib/cell/templates.rb +60 -0
- data/lib/cell/test_case.rb +4 -162
- data/lib/cell/testing.rb +15 -0
- data/lib/cell/twin.rb +11 -29
- data/lib/cell/version.rb +10 -0
- data/lib/cell/view_model.rb +196 -88
- data/lib/cells.rb +1 -20
- data/lib/rails/generators/cell/cell_generator.rb +43 -0
- data/lib/rails/generators/cell/templates/cell.rb.erb +8 -0
- data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.erb +0 -0
- data/lib/{generators/templates/concept → rails/generators/cell/templates}/view.haml +0 -0
- data/lib/rails/generators/cell/templates/view.slim +2 -0
- data/lib/rails/generators/concept/concept_generator.rb +38 -0
- data/lib/{generators/templates/concept/cell.rb → rails/generators/concept/templates/concept.rb.erb} +2 -2
- data/lib/{generators → rails/generators/concept}/templates/view.erb +0 -0
- data/lib/{generators → rails/generators/concept}/templates/view.haml +0 -0
- data/lib/rails/generators/concept/templates/view.slim +2 -0
- data/lib/rails/generators/test_unit/cell/cell_generator.rb +21 -0
- data/lib/{generators/templates/cell_test.rb → rails/generators/test_unit/cell/templates/unit_test.rb.erb} +3 -3
- data/lib/rails/generators/test_unit/concept/concept_generator.rb +21 -0
- data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +11 -0
- data/lib/{cells → tasks}/cells.rake +0 -0
- data/test/builder_test.rb +58 -0
- data/test/caching_test.rb +298 -0
- data/test/cell_benchmark.rb +32 -0
- data/test/cell_generator_test.rb +51 -82
- data/test/cell_test.rb +8 -23
- data/test/concept_generator_test.rb +22 -13
- data/test/concept_test.rb +41 -75
- data/test/dummy/app/views/musician/hamlet.html.erb +1 -0
- data/test/dummy/config/application.rb +21 -8
- data/test/{app/cells/bassist/play.html.erb → fixtures/bassist/play.erb} +0 -0
- data/test/fixtures/concepts/record/views/layout.erb +1 -0
- data/test/{app → fixtures}/concepts/record/views/show.erb +0 -0
- data/test/{app → fixtures}/concepts/record/views/song.erb +0 -0
- data/test/fixtures/inherit_views_test/popper/tap.erb +1 -0
- data/test/fixtures/inherit_views_test/tapper/play.erb +1 -0
- data/test/fixtures/inherit_views_test/tapper/tap.erb +1 -0
- data/test/fixtures/partial_test/with_partial/show.erb +1 -0
- data/test/fixtures/partials/_show.html.erb +1 -0
- data/test/fixtures/partials/_show.xml.erb +1 -0
- data/test/fixtures/song/ivar.erb +1 -0
- data/test/fixtures/song/show.erb +1 -0
- data/test/fixtures/song/with_erb.erb +4 -0
- data/test/fixtures/song/with_html.erb +1 -0
- data/test/fixtures/song/with_locals.erb +2 -0
- data/test/fixtures/song_with_layout/happy.erb +1 -0
- data/test/fixtures/song_with_layout/merry.erb +1 -0
- data/test/fixtures/song_with_layout/show.erb +1 -0
- data/test/fixtures/song_with_layout/show_with_layout.erb +1 -0
- data/test/fixtures/templates_caching_test/song/show.erb +1 -0
- data/test/fixtures/url_helper_test/song/edit.erb +8 -0
- data/test/fixtures/url_helper_test/song/with_block.erb +2 -0
- data/test/fixtures/url_helper_test/song/with_capture.erb +4 -0
- data/test/fixtures/url_helper_test/song/with_content_tag.erb +6 -0
- data/test/fixtures/url_helper_test/song/with_form_for_block.erb +3 -0
- data/test/fixtures/url_helper_test/song/with_link_to.erb +3 -0
- data/test/layout_test.rb +57 -0
- data/test/partial_test.rb +27 -0
- data/test/prefixes_test.rb +36 -10
- data/test/public_test.rb +42 -0
- data/test/rails_extensions_test.rb +51 -0
- data/test/render_test.rb +103 -0
- data/test/templates_test.rb +45 -0
- data/test/test_case_test.rb +21 -122
- data/test/test_helper.rb +37 -33
- data/test/twin_test.rb +3 -7
- data/test/url_helper_test.rb +89 -0
- metadata +92 -357
- data/gemfiles/Gemfile.rails3-0 +0 -7
- data/gemfiles/Gemfile.rails3-1 +0 -7
- data/gemfiles/Gemfile.rails3-2 +0 -7
- data/gemfiles/Gemfile.rails4-0 +0 -12
- data/gemfiles/Gemfile.rails4-1 +0 -12
- data/lib/cell/base.rb +0 -82
- data/lib/cell/base/view.rb +0 -15
- data/lib/cell/builder.rb +0 -71
- data/lib/cell/deprecations.rb +0 -41
- data/lib/cell/dsl.rb +0 -7
- data/lib/cell/rack.rb +0 -32
- data/lib/cell/rails/helper_api.rb +0 -37
- data/lib/cell/rails/view_model.rb +0 -159
- data/lib/cell/rails3_0_strategy.rb +0 -82
- data/lib/cell/rails3_1_strategy.rb +0 -40
- data/lib/cell/rails4_0_strategy.rb +0 -39
- data/lib/cell/rails4_1_strategy.rb +0 -40
- data/lib/cell/rendering.rb +0 -109
- data/lib/cells/rails.rb +0 -86
- data/lib/cells/railtie.rb +0 -38
- data/lib/cells/version.rb +0 -3
- data/lib/generators/USAGE +0 -30
- data/lib/generators/cells/base.rb +0 -22
- data/lib/generators/cells/cell_generator.rb +0 -15
- data/lib/generators/cells/view_generator.rb +0 -18
- data/lib/generators/erb/cell_generator.rb +0 -15
- data/lib/generators/erb/concept_generator.rb +0 -17
- data/lib/generators/haml/cell_generator.rb +0 -17
- data/lib/generators/haml/concept_generator.rb +0 -17
- data/lib/generators/rails/cell_generator.rb +0 -16
- data/lib/generators/rails/concept_generator.rb +0 -16
- data/lib/generators/slim/cell_generator.rb +0 -17
- data/lib/generators/templates/cell.rb +0 -9
- data/lib/generators/templates/view.slim +0 -4
- data/lib/generators/test_unit/cell_generator.rb +0 -14
- data/lib/generators/trailblazer/base.rb +0 -21
- data/lib/generators/trailblazer/view_generator.rb +0 -18
- data/test/app/cells/album/views/cover.haml +0 -1
- data/test/app/cells/bad_guitarist/_dii.html.erb +0 -1
- data/test/app/cells/bad_guitarist_cell.rb +0 -2
- data/test/app/cells/bassist/_dii.html.erb +0 -1
- data/test/app/cells/bassist/ahem.html.erb +0 -1
- data/test/app/cells/bassist/compose.html.erb +0 -1
- data/test/app/cells/bassist/contact_form.html.erb +0 -1
- data/test/app/cells/bassist/form_for.erb +0 -3
- data/test/app/cells/bassist/form_for_in_haml.haml +0 -2
- data/test/app/cells/bassist/jam.html.erb +0 -3
- data/test/app/cells/bassist/play.js.erb +0 -1
- data/test/app/cells/bassist/pose.html.erb +0 -1
- data/test/app/cells/bassist/promote.html.erb +0 -1
- data/test/app/cells/bassist/provoke.html.erb +0 -1
- data/test/app/cells/bassist/shout.html.erb +0 -1
- data/test/app/cells/bassist/sing.html.haml +0 -1
- data/test/app/cells/bassist/slap.html.erb +0 -1
- data/test/app/cells/bassist/yell.en.html.erb +0 -1
- data/test/app/cells/bassist_cell.rb +0 -25
- data/test/app/cells/club_security.rb +0 -2
- data/test/app/cells/club_security/guard/help.html.erb +0 -1
- data/test/app/cells/club_security/guard_cell.rb +0 -6
- data/test/app/cells/club_security/medic/help.html.erb +0 -1
- data/test/app/cells/club_security/medic_cell.rb +0 -8
- data/test/app/cells/layouts/b.erb +0 -1
- data/test/app/cells/layouts/metal.html.erb +0 -1
- data/test/app/cells/rails_helper_api_test/bassist/edit.html.erb +0 -5
- data/test/app/cells/shouter/sing.html.erb +0 -1
- data/test/app/cells/song/dashboard.haml +0 -7
- data/test/app/cells/song/details.html.haml +0 -1
- data/test/app/cells/song/info.html.haml +0 -1
- data/test/app/cells/song/lyrics.html.haml +0 -6
- data/test/app/cells/song/plays.haml +0 -1
- data/test/app/cells/song/scale.haml +0 -1
- data/test/app/cells/song/show.html.haml +0 -3
- data/test/app/cells/song/title.html.haml +0 -1
- data/test/app/cells/trumpeter/promote.html.erb +0 -1
- data/test/app/cells/trumpeter_cell.rb +0 -8
- data/test/app/cells/view_model_test/comments/show.haml +0 -7
- data/test/app/concepts/record/views/layout.haml +0 -2
- data/test/app/views/shared/_dong.html.erb +0 -1
- data/test/cell_module_test.rb +0 -170
- data/test/cells_module_test.rb +0 -27
- data/test/deprecations_test.rb +0 -101
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/views/musician/hamlet.html.haml +0 -1
- data/test/dummy/config/environments/development.rb +0 -16
- data/test/dummy/config/environments/production.rb +0 -46
- data/test/dummy/config/environments/test.rb +0 -33
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/label/app/cells/label/show.erb +0 -1
- data/test/dummy/label/app/cells/label_cell.rb +0 -5
- data/test/dummy/label/label.gemspec +0 -20
- data/test/dummy/label/lib/label.rb +0 -4
- data/test/dummy/label/lib/label/version.rb +0 -3
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/stylesheets/.gitkeep +0 -0
- data/test/helper_test.rb +0 -81
- data/test/rack_test.rb +0 -32
- data/test/rails/asset_pipeline_test.rb +0 -20
- data/test/rails/caching_test.rb +0 -456
- data/test/rails/cells_test.rb +0 -119
- data/test/rails/forms_test.rb +0 -75
- data/test/rails/integration_test.rb +0 -299
- data/test/rails/render_test.rb +0 -189
- data/test/rails/view_model_test.rb +0 -226
- data/test/rails/view_test.rb +0 -49
- data/test/rails_helper_api_test.rb +0 -58
- data/test/self_contained_test.rb +0 -31
@@ -1,82 +0,0 @@
|
|
1
|
-
# This file contains VersionStrategies for the Cell and Cells module for Rails 3.0.
|
2
|
-
module Cell
|
3
|
-
Layouts = AbstractController::Layouts
|
4
|
-
|
5
|
-
# Methods to be included in Cell::Rails in 3.0 context, where there's no view inheritance.
|
6
|
-
module VersionStrategy
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
class MissingTemplate < ActionView::ActionViewError
|
10
|
-
def initialize(message, possible_paths)
|
11
|
-
super(message + " and possible paths #{possible_paths}")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
module ClassMethods
|
17
|
-
def helper_modules
|
18
|
-
[_helpers, _routes.url_helpers]
|
19
|
-
end
|
20
|
-
|
21
|
-
# Return the default view path for +state+. Override this if you cell has a differing naming style.
|
22
|
-
def view_for_state(state)
|
23
|
-
"#{cell_name}/#{state}"
|
24
|
-
end
|
25
|
-
|
26
|
-
# Returns all possible view paths for +state+ by invoking #view_for_state on all classes up
|
27
|
-
# the inheritance chain.
|
28
|
-
def find_class_view_for_state(state)
|
29
|
-
return [view_for_state(state)] if superclass.abstract?
|
30
|
-
|
31
|
-
superclass.find_class_view_for_state(state) << view_for_state(state)
|
32
|
-
end
|
33
|
-
|
34
|
-
def cell_name
|
35
|
-
controller_path
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
# Computes all possible paths for +state+ by traversing up the inheritance chain.
|
41
|
-
def possible_paths_for_state(state)
|
42
|
-
self.class.find_class_view_for_state(state).reverse!
|
43
|
-
end
|
44
|
-
|
45
|
-
# Climbs up the inheritance chain, looking for a view for the current +state+.
|
46
|
-
def find_family_view_for_state(state)
|
47
|
-
exception = nil
|
48
|
-
possible_paths = possible_paths_for_state(state)
|
49
|
-
|
50
|
-
possible_paths.each do |template_path|
|
51
|
-
begin
|
52
|
-
template = find_template(template_path)
|
53
|
-
return template if template
|
54
|
-
rescue ::ActionView::MissingTemplate => exception
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
raise MissingTemplate.new(exception.message, possible_paths)
|
59
|
-
end
|
60
|
-
|
61
|
-
def process_opts_for(opts, state)
|
62
|
-
lookup_context.formats = opts.delete(:format) if opts[:format]
|
63
|
-
|
64
|
-
opts[:template] = find_family_view_for_state(opts.delete(:view) || state)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
module Cells
|
71
|
-
module Engines
|
72
|
-
module VersionStrategy
|
73
|
-
def registered_engines
|
74
|
-
::Rails.application.railties.engines
|
75
|
-
end
|
76
|
-
|
77
|
-
def existent_directories_for(path)
|
78
|
-
path.to_a.select { |d| File.directory?(d) }
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# This file contains VersionStrategies for the Cell and Cells module for Rails >= 3.1.
|
2
|
-
module Cell
|
3
|
-
Layouts = AbstractController::Layouts
|
4
|
-
|
5
|
-
# Methods to be included in Cell::Rails in 3.1 context.
|
6
|
-
module VersionStrategy
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
include AbstractController::UrlFor # must be included before _routes is set in Railstie. # TODO: remove that.
|
10
|
-
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
def helper_modules
|
14
|
-
[_routes.url_helpers, _routes.mounted_helpers, _helpers]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def process_opts_for(opts, state)
|
20
|
-
opts[:action] = opts[:view] || state
|
21
|
-
|
22
|
-
lookup_context.formats = [opts.delete(:format)] if opts[:format]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
module Cells
|
29
|
-
module Engines
|
30
|
-
module VersionStrategy
|
31
|
-
def registered_engines
|
32
|
-
::Rails.application.railties.engines
|
33
|
-
end
|
34
|
-
|
35
|
-
def existent_directories_for(path)
|
36
|
-
path.existent_directories
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Cell
|
2
|
-
Layouts = AbstractController::Layouts
|
3
|
-
|
4
|
-
# Methods to be included in Cell::Rails in 3.1 context.
|
5
|
-
module VersionStrategy
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
include AbstractController::UrlFor # must be included before _routes is set in Railstie. # TODO: remove that.
|
9
|
-
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
def helper_modules
|
13
|
-
[_routes.url_helpers, _routes.mounted_helpers, _helpers]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
def process_opts_for(opts, state)
|
19
|
-
opts[:action] = opts[:view] || state
|
20
|
-
|
21
|
-
lookup_context.formats = [opts.delete(:format)] if opts[:format]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
module Cells
|
28
|
-
module Engines
|
29
|
-
module VersionStrategy
|
30
|
-
def registered_engines
|
31
|
-
::Rails::Engine::Railties.engines
|
32
|
-
end
|
33
|
-
|
34
|
-
def existent_directories_for(path)
|
35
|
-
path.existent_directories
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# This file contains VersionStrategies for the Cell and Cells module for Rails >= 3.1.
|
2
|
-
module Cell
|
3
|
-
Layouts = ActionView::Layouts
|
4
|
-
|
5
|
-
# Methods to be included in Cell::Rails in 3.1 context.
|
6
|
-
module VersionStrategy
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
include AbstractController::UrlFor # must be included before _routes is set in Railstie. # TODO: remove that.
|
10
|
-
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
def helper_modules
|
14
|
-
[_routes.url_helpers, _routes.mounted_helpers, _helpers]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def process_opts_for(opts, state)
|
20
|
-
opts[:action] = opts[:view] || state
|
21
|
-
|
22
|
-
lookup_context.formats = [opts.delete(:format)] if opts[:format]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
module Cells
|
29
|
-
module Engines
|
30
|
-
module VersionStrategy
|
31
|
-
def registered_engines
|
32
|
-
::Rails::Engine::Railties.new
|
33
|
-
end
|
34
|
-
|
35
|
-
def existent_directories_for(path)
|
36
|
-
path.existent_directories
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/cell/rendering.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
module Cell
|
2
|
-
module Rendering
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
# Invoke the state method for +state+ which usually renders something nice.
|
6
|
-
def render_state(state, *args)
|
7
|
-
process(state, *args)
|
8
|
-
end
|
9
|
-
|
10
|
-
# Renders the view for the current state and returns the markup.
|
11
|
-
# Don't forget to return the markup itself from the state method.
|
12
|
-
#
|
13
|
-
# === Options
|
14
|
-
# +:view+:: Specifies the name of the view file to render. Defaults to the current state name.
|
15
|
-
# +:layout+:: Renders the state wrapped in the layout. Layouts reside in <tt>app/cells/layouts</tt>.
|
16
|
-
# +:locals+:: Makes the named parameters available as variables in the view.
|
17
|
-
# +:text+:: Just renders plain text.
|
18
|
-
# +:inline+:: Renders an inline template as state view. See ActionView::Base#render for details.
|
19
|
-
# +:file+:: Specifies the name of the file template to render.
|
20
|
-
# +:nothing+:: Doesn't invoke the rendering process.
|
21
|
-
# +:state+:: Instantly invokes another rendering cycle for the passed state and returns. You may pass arbitrary state-args to the called state.
|
22
|
-
# +:format+:: Sets a different template format, e.g. +:json+. Use this option with caution as it currently modifies the global format variable. This might lead to unexpected subsequent render behaviour due to a design flaw in Rails.
|
23
|
-
#
|
24
|
-
# Example:
|
25
|
-
# class MusicianCell < ::Cell::Base
|
26
|
-
# def sing
|
27
|
-
# # ... laalaa
|
28
|
-
# render
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# renders the view <tt>musician/sing.html</tt>.
|
32
|
-
#
|
33
|
-
# def sing
|
34
|
-
# # ... laalaa
|
35
|
-
# render :view => :shout, :layout => 'metal'
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
# renders <tt>musician/shout.html</tt> and wrap it in <tt>app/cells/layouts/metal.html.erb</tt>.
|
39
|
-
#
|
40
|
-
# === #render is explicit!
|
41
|
-
# You can also alter the markup from #render. Just remember to return it.
|
42
|
-
#
|
43
|
-
# def sing
|
44
|
-
# render + render + render
|
45
|
-
# end
|
46
|
-
#
|
47
|
-
# will render three concated views.
|
48
|
-
#
|
49
|
-
# === Partials?
|
50
|
-
#
|
51
|
-
# In Cells we abandoned the term 'partial' in favor of plain 'views' - we don't need to distinguish
|
52
|
-
# between both terms. A cell view is both, a view and a kind of partial as it represents only a fragment
|
53
|
-
# of the page.
|
54
|
-
#
|
55
|
-
# Just use <tt>:view</tt> and enjoy.
|
56
|
-
#
|
57
|
-
# === Using states instead of helpers
|
58
|
-
#
|
59
|
-
# Sometimes it's useful to not only render a view but also invoke the associated state. This is
|
60
|
-
# especially helpful when replacing helpers. Do that with <tt>render :state</tt>.
|
61
|
-
#
|
62
|
-
# def show_cheap_item(item)
|
63
|
-
# render if item.price <= 1
|
64
|
-
# end
|
65
|
-
#
|
66
|
-
# A view could use this state in place of an odd helper.
|
67
|
-
#
|
68
|
-
# - @items.each do |item|
|
69
|
-
# = render({:state => :show_cheap_item}, item)
|
70
|
-
#
|
71
|
-
# This calls the state method which in turn will render its view - if the item isn't too expensive.
|
72
|
-
def render(*args)
|
73
|
-
render_view_for(self.action_name, *args)
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
# Renders the view belonging to the given state. Will raise ActionView::MissingTemplate
|
78
|
-
# if it can't find a view.
|
79
|
-
def render_view_for(state, *args)
|
80
|
-
opts = args.first.is_a?(::Hash) ? args.shift : {}
|
81
|
-
|
82
|
-
return "" if opts[:nothing]
|
83
|
-
|
84
|
-
if opts[:state]
|
85
|
-
opts[:text] = render_state(opts.delete(:state), *args)
|
86
|
-
elsif (opts.keys & [:text, :inline, :file]).blank?
|
87
|
-
process_opts_for(opts, state)
|
88
|
-
end
|
89
|
-
|
90
|
-
render_to_string(opts).html_safe # ActionView::Template::Text doesn't do that for us.
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
module ClassMethods
|
95
|
-
# Main entry point for #render_cell.
|
96
|
-
def render_cell_for(name, state, *args)
|
97
|
-
cell = cell_for(name, *args)
|
98
|
-
yield cell if block_given?
|
99
|
-
|
100
|
-
render_cell_state(cell, state, *args)
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
def render_cell_state(cell, state, *args)
|
105
|
-
cell.render_state(state, *args)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
data/lib/cells/rails.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# These Methods are automatically added to all Controllers and Views when
|
2
|
-
# the cells plugin is loaded.
|
3
|
-
module Cells
|
4
|
-
module Rails
|
5
|
-
module ActionController
|
6
|
-
def cell_for(name, *args, &block)
|
7
|
-
return Cell::Rails::ViewModel.cell(name, self, *args, &block) if args.first.is_a?(Hash) and args.first[:collection] # FIXME: we only want this feature in view models for now.
|
8
|
-
::Cell::Base.cell_for(name, self, *args, &block)
|
9
|
-
end
|
10
|
-
alias_method :cell, :cell_for # DISCUSS: make this configurable?
|
11
|
-
|
12
|
-
def concept_for(name, *args, &block)
|
13
|
-
return Cell::Concept.cell(name, self, *args, &block)
|
14
|
-
end
|
15
|
-
alias_method :concept, :concept_for
|
16
|
-
|
17
|
-
# Renders the cell state and returns the content. You may pass options here, too. They will be
|
18
|
-
# around in @opts.
|
19
|
-
#
|
20
|
-
# Example:
|
21
|
-
#
|
22
|
-
# @box = render_cell(:posts, :latest, :user => current_user)
|
23
|
-
#
|
24
|
-
# If you need the cell instance before it renders, you can pass a block receiving the cell.
|
25
|
-
#
|
26
|
-
# Example:
|
27
|
-
#
|
28
|
-
# @box = render_cell(:comments, :top5) do |cell|
|
29
|
-
# cell.markdown! if config.parse_comments?
|
30
|
-
# end
|
31
|
-
def render_cell(name, state, *args, &block)
|
32
|
-
::Cell::Rails.render_cell_for(name, state, self, *args, &block)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Expires the cached cell state view, similar to ActionController::expire_fragment.
|
36
|
-
# Usually, this method is used in Sweepers.
|
37
|
-
# Beside the obvious first two args <tt>cell_name</tt> and <tt>state</tt> you can pass
|
38
|
-
# in additional cache key <tt>args</tt> and cache store specific <tt>opts</tt>.
|
39
|
-
#
|
40
|
-
# Example:
|
41
|
-
#
|
42
|
-
# class ListSweeper < ActionController::Caching::Sweeper
|
43
|
-
# observe List, Item
|
44
|
-
#
|
45
|
-
# def after_save(record)
|
46
|
-
# expire_cell_state :my_listing, :display_list
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# will expire the view for state <tt>:display_list</tt> in the cell <tt>MyListingCell</tt>.
|
50
|
-
def expire_cell_state(cell_class, state, args={}, opts=nil)
|
51
|
-
key = cell_class.state_cache_key(state, args)
|
52
|
-
cell_class.expire_cache_key(key, opts)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
module ActionView
|
57
|
-
# Returns the cell instance for +name+. You may pass arbitrary options to your
|
58
|
-
# cell.
|
59
|
-
#
|
60
|
-
# = cell(:song, :title => "Creeping Out Sara").render(:show)
|
61
|
-
def cell_for(name, *args, &block)
|
62
|
-
controller.cell_for(name, *args, &block)
|
63
|
-
end
|
64
|
-
alias_method :cell, :cell_for # DISCUSS: make this configurable?
|
65
|
-
|
66
|
-
# See Cells::Rails::ActionController#render_cell.
|
67
|
-
def render_cell(name, state, *args, &block)
|
68
|
-
::Cell::Rails.render_cell_for(name, state, controller, *args, &block)
|
69
|
-
end
|
70
|
-
|
71
|
-
def concept(name, *args, &block)
|
72
|
-
controller.concept_for(name, *args, &block)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Add extended ActionController behaviour.
|
79
|
-
ActionController::Base.class_eval do
|
80
|
-
include ::Cells::Rails::ActionController
|
81
|
-
end
|
82
|
-
|
83
|
-
# Add extended ActionView behaviour.
|
84
|
-
ActionView::Base.class_eval do
|
85
|
-
include ::Cells::Rails::ActionView
|
86
|
-
end
|
data/lib/cells/railtie.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require "rails/railtie"
|
2
|
-
|
3
|
-
module Cells
|
4
|
-
class Railtie < ::Rails::Railtie
|
5
|
-
config.cells = ActiveSupport::OrderedOptions.new
|
6
|
-
|
7
|
-
|
8
|
-
initializer "cells.attach_router" do |app|
|
9
|
-
Cell::Base.class_eval do
|
10
|
-
include app.routes.url_helpers # TODO: i hate this, make it better in Rails.
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
initializer "cells.setup_engines_view_paths" do |app|
|
15
|
-
Cells::Engines.append_engines_view_paths_for(app.config.action_controller)
|
16
|
-
end
|
17
|
-
|
18
|
-
# ruthlessly stolen from the zurb-foundation gem.
|
19
|
-
add_paths_block = lambda do |app|
|
20
|
-
(app.config.cells.with_assets or []).each do |name|
|
21
|
-
# FIXME: this doesn't take engine cells into account.
|
22
|
-
app.config.assets.paths << "#{app.root}/app/cells/#{name}/assets"
|
23
|
-
app.config.assets.paths << "#{app.root}/app/concepts/#{name}/assets" # TODO: find out type.
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Standard initializer
|
28
|
-
initializer 'cells.update_asset_paths', &add_paths_block
|
29
|
-
|
30
|
-
# run at assets:precompile even when `config.assets.initialize_on_precompile = false`
|
31
|
-
initializer 'cells.update_asset_paths', :group => :assets, &add_paths_block
|
32
|
-
|
33
|
-
|
34
|
-
rake_tasks do
|
35
|
-
load "cells/cells.rake"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/cells/version.rb
DELETED
data/lib/generators/USAGE
DELETED
@@ -1,30 +0,0 @@
|
|
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/ directory.
|
7
|
-
|
8
|
-
Examples:
|
9
|
-
|
10
|
-
rails g cell ShoppingCart index
|
11
|
-
|
12
|
-
This will create these cell assets:
|
13
|
-
Cell:
|
14
|
-
app/cells/shopping_cart_cell.rb
|
15
|
-
Views:
|
16
|
-
app/cells/shopping_cart/index.html.erb
|
17
|
-
Test:
|
18
|
-
test/cells/shopping_cart_cell_test.rb
|
19
|
-
|
20
|
-
|
21
|
-
rails g cell main_menu display sort -e haml -t rspec
|
22
|
-
|
23
|
-
This will create these cell assets:
|
24
|
-
Cell:
|
25
|
-
app/cells/main_menu_cell.rb
|
26
|
-
Views:
|
27
|
-
app/cells/main_menu/display.html.haml
|
28
|
-
app/cells/main_menu/sort.html.haml
|
29
|
-
Spec:
|
30
|
-
spec/cells/main_menu_cell_spec.rb
|