Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
### Unreleased
* Add tests with Rails 7.2 and 8.0
* Add tests with Ruby 3.4
* Add tests with Ruby 3.4 and 4.0
* Drop support for Ruby < 3.2
* Curly::Presenter#dependencies now return an Array instead of a SortedSet. Entries in this array will still be sorted.
* Drops dependency on sorted_set

### Curly 3.4.0 (July 2, 2024)
* Drop upper limit on Rails, test with Rails main.
Expand Down
1 change: 0 additions & 1 deletion curly-templates.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Gem::Specification.new do |s|
s.required_ruby_version = ">= 3.2"

s.add_dependency("actionpack", ">= 6.1")
s.add_dependency("sorted_set")

s.add_development_dependency("rake")
s.add_development_dependency("rspec", ">= 3")
Expand Down
6 changes: 0 additions & 6 deletions gemfiles/rails6.1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
curly-templates (3.4.0)
actionpack (>= 6.1)
sorted_set

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -147,7 +146,6 @@ GEM
rake (>= 12.2)
thor (~> 1.0)
rake (13.1.0)
rbtree (0.4.6)
redcarpet (3.6.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand All @@ -170,10 +168,6 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
set (1.0.3)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down
6 changes: 0 additions & 6 deletions gemfiles/rails7.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
curly-templates (3.4.0)
actionpack (>= 6.1)
sorted_set

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -153,7 +152,6 @@ GEM
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.1.0)
rbtree (0.4.6)
redcarpet (3.6.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand All @@ -176,10 +174,6 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
set (1.0.3)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
stackprof (0.2.25)
thor (1.3.0)
timeout (0.4.1)
Expand Down
6 changes: 0 additions & 6 deletions gemfiles/rails7.1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
curly-templates (3.4.0)
actionpack (>= 6.1)
sorted_set

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -178,7 +177,6 @@ GEM
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.1.0)
rbtree (0.4.6)
rdoc (6.6.0)
psych (>= 4.0.0)
redcarpet (3.6.0)
Expand All @@ -205,10 +203,6 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
set (1.0.3)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
stackprof (0.2.25)
stringio (3.0.9)
thor (1.3.0)
Expand Down
8 changes: 1 addition & 7 deletions gemfiles/rails7.2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
curly-templates (3.4.0)
actionpack (>= 6.1)
sorted_set

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -176,7 +175,6 @@ GEM
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.2.1)
rbtree (0.4.6)
rdoc (6.10.0)
psych (>= 4.0.0)
redcarpet (3.6.0)
Expand Down Expand Up @@ -204,10 +202,6 @@ GEM
rspec-support (~> 3.13)
rspec-support (3.13.2)
securerandom (0.4.1)
set (1.1.1)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
stackprof (0.2.26)
stringio (3.1.2)
thor (1.3.2)
Expand Down Expand Up @@ -243,4 +237,4 @@ DEPENDENCIES
yard-tomdoc

BUNDLED WITH
2.5.17
4.0.3
8 changes: 1 addition & 7 deletions gemfiles/rails8.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PATH
specs:
curly-templates (3.4.0)
actionpack (>= 6.1)
sorted_set

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -176,7 +175,6 @@ GEM
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rake (13.2.1)
rbtree (0.4.6)
rdoc (6.10.0)
psych (>= 4.0.0)
redcarpet (3.6.0)
Expand Down Expand Up @@ -204,10 +202,6 @@ GEM
rspec-support (~> 3.13)
rspec-support (3.13.2)
securerandom (0.4.1)
set (1.1.1)
sorted_set (1.0.3)
rbtree
set (~> 1.0)
stackprof (0.2.26)
stringio (3.1.2)
thor (1.3.2)
Expand Down Expand Up @@ -244,4 +238,4 @@ DEPENDENCIES
yard-tomdoc

BUNDLED WITH
2.5.17
4.0.3
19 changes: 9 additions & 10 deletions lib/curly/presenter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'curly/presenter_name_error'
require "sorted_set"

module Curly

Expand Down Expand Up @@ -246,23 +245,23 @@ def available_components
# Posts::ShowPresenter.dependencies
# #=> ['posts/comment', 'posts/comment_form']
#
# Returns a Set of String view paths.
# Returns an Array of sorted view paths.
def dependencies
# The base presenter doesn't have any dependencies.
return SortedSet.new if self == Curly::Presenter
return [] if self == Curly::Presenter

@dependencies ||= SortedSet.new
@dependencies.union(superclass.dependencies)
@dependencies ||= []
@dependencies = @dependencies.union(superclass.dependencies).uniq.sort
end

# Indicate that the presenter depends a list of other views.
# Indicate that the presenter depends on a list of other views.
#
# deps - A list of String view paths that the presenter depends on.
# dependencies - A list of String view paths that the presenter depends on.
#
# Returns nothing.
# Returns updated Array of String view paths.
def depends_on(*dependencies)
@dependencies ||= SortedSet.new
@dependencies.merge(dependencies)
@dependencies ||= []
@dependencies = @dependencies.union(dependencies).uniq.sort
end

# Get or set the version of the presenter.
Expand Down
32 changes: 31 additions & 1 deletion spec/presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,29 @@ class SubNestedPresenter < Curly::Presenter
expect(cache_key).to eq "Foo::BarPresenter/42/Foo::BumPresenter/1337"
end

it "includes the cache keys of all presenters in the dependency list" do
presenter = Class.new(Curly::Presenter) do
version 42
depends_on 'foo/bum'
depends_on 'foo/aum'
end

dependency = Class.new(Curly::Presenter) do
version 1337
end

dependency_2 = Class.new(Curly::Presenter) do
version 1338
end

stub_const("Foo::BarPresenter", presenter)
stub_const("Foo::BumPresenter", dependency)
stub_const("Foo::AumPresenter", dependency_2)

cache_key = Foo::BarPresenter.cache_key
expect(cache_key).to eq "Foo::BarPresenter/42/Foo::AumPresenter/1338/Foo::BumPresenter/1337"
end

it "uses the view path of a dependency if there is no presenter for it" do
presenter = Class.new(Curly::Presenter) do
version 42
Expand All @@ -249,7 +272,14 @@ class SubNestedPresenter < Curly::Presenter
Curly::Presenter.dependencies
parent = Class.new(Curly::Presenter) { depends_on 'foo' }
presenter = Class.new(parent) { depends_on 'bar' }
expect(presenter.dependencies.to_a).to match_array ['foo', 'bar']
expect(presenter.dependencies).to eq ['bar', 'foo']
end

it "doesn’t include duplicates" do
Curly::Presenter.dependencies
parent = Class.new(Curly::Presenter) { depends_on 'foo' }
presenter = Class.new(parent) { depends_on 'bar'; depends_on 'foo' }
expect(presenter.dependencies).to eq ['bar', 'foo']
end
end
end