Skip to content

Commit

Permalink
Merge pull request #10 from Tonksthebear/allow_nested_component_sidec…
Browse files Browse the repository at this point in the history
…ar_yaml

Nested ViewComponent Sidecar Assets
  • Loading branch information
Tonksthebear authored Jan 29, 2022
2 parents 398cc6c + b510acd commit 8fcb1fb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
Binary file removed classy-yaml-0.8.0.gem
Binary file not shown.
Binary file added classy-yaml-0.8.5.gem
Binary file not shown.
8 changes: 5 additions & 3 deletions lib/classy/yaml/component_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ module Classy
module Yaml
module ComponentHelpers
def yass(*args)
component_name = self.class.source_location.split("/").last.split(".").first
calling_path = self.class.source_location.split("/")[0...-1].join("/")
classy_file = if Dir.exist?("#{calling_path}/#{component_name}")
"#{calling_path}/#{component_name}/#{component_name}.yml"
calling_file = self.class.source_location.split("/").last.split(".").first
component_name = self.class.name.underscore.split("/").last.split(".").first

classy_file = if Dir.exist?("#{calling_path}/#{calling_file}")
"#{calling_path}/#{calling_file}/#{component_name}.yml"
else
"#{calling_path}/#{component_name}.yml"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/classy/yaml/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Classy
module Yaml
VERSION = '0.8.0'
VERSION = '0.8.5'
end
end
10 changes: 10 additions & 0 deletions test/classy/yaml_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,14 @@ class Classy::YamlComponentTest < ViewComponent::TestCase
assert_text "inherited"
end

test "can find nested component utility classes" do
render_inline(TestComponent::NestedComponent.new classy: :nested)
assert_text "nested"
end

test "can find nested component utility classes through inherited function call" do
render_inline(TestComponent::NestedComponent.new classy: :nested_inherited, inherited: true)
assert_text "nested-inherited"
end

end
6 changes: 6 additions & 0 deletions test/dummy/app/components/test_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ class TestComponent < ApplicationComponent
def call
@inherited ? inherited_call : yass(@classy)
end

class NestedComponent < TestComponent
def call
@inherited ? inherited_call : yass(@classy)
end
end
end
2 changes: 2 additions & 0 deletions test/dummy/app/components/test_component/nested_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nested: "nested"
nested_inherited: "nested-inherited"

0 comments on commit 8fcb1fb

Please sign in to comment.