From 1500fddcc008f9d2b063679d6cad64836d13f0fc Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 25 Sep 2023 17:55:06 +0200 Subject: [PATCH 01/33] add: helper api --- lib/view_component/base.rb | 1 + lib/view_component/helpers_api.rb | 13 +++++++++++++ .../app/components/helpers_api_component.html.slim | 2 ++ .../sandbox/app/components/helpers_api_component.rb | 7 +++++++ test/sandbox/test/rendering_test.rb | 5 +++++ 5 files changed, 28 insertions(+) create mode 100644 lib/view_component/helpers_api.rb create mode 100644 test/sandbox/app/components/helpers_api_component.html.slim create mode 100644 test/sandbox/app/components/helpers_api_component.rb diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index 9dd3944af..187854699 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -12,6 +12,7 @@ require "view_component/slotable" require "view_component/translatable" require "view_component/with_content_helper" +require "view_component/helpers_api" module ViewComponent class Base < ActionView::Base diff --git a/lib/view_component/helpers_api.rb b/lib/view_component/helpers_api.rb new file mode 100644 index 000000000..40e2d3f2c --- /dev/null +++ b/lib/view_component/helpers_api.rb @@ -0,0 +1,13 @@ +module ViewComponent::HelpersApi + extend ActiveSupport::Concern + + class_methods do + def use_helper(*args) + args.each do |helper| + define_method helper do + self.helpers.send(helper) + end + end + end + end +end diff --git a/test/sandbox/app/components/helpers_api_component.html.slim b/test/sandbox/app/components/helpers_api_component.html.slim new file mode 100644 index 000000000..9509f5d29 --- /dev/null +++ b/test/sandbox/app/components/helpers_api_component.html.slim @@ -0,0 +1,2 @@ +.helper__message + = message diff --git a/test/sandbox/app/components/helpers_api_component.rb b/test/sandbox/app/components/helpers_api_component.rb new file mode 100644 index 000000000..fb257fd18 --- /dev/null +++ b/test/sandbox/app/components/helpers_api_component.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class HelpersApiComponent < ViewComponent::Base + include ViewComponent::HelpersApi + + use_helper :message +end diff --git a/test/sandbox/test/rendering_test.rb b/test/sandbox/test/rendering_test.rb index 2f5069ea4..03cf9f0b8 100644 --- a/test/sandbox/test/rendering_test.rb +++ b/test/sandbox/test/rendering_test.rb @@ -1094,4 +1094,9 @@ def test_content_security_policy_nonce assert_selector("script", text: "\n//\n", visible: :hidden) end + + def test_use_helper + render_inline(HelpersApiComponent.new) + assert_selector ".helper__message", text: "Hello helper method" + end end From 305a9523b1e19f58814484b141fd9e5018883302 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 25 Sep 2023 18:01:30 +0200 Subject: [PATCH 02/33] remove: redundant self --- lib/view_component/helpers_api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view_component/helpers_api.rb b/lib/view_component/helpers_api.rb index 40e2d3f2c..101f2c85f 100644 --- a/lib/view_component/helpers_api.rb +++ b/lib/view_component/helpers_api.rb @@ -5,7 +5,7 @@ module ViewComponent::HelpersApi def use_helper(*args) args.each do |helper| define_method helper do - self.helpers.send(helper) + helpers.send(helper) end end end From 11e3aefae315f50ff7d8bb24c84c79550c06a996 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 25 Sep 2023 21:09:17 +0200 Subject: [PATCH 03/33] add: args and block passthrough --- lib/view_component/helpers_api.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/view_component/helpers_api.rb b/lib/view_component/helpers_api.rb index 101f2c85f..be6f39fb1 100644 --- a/lib/view_component/helpers_api.rb +++ b/lib/view_component/helpers_api.rb @@ -4,8 +4,8 @@ module ViewComponent::HelpersApi class_methods do def use_helper(*args) args.each do |helper| - define_method helper do - helpers.send(helper) + define_method helper do |*args, &block| + helpers.send(helper, *args, &block) end end end From 903cd3edbeefbdf09880230390dfe586b0c6ef51 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 25 Sep 2023 21:10:00 +0200 Subject: [PATCH 04/33] add: changelog entry --- docs/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 25b43b91a..1d2df2a9c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,7 +13,9 @@ nav_order: 5 * Add Simundia to list of companies using ViewComponent. *Alexandre Ignjatovic* +* Add `use_helper` api + *Reegan Viljoen* ## 3.6.0 * Refer to `helpers` in `NameError` message in development and test environments. From b8bbde989177a4cadb9d73b99931f073efbb24c7 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 25 Sep 2023 21:16:58 +0200 Subject: [PATCH 05/33] Fix: markdown liniting errors --- docs/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1d2df2a9c..39359513f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -16,6 +16,7 @@ nav_order: 5 * Add `use_helper` api *Reegan Viljoen* + ## 3.6.0 * Refer to `helpers` in `NameError` message in development and test environments. From 39df32a4addb5806a79bf233bf8302d042785d84 Mon Sep 17 00:00:00 2001 From: Reegan Viljoen <62689748+reeganviljoen@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:50:07 +0200 Subject: [PATCH 06/33] Update lib/view_component/helpers_api.rb Co-authored-by: Cameron Dutro --- lib/view_component/helpers_api.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/view_component/helpers_api.rb b/lib/view_component/helpers_api.rb index be6f39fb1..33d8d30b7 100644 --- a/lib/view_component/helpers_api.rb +++ b/lib/view_component/helpers_api.rb @@ -1,13 +1,15 @@ -module ViewComponent::HelpersApi - extend ActiveSupport::Concern +# frozen_string_literal: true - class_methods do - def use_helper(*args) - args.each do |helper| - define_method helper do |*args, &block| - helpers.send(helper, *args, &block) - end +module ViewComponent::UseHelper + def use_helper(*args) + args.each do |helper_mtd| + class_eval(<<-RUBY, __FILE__, __LINE__ + 1) + def #{helper_mtd} do |*args, &block| + helpers.send(#{helper_mtd}, *args, &block) end + RUBY + + ruby2_keywords(helper_mtd) if respond_to?(:ruby2_keywords, true) end end end From d298203e9e8b07441d5db918031989a7717fac02 Mon Sep 17 00:00:00 2001 From: Reegan Viljoen <62689748+reeganviljoen@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:50:15 +0200 Subject: [PATCH 07/33] Update docs/CHANGELOG.md Co-authored-by: Cameron Dutro --- docs/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 39359513f..6d87e3cfe 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,7 @@ nav_order: 5 * Add Simundia to list of companies using ViewComponent. *Alexandre Ignjatovic* + * Add `use_helper` api *Reegan Viljoen* From b06db0453077ca5c7f57156785281a95d71a63dd Mon Sep 17 00:00:00 2001 From: Reegan Viljoen <62689748+reeganviljoen@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:50:24 +0200 Subject: [PATCH 08/33] Update test/sandbox/app/components/helpers_api_component.rb Co-authored-by: Cameron Dutro --- test/sandbox/app/components/helpers_api_component.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sandbox/app/components/helpers_api_component.rb b/test/sandbox/app/components/helpers_api_component.rb index fb257fd18..d3d5ebfb3 100644 --- a/test/sandbox/app/components/helpers_api_component.rb +++ b/test/sandbox/app/components/helpers_api_component.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -class HelpersApiComponent < ViewComponent::Base - include ViewComponent::HelpersApi +class UseHelperComponent < ViewComponent::Base + include ViewComponent::UseHelpers use_helper :message end From c467068044631d6111b20246d971e7f92d6642ed Mon Sep 17 00:00:00 2001 From: Reegan Viljoen <62689748+reeganviljoen@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:50:30 +0200 Subject: [PATCH 09/33] Update test/sandbox/test/rendering_test.rb Co-authored-by: Cameron Dutro --- test/sandbox/test/rendering_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sandbox/test/rendering_test.rb b/test/sandbox/test/rendering_test.rb index 03cf9f0b8..cd985beb6 100644 --- a/test/sandbox/test/rendering_test.rb +++ b/test/sandbox/test/rendering_test.rb @@ -1096,7 +1096,7 @@ def test_content_security_policy_nonce end def test_use_helper - render_inline(HelpersApiComponent.new) + render_inline(UseHelpersComponent.new) assert_selector ".helper__message", text: "Hello helper method" end end From 7bcc15fb9ede9fcb157b4915439d12a66d118c93 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Sat, 30 Sep 2023 22:53:24 +0200 Subject: [PATCH 10/33] refactor: use_helpers --- lib/view_component/base.rb | 2 +- lib/view_component/helpers_api.rb | 15 ----------- lib/view_component/use_helpers.rb | 25 +++++++++++++++++++ .../helpers_api_component.html.slim | 2 -- .../components/use_helpers_component.html.erb | 3 +++ ..._component.rb => use_helpers_component.rb} | 4 +-- 6 files changed, 31 insertions(+), 20 deletions(-) delete mode 100644 lib/view_component/helpers_api.rb create mode 100644 lib/view_component/use_helpers.rb delete mode 100644 test/sandbox/app/components/helpers_api_component.html.slim create mode 100644 test/sandbox/app/components/use_helpers_component.html.erb rename test/sandbox/app/components/{helpers_api_component.rb => use_helpers_component.rb} (50%) diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index 187854699..c83c1b728 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -12,7 +12,7 @@ require "view_component/slotable" require "view_component/translatable" require "view_component/with_content_helper" -require "view_component/helpers_api" +require "view_component/use_helpers" module ViewComponent class Base < ActionView::Base diff --git a/lib/view_component/helpers_api.rb b/lib/view_component/helpers_api.rb deleted file mode 100644 index 33d8d30b7..000000000 --- a/lib/view_component/helpers_api.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -module ViewComponent::UseHelper - def use_helper(*args) - args.each do |helper_mtd| - class_eval(<<-RUBY, __FILE__, __LINE__ + 1) - def #{helper_mtd} do |*args, &block| - helpers.send(#{helper_mtd}, *args, &block) - end - RUBY - - ruby2_keywords(helper_mtd) if respond_to?(:ruby2_keywords, true) - end - end -end diff --git a/lib/view_component/use_helpers.rb b/lib/view_component/use_helpers.rb new file mode 100644 index 000000000..8668354c6 --- /dev/null +++ b/lib/view_component/use_helpers.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module ViewComponent::UseHelpers + extend ActiveSupport::Concern + + class_methods do + def use_helpers(*args) + args.each do |helper_mtd| + class_eval(<<-RUBY, __FILE__, __LINE__ + 1) + def #{helper_mtd}(*args, &block) + raise HelpersCalledBeforeRenderError if view_context.nil? + + if __vc_original_view_context + __vc_original_view_context.send(#{helper_mtd.inspect}, *args, &block) + elsif controller.view_context + controller.view_context.send(#{helper_mtd.inspect}, *args, &block) + end + end + RUBY + + ruby2_keywords(helper_mtd) if respond_to?(:ruby2_keywords, true) + end + end + end +end diff --git a/test/sandbox/app/components/helpers_api_component.html.slim b/test/sandbox/app/components/helpers_api_component.html.slim deleted file mode 100644 index 9509f5d29..000000000 --- a/test/sandbox/app/components/helpers_api_component.html.slim +++ /dev/null @@ -1,2 +0,0 @@ -.helper__message - = message diff --git a/test/sandbox/app/components/use_helpers_component.html.erb b/test/sandbox/app/components/use_helpers_component.html.erb new file mode 100644 index 000000000..f24542007 --- /dev/null +++ b/test/sandbox/app/components/use_helpers_component.html.erb @@ -0,0 +1,3 @@ +
+ <%= message %> +
diff --git a/test/sandbox/app/components/helpers_api_component.rb b/test/sandbox/app/components/use_helpers_component.rb similarity index 50% rename from test/sandbox/app/components/helpers_api_component.rb rename to test/sandbox/app/components/use_helpers_component.rb index d3d5ebfb3..375c07db6 100644 --- a/test/sandbox/app/components/helpers_api_component.rb +++ b/test/sandbox/app/components/use_helpers_component.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -class UseHelperComponent < ViewComponent::Base +class UseHelpersComponent < ViewComponent::Base include ViewComponent::UseHelpers - use_helper :message + use_helpers :message end From 7052b36cdd55a48d11050548717becd2ddf87321 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Sun, 1 Oct 2023 19:39:31 +0200 Subject: [PATCH 11/33] refactor to use safe navigation --- lib/view_component/use_helpers.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/view_component/use_helpers.rb b/lib/view_component/use_helpers.rb index 8668354c6..254a04602 100644 --- a/lib/view_component/use_helpers.rb +++ b/lib/view_component/use_helpers.rb @@ -9,12 +9,7 @@ def use_helpers(*args) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) def #{helper_mtd}(*args, &block) raise HelpersCalledBeforeRenderError if view_context.nil? - - if __vc_original_view_context - __vc_original_view_context.send(#{helper_mtd.inspect}, *args, &block) - elsif controller.view_context - controller.view_context.send(#{helper_mtd.inspect}, *args, &block) - end + __vc_original_view_context&.send(#{helper_mtd.inspect}, *args, &block) || view_context.send(#{helper_mtd.inspect}, *args, &block) end RUBY From c5685508c74468d29c5e01ef88cd2ca624d818b7 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 23 Oct 2023 11:18:26 +0200 Subject: [PATCH 12/33] wip --- .tool-versions | 2 +- Gemfile.lock | 3 +++ gemfiles/rails_6.0.gemfile | 12 +++++++++++- gemfiles/rails_6.1.gemfile | 13 ++++++++++--- gemfiles/rails_7.0.gemfile | 12 +++++++++++- gemfiles/rails_head.gemfile | 12 +++++++++++- lib/view_component/test_helpers.rb | 18 +++++++++++++++++- .../components/use_helpers_component.html.erb | 2 +- .../app/components/use_helpers_component.rb | 2 +- test/sandbox/test/rendering_test.rb | 6 ++++-- 10 files changed, 70 insertions(+), 12 deletions(-) diff --git a/.tool-versions b/.tool-versions index 38ec15178..c23af94d4 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 3.0.3 +ruby 3.2.0 diff --git a/Gemfile.lock b/Gemfile.lock index df3b5d943..adbf593b9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -333,6 +333,9 @@ DEPENDENCIES jbuilder (~> 2) m (~> 1) minitest (~> 5.18) + net-imap + net-pop + net-smtp pry (~> 0.13) puma (~> 6) rails (~> 7.0.0) diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile index 837afbd05..e39568655 100644 --- a/gemfiles/rails_6.0.gemfile +++ b/gemfiles/rails_6.0.gemfile @@ -4,7 +4,17 @@ source "https://rubygems.org" gem "capybara", "~> 3" gem "rails", "~> 6.0.0" -gem "rspec-rails", "~> 5.1" +gem "rspec-rails", "~> 5" +gem "net-imap", require: false +gem "net-pop", require: false +gem "net-smtp", require: false +gem "debug" gem "tailwindcss-rails", "~> 2.0" +group :test do + gem "cuprite", "~> 0.8" + gem "puma", "~> 6" + gem "selenium-webdriver", "4.9.0" +end + gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index 4f68feb46..45f86074f 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -4,10 +4,17 @@ source "https://rubygems.org" gem "capybara", "~> 3" gem "rails", "~> 6.1.0" -gem "rspec-rails", "~> 5.1" -gem "tailwindcss-rails", "~> 2.0" -gem "net-smtp", require: false +gem "rspec-rails", "~> 5" gem "net-imap", require: false gem "net-pop", require: false +gem "net-smtp", require: false +gem "debug" +gem "tailwindcss-rails", "~> 2.0" + +group :test do + gem "cuprite", "~> 0.8" + gem "puma", "~> 6" + gem "selenium-webdriver", "4.9.0" +end gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index cfc057a56..323674fa3 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -4,7 +4,17 @@ source "https://rubygems.org" gem "capybara", "~> 3" gem "rails", "~> 7.0.0" -gem "rspec-rails", "~> 5.1" +gem "rspec-rails", "~> 5" +gem "net-imap", require: false +gem "net-pop", require: false +gem "net-smtp", require: false +gem "debug" gem "tailwindcss-rails", "~> 2.0" +group :test do + gem "cuprite", "~> 0.8" + gem "puma", "~> 6" + gem "selenium-webdriver", "4.9.0" +end + gemspec path: "../" diff --git a/gemfiles/rails_head.gemfile b/gemfiles/rails_head.gemfile index d187ac20e..231622d79 100644 --- a/gemfiles/rails_head.gemfile +++ b/gemfiles/rails_head.gemfile @@ -4,7 +4,17 @@ source "https://rubygems.org" gem "capybara", "~> 3" gem "rails", github: "rails/rails", branch: "main" -gem "rspec-rails", "~> 5.1" +gem "rspec-rails", "~> 5" +gem "net-imap", require: false +gem "net-pop", require: false +gem "net-smtp", require: false +gem "debug" gem "tailwindcss-rails", "~> 2.0" +group :test do + gem "cuprite", "~> 0.8" + gem "puma", "~> 6" + gem "selenium-webdriver", "4.9.0" +end + gemspec path: "../" diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb index 1cb733451..ac8ab73df 100644 --- a/lib/view_component/test_helpers.rb +++ b/lib/view_component/test_helpers.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true - +require 'debug' module ViewComponent module TestHelpers begin @@ -190,6 +190,22 @@ def with_request_url(path, host: nil) @vc_test_controller = old_controller end + def with_helpers(**kwargs) + kwargs.each do |helper_mthd_name, helper_mthd| + result = helper_mthd.call + vc_test_controller.view_context.class.class_eval(<<-RUBY.gsub(/\n/, ''), __FILE__, __LINE__ + 1) + def #{helper_mthd_name}(*args, &block) + binding.break + #{ result } + + end + RUBY + end + yield + ensure + # vc_test_controller.clear_helpers + end + # Access the controller used by `render_inline`: # # ```ruby diff --git a/test/sandbox/app/components/use_helpers_component.html.erb b/test/sandbox/app/components/use_helpers_component.html.erb index f24542007..47dd48973 100644 --- a/test/sandbox/app/components/use_helpers_component.html.erb +++ b/test/sandbox/app/components/use_helpers_component.html.erb @@ -1,3 +1,3 @@
- <%= message %> + <%= test_helper %>
diff --git a/test/sandbox/app/components/use_helpers_component.rb b/test/sandbox/app/components/use_helpers_component.rb index 375c07db6..209e937e2 100644 --- a/test/sandbox/app/components/use_helpers_component.rb +++ b/test/sandbox/app/components/use_helpers_component.rb @@ -3,5 +3,5 @@ class UseHelpersComponent < ViewComponent::Base include ViewComponent::UseHelpers - use_helpers :message + use_helpers :test_helper end diff --git a/test/sandbox/test/rendering_test.rb b/test/sandbox/test/rendering_test.rb index cd985beb6..144bba977 100644 --- a/test/sandbox/test/rendering_test.rb +++ b/test/sandbox/test/rendering_test.rb @@ -1096,7 +1096,9 @@ def test_content_security_policy_nonce end def test_use_helper - render_inline(UseHelpersComponent.new) - assert_selector ".helper__message", text: "Hello helper method" + with_helpers(test_helper: -> { "Hello helper method" }) do + render_inline(UseHelpersComponent.new) + assert_selector ".helper__message", text: "Hello helper method" + end end end From 9f0eafe05e785b445880d8b194276be01268be19 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 23 Oct 2023 21:58:24 +0200 Subject: [PATCH 13/33] add: with_helpers hellper --- lib/view_component/test_helpers.rb | 30 +++++++++++++++++++---------- test/sandbox/test/rendering_test.rb | 7 ++++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb index ac8ab73df..3319f5006 100644 --- a/lib/view_component/test_helpers.rb +++ b/lib/view_component/test_helpers.rb @@ -190,17 +190,27 @@ def with_request_url(path, host: nil) @vc_test_controller = old_controller end - def with_helpers(**kwargs) - kwargs.each do |helper_mthd_name, helper_mthd| - result = helper_mthd.call - vc_test_controller.view_context.class.class_eval(<<-RUBY.gsub(/\n/, ''), __FILE__, __LINE__ + 1) - def #{helper_mthd_name}(*args, &block) - binding.break - #{ result } - end - RUBY - end + # Set the controller helpers to be used while executing the given block, + # + # ```ruby + # with_helpers(UsersHelper) do + # render_inline(MyComponent.new) + # end + # ``` + # + # @param *args [Array] The helpers to be used. + def with_helpers(*args) + args.each do |helper_mthd| + vc_test_controller.class_eval(<<-RUBY, __FILE__, __LINE__ + 1) + def #{helper_mthd} + return #{return self.send(helper_mthd)} + end + + ruby2_keywords(:'#{helper_mthd}') + RUBY + vc_test_controller.class.helper_method helper_mthd + end yield ensure # vc_test_controller.clear_helpers diff --git a/test/sandbox/test/rendering_test.rb b/test/sandbox/test/rendering_test.rb index 144bba977..a806ad619 100644 --- a/test/sandbox/test/rendering_test.rb +++ b/test/sandbox/test/rendering_test.rb @@ -1096,9 +1096,14 @@ def test_content_security_policy_nonce end def test_use_helper - with_helpers(test_helper: -> { "Hello helper method" }) do + with_helpers(:test_helper) do render_inline(UseHelpersComponent.new) assert_selector ".helper__message", text: "Hello helper method" end end + + private + def test_helper + "Hello helper method" + end end From da9a8af0ed39aad8463f724ee1e9926c3d1119fb Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 23 Oct 2023 22:05:39 +0200 Subject: [PATCH 14/33] edit: cleanup --- gemfiles/rails_5.2.gemfile | 8 -------- gemfiles/rails_6.0.gemfile | 20 -------------------- gemfiles/rails_6.1.gemfile | 20 -------------------- gemfiles/rails_7.0.gemfile | 20 -------------------- gemfiles/rails_head.gemfile | 20 -------------------- lib/view_component/test_helpers.rb | 3 --- 6 files changed, 91 deletions(-) delete mode 100644 gemfiles/rails_5.2.gemfile delete mode 100644 gemfiles/rails_6.0.gemfile delete mode 100644 gemfiles/rails_6.1.gemfile delete mode 100644 gemfiles/rails_7.0.gemfile delete mode 100644 gemfiles/rails_head.gemfile diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile deleted file mode 100644 index 56ee0723f..000000000 --- a/gemfiles/rails_5.2.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "capybara", "~> 3" -gem "rails", "~> 5.2.0" - -gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile deleted file mode 100644 index e39568655..000000000 --- a/gemfiles/rails_6.0.gemfile +++ /dev/null @@ -1,20 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "capybara", "~> 3" -gem "rails", "~> 6.0.0" -gem "rspec-rails", "~> 5" -gem "net-imap", require: false -gem "net-pop", require: false -gem "net-smtp", require: false -gem "debug" -gem "tailwindcss-rails", "~> 2.0" - -group :test do - gem "cuprite", "~> 0.8" - gem "puma", "~> 6" - gem "selenium-webdriver", "4.9.0" -end - -gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile deleted file mode 100644 index 45f86074f..000000000 --- a/gemfiles/rails_6.1.gemfile +++ /dev/null @@ -1,20 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "capybara", "~> 3" -gem "rails", "~> 6.1.0" -gem "rspec-rails", "~> 5" -gem "net-imap", require: false -gem "net-pop", require: false -gem "net-smtp", require: false -gem "debug" -gem "tailwindcss-rails", "~> 2.0" - -group :test do - gem "cuprite", "~> 0.8" - gem "puma", "~> 6" - gem "selenium-webdriver", "4.9.0" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile deleted file mode 100644 index 323674fa3..000000000 --- a/gemfiles/rails_7.0.gemfile +++ /dev/null @@ -1,20 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "capybara", "~> 3" -gem "rails", "~> 7.0.0" -gem "rspec-rails", "~> 5" -gem "net-imap", require: false -gem "net-pop", require: false -gem "net-smtp", require: false -gem "debug" -gem "tailwindcss-rails", "~> 2.0" - -group :test do - gem "cuprite", "~> 0.8" - gem "puma", "~> 6" - gem "selenium-webdriver", "4.9.0" -end - -gemspec path: "../" diff --git a/gemfiles/rails_head.gemfile b/gemfiles/rails_head.gemfile deleted file mode 100644 index 231622d79..000000000 --- a/gemfiles/rails_head.gemfile +++ /dev/null @@ -1,20 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "capybara", "~> 3" -gem "rails", github: "rails/rails", branch: "main" -gem "rspec-rails", "~> 5" -gem "net-imap", require: false -gem "net-pop", require: false -gem "net-smtp", require: false -gem "debug" -gem "tailwindcss-rails", "~> 2.0" - -group :test do - gem "cuprite", "~> 0.8" - gem "puma", "~> 6" - gem "selenium-webdriver", "4.9.0" -end - -gemspec path: "../" diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb index 3319f5006..e6050eea0 100644 --- a/lib/view_component/test_helpers.rb +++ b/lib/view_component/test_helpers.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require 'debug' module ViewComponent module TestHelpers begin @@ -212,8 +211,6 @@ def #{helper_mthd} vc_test_controller.class.helper_method helper_mthd end yield - ensure - # vc_test_controller.clear_helpers end # Access the controller used by `render_inline`: From 52eb3ba19b48badebdc979118f6d05fb24c3b194 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 23 Oct 2023 22:12:01 +0200 Subject: [PATCH 15/33] edit: cleanup --- .tool-versions | 2 +- gemfiles/rails_6.0.gemfile | 10 ++++++++++ gemfiles/rails_6.1.gemfile | 14 ++++++++++++++ gemfiles/rails_7.0.gemfile | 11 +++++++++++ gemfiles/rails_head.gemfile | 11 +++++++++++ lib/view_component/test_helpers.rb | 1 + 6 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 gemfiles/rails_6.0.gemfile create mode 100644 gemfiles/rails_6.1.gemfile create mode 100644 gemfiles/rails_7.0.gemfile create mode 100644 gemfiles/rails_head.gemfile diff --git a/.tool-versions b/.tool-versions index c23af94d4..38ec15178 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 3.2.0 +ruby 3.0.3 diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile new file mode 100644 index 000000000..837afbd05 --- /dev/null +++ b/gemfiles/rails_6.0.gemfile @@ -0,0 +1,10 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "capybara", "~> 3" +gem "rails", "~> 6.0.0" +gem "rspec-rails", "~> 5.1" +gem "tailwindcss-rails", "~> 2.0" + +gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile new file mode 100644 index 000000000..5e7fa7750 --- /dev/null +++ b/gemfiles/rails_6.1.gemfile @@ -0,0 +1,14 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "capybara", "~> 3" +gem "rails", "~> 6.1.0" +gem "rspec-rails", "~> 5" +gem "debug" +gem "tailwindcss-rails", "~> 2.0" +gem "net-smtp", require: false +gem "net-imap", require: false +gem "net-pop", require: false + +gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile new file mode 100644 index 000000000..dc678af68 --- /dev/null +++ b/gemfiles/rails_7.0.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "capybara", "~> 3" +gem "rails", "~> 7.0.0" +gem "rspec-rails", "~> 5" +gem "debug" +gem "tailwindcss-rails", "~> 2.0" + +gemspec path: "../" diff --git a/gemfiles/rails_head.gemfile b/gemfiles/rails_head.gemfile new file mode 100644 index 000000000..40e0126d9 --- /dev/null +++ b/gemfiles/rails_head.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "capybara", "~> 3" +gem "rails", github: "rails/rails", branch: "main" +gem "rspec-rails", "~> 5" +gem "debug" +gem "tailwindcss-rails", "~> 2.0" + +gemspec path: "../" diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb index e6050eea0..8fe09efde 100644 --- a/lib/view_component/test_helpers.rb +++ b/lib/view_component/test_helpers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ViewComponent module TestHelpers begin From 25867a6ac192d87f96df89ec05cf66eab1e3fbdd Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 23 Oct 2023 22:14:23 +0200 Subject: [PATCH 16/33] edit: cleanup --- gemfiles/rails_5.2.gemfile | 8 ++++++++ gemfiles/rails_6.1.gemfile | 3 +-- gemfiles/rails_7.0.gemfile | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 gemfiles/rails_5.2.gemfile diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile new file mode 100644 index 000000000..56ee0723f --- /dev/null +++ b/gemfiles/rails_5.2.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "capybara", "~> 3" +gem "rails", "~> 5.2.0" + +gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index 5e7fa7750..4f68feb46 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -4,8 +4,7 @@ source "https://rubygems.org" gem "capybara", "~> 3" gem "rails", "~> 6.1.0" -gem "rspec-rails", "~> 5" -gem "debug" +gem "rspec-rails", "~> 5.1" gem "tailwindcss-rails", "~> 2.0" gem "net-smtp", require: false gem "net-imap", require: false diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index dc678af68..cfc057a56 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -4,8 +4,7 @@ source "https://rubygems.org" gem "capybara", "~> 3" gem "rails", "~> 7.0.0" -gem "rspec-rails", "~> 5" -gem "debug" +gem "rspec-rails", "~> 5.1" gem "tailwindcss-rails", "~> 2.0" gemspec path: "../" From 750863922df5ac71064bb4065e4458184c68c2d9 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 23 Oct 2023 22:15:26 +0200 Subject: [PATCH 17/33] edit: cleanup --- gemfiles/rails_head.gemfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gemfiles/rails_head.gemfile b/gemfiles/rails_head.gemfile index 40e0126d9..d187ac20e 100644 --- a/gemfiles/rails_head.gemfile +++ b/gemfiles/rails_head.gemfile @@ -4,8 +4,7 @@ source "https://rubygems.org" gem "capybara", "~> 3" gem "rails", github: "rails/rails", branch: "main" -gem "rspec-rails", "~> 5" -gem "debug" +gem "rspec-rails", "~> 5.1" gem "tailwindcss-rails", "~> 2.0" gemspec path: "../" From 1315a54addb6d4c851e4158c8d253e94399d92b0 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Mon, 23 Oct 2023 22:22:28 +0200 Subject: [PATCH 18/33] edit: cleanup --- lib/view_component/test_helpers.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb index 8fe09efde..f062d1a20 100644 --- a/lib/view_component/test_helpers.rb +++ b/lib/view_component/test_helpers.rb @@ -190,7 +190,6 @@ def with_request_url(path, host: nil) @vc_test_controller = old_controller end - # Set the controller helpers to be used while executing the given block, # # ```ruby From 925008266dae92e5c3330a4ba085944e710caec8 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 24 Oct 2023 06:41:17 +0200 Subject: [PATCH 19/33] remove Style/RedundantSelf lint error --- lib/view_component/test_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb index f062d1a20..5a565671e 100644 --- a/lib/view_component/test_helpers.rb +++ b/lib/view_component/test_helpers.rb @@ -203,7 +203,7 @@ def with_helpers(*args) args.each do |helper_mthd| vc_test_controller.class_eval(<<-RUBY, __FILE__, __LINE__ + 1) def #{helper_mthd} - return #{return self.send(helper_mthd)} + return #{return send(helper_mthd)} end ruby2_keywords(:'#{helper_mthd}') From d5e5797891f6e885b9ba60d372055de9dd8d6f57 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 24 Oct 2023 06:42:26 +0200 Subject: [PATCH 20/33] remove Layout/EmptyLinesAroundAccessModifier lint error --- test/sandbox/test/rendering_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/sandbox/test/rendering_test.rb b/test/sandbox/test/rendering_test.rb index a806ad619..b4a0bf400 100644 --- a/test/sandbox/test/rendering_test.rb +++ b/test/sandbox/test/rendering_test.rb @@ -1103,6 +1103,7 @@ def test_use_helper end private + def test_helper "Hello helper method" end From 9fbf47dffb89f4cd584699ec2bedfedaceb531b6 Mon Sep 17 00:00:00 2001 From: Reegan Viljoen <62689748+reeganviljoen@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:53:27 +0200 Subject: [PATCH 21/33] Update lib/view_component/use_helpers.rb Co-authored-by: Blake Williams --- lib/view_component/use_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view_component/use_helpers.rb b/lib/view_component/use_helpers.rb index 254a04602..b8559758b 100644 --- a/lib/view_component/use_helpers.rb +++ b/lib/view_component/use_helpers.rb @@ -9,7 +9,7 @@ def use_helpers(*args) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) def #{helper_mtd}(*args, &block) raise HelpersCalledBeforeRenderError if view_context.nil? - __vc_original_view_context&.send(#{helper_mtd.inspect}, *args, &block) || view_context.send(#{helper_mtd.inspect}, *args, &block) + __vc_original_view_context&.send(#{helper_mtd.inspect}, *args, &block) end RUBY From 1aa85396dad801b3b97cbc007028872d673b118e Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 09:00:59 +0200 Subject: [PATCH 22/33] edit: change helper spelling --- lib/view_component/use_helpers.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/view_component/use_helpers.rb b/lib/view_component/use_helpers.rb index b8559758b..881970ccb 100644 --- a/lib/view_component/use_helpers.rb +++ b/lib/view_component/use_helpers.rb @@ -5,15 +5,15 @@ module ViewComponent::UseHelpers class_methods do def use_helpers(*args) - args.each do |helper_mtd| + args.each do |helper_method| class_eval(<<-RUBY, __FILE__, __LINE__ + 1) - def #{helper_mtd}(*args, &block) + def #{helper_method}(*args, &block) raise HelpersCalledBeforeRenderError if view_context.nil? - __vc_original_view_context&.send(#{helper_mtd.inspect}, *args, &block) + __vc_original_view_context&.send(#{helper_method.inspect}, *args, &block) end RUBY - ruby2_keywords(helper_mtd) if respond_to?(:ruby2_keywords, true) + ruby2_keywords(helper_method) if respond_to?(:ruby2_keywords, true) end end end From 43289df3281c6270ddb67d3b1e4a2e6737f2158c Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 09:02:28 +0200 Subject: [PATCH 23/33] edit: omptimize helper eval --- lib/view_component/use_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view_component/use_helpers.rb b/lib/view_component/use_helpers.rb index 881970ccb..b0c972c83 100644 --- a/lib/view_component/use_helpers.rb +++ b/lib/view_component/use_helpers.rb @@ -9,7 +9,7 @@ def use_helpers(*args) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) def #{helper_method}(*args, &block) raise HelpersCalledBeforeRenderError if view_context.nil? - __vc_original_view_context&.send(#{helper_method.inspect}, *args, &block) + __vc_original_view_context.helper_method(*args, &block) end RUBY From c4fdaaae4c84b35b6ee796d699950e4f154e6d58 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 21:26:23 +0200 Subject: [PATCH 24/33] remove test_helpers and fix use_helpers --- lib/view_component/test_helpers.rb | 23 ------------------- lib/view_component/use_helpers.rb | 2 +- .../components/use_helpers_component.html.erb | 2 +- .../app/components/use_helpers_component.rb | 2 +- test/sandbox/test/rendering_test.rb | 12 ++-------- 5 files changed, 5 insertions(+), 36 deletions(-) diff --git a/lib/view_component/test_helpers.rb b/lib/view_component/test_helpers.rb index 5a565671e..1cb733451 100644 --- a/lib/view_component/test_helpers.rb +++ b/lib/view_component/test_helpers.rb @@ -190,29 +190,6 @@ def with_request_url(path, host: nil) @vc_test_controller = old_controller end - # Set the controller helpers to be used while executing the given block, - # - # ```ruby - # with_helpers(UsersHelper) do - # render_inline(MyComponent.new) - # end - # ``` - # - # @param *args [Array] The helpers to be used. - def with_helpers(*args) - args.each do |helper_mthd| - vc_test_controller.class_eval(<<-RUBY, __FILE__, __LINE__ + 1) - def #{helper_mthd} - return #{return send(helper_mthd)} - end - - ruby2_keywords(:'#{helper_mthd}') - RUBY - vc_test_controller.class.helper_method helper_mthd - end - yield - end - # Access the controller used by `render_inline`: # # ```ruby diff --git a/lib/view_component/use_helpers.rb b/lib/view_component/use_helpers.rb index b0c972c83..32d13cd43 100644 --- a/lib/view_component/use_helpers.rb +++ b/lib/view_component/use_helpers.rb @@ -9,7 +9,7 @@ def use_helpers(*args) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) def #{helper_method}(*args, &block) raise HelpersCalledBeforeRenderError if view_context.nil? - __vc_original_view_context.helper_method(*args, &block) + __vc_original_view_context.#{helper_method}(*args, &block) end RUBY diff --git a/test/sandbox/app/components/use_helpers_component.html.erb b/test/sandbox/app/components/use_helpers_component.html.erb index 47dd48973..f24542007 100644 --- a/test/sandbox/app/components/use_helpers_component.html.erb +++ b/test/sandbox/app/components/use_helpers_component.html.erb @@ -1,3 +1,3 @@
- <%= test_helper %> + <%= message %>
diff --git a/test/sandbox/app/components/use_helpers_component.rb b/test/sandbox/app/components/use_helpers_component.rb index 209e937e2..375c07db6 100644 --- a/test/sandbox/app/components/use_helpers_component.rb +++ b/test/sandbox/app/components/use_helpers_component.rb @@ -3,5 +3,5 @@ class UseHelpersComponent < ViewComponent::Base include ViewComponent::UseHelpers - use_helpers :test_helper + use_helpers :message end diff --git a/test/sandbox/test/rendering_test.rb b/test/sandbox/test/rendering_test.rb index b4a0bf400..cd985beb6 100644 --- a/test/sandbox/test/rendering_test.rb +++ b/test/sandbox/test/rendering_test.rb @@ -1096,15 +1096,7 @@ def test_content_security_policy_nonce end def test_use_helper - with_helpers(:test_helper) do - render_inline(UseHelpersComponent.new) - assert_selector ".helper__message", text: "Hello helper method" - end - end - - private - - def test_helper - "Hello helper method" + render_inline(UseHelpersComponent.new) + assert_selector ".helper__message", text: "Hello helper method" end end From b270ef851c708c8a2798a949e7db7884f3205ba8 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 21:51:16 +0200 Subject: [PATCH 25/33] add: docs --- docs/guide/helpers.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/guide/helpers.md b/docs/guide/helpers.md index 1407fe14a..5113996b2 100644 --- a/docs/guide/helpers.md +++ b/docs/guide/helpers.md @@ -51,6 +51,24 @@ class UserComponent < ViewComponent::Base end ``` +## UseHelpers setter +To use the `UseHelpers` setter include `ViewComponent::UseHelpers` +`UseHelpers` defines the helper on the component and is similar in use to using `delegate` on helpers + + +```ruby +class UseHelpersComponent < ViewComponent::Base + include ViewComponent::UseHelpers + use_helpers :message + + erb_template <<-ERB +
+ <%= message %> +
+ ERB +end +``` + ## Nested URL helpers Rails nested URL helpers implicitly depend on the current `request` in certain cases. Since ViewComponent is built to enable reusing components in different contexts, nested URL helpers should be passed their options explicitly: From ba7dd226d0276a650f2a1ac159492f00f5accd6b Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 21:59:41 +0200 Subject: [PATCH 26/33] fix markdown issues --- docs/guide/helpers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/helpers.md b/docs/guide/helpers.md index 5113996b2..29d002761 100644 --- a/docs/guide/helpers.md +++ b/docs/guide/helpers.md @@ -52,10 +52,10 @@ end ``` ## UseHelpers setter + To use the `UseHelpers` setter include `ViewComponent::UseHelpers` `UseHelpers` defines the helper on the component and is similar in use to using `delegate` on helpers - ```ruby class UseHelpersComponent < ViewComponent::Base include ViewComponent::UseHelpers From d0198a1f2d4e41a73e2f6d46a11af50e7dd570db Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 22:03:29 +0200 Subject: [PATCH 27/33] fix markdown issues --- docs/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 6760f6e69..1f64c665e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -14,7 +14,6 @@ nav_order: 5 *Reegan Viljoen* - ## 3.7.0 * Support Rails 7.1 in CI. From 6798415a36a4ee32829f24dd24704c5d9ab2d0ae Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 22:03:50 +0200 Subject: [PATCH 28/33] edit: changelog entry --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1f64c665e..c62a85f8c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,7 +10,7 @@ nav_order: 5 ## main -* Add `use_helper` api +* Add `use_helper` setter *Reegan Viljoen* From 530ab54a5d8a27fe816e7e2fdda83e3d2b5d9bfd Mon Sep 17 00:00:00 2001 From: Reegan Viljoen <62689748+reeganviljoen@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:16:09 +0200 Subject: [PATCH 29/33] Update docs/guide/helpers.md Co-authored-by: Hans Lemuet --- docs/guide/helpers.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/guide/helpers.md b/docs/guide/helpers.md index 29d002761..11056d912 100644 --- a/docs/guide/helpers.md +++ b/docs/guide/helpers.md @@ -53,7 +53,9 @@ end ## UseHelpers setter -To use the `UseHelpers` setter include `ViewComponent::UseHelpers` +By default, ViewComponents do not have access to helper methods defined externally. The `use_helpers` method allows external helpers to be called from the component. + +To use the `use_helpers` method, include `ViewComponent::UseHelpers`. `UseHelpers` defines the helper on the component and is similar in use to using `delegate` on helpers ```ruby From 357ba441360553cd7850c489e7e88b56b0bb334c Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 22:18:38 +0200 Subject: [PATCH 30/33] make helpers example more clear --- docs/guide/helpers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guide/helpers.md b/docs/guide/helpers.md index 11056d912..2888c890f 100644 --- a/docs/guide/helpers.md +++ b/docs/guide/helpers.md @@ -61,11 +61,11 @@ To use the `use_helpers` method, include `ViewComponent::UseHelpers`. ```ruby class UseHelpersComponent < ViewComponent::Base include ViewComponent::UseHelpers - use_helpers :message + use_helpers :icon erb_template <<-ERB -
- <%= message %> +
+ <%= icon :user %>
ERB end From ea2d7bcbd0ffdea4fffd3a67ca12c225b21dd179 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 22:19:40 +0200 Subject: [PATCH 31/33] fix markdown issues --- docs/guide/helpers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/helpers.md b/docs/guide/helpers.md index 2888c890f..454e673e0 100644 --- a/docs/guide/helpers.md +++ b/docs/guide/helpers.md @@ -56,7 +56,7 @@ end By default, ViewComponents do not have access to helper methods defined externally. The `use_helpers` method allows external helpers to be called from the component. To use the `use_helpers` method, include `ViewComponent::UseHelpers`. -`UseHelpers` defines the helper on the component and is similar in use to using `delegate` on helpers +`UseHelpers` defines the helper on the component and is similar in use to using `delegate` on helpers. ```ruby class UseHelpersComponent < ViewComponent::Base From 3012915350849061a0f5281467c3b6f9ab586795 Mon Sep 17 00:00:00 2001 From: reeganviljoen Date: Tue, 31 Oct 2023 22:20:25 +0200 Subject: [PATCH 32/33] edit: changelog entry --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c62a85f8c..4c316de5d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,7 +10,7 @@ nav_order: 5 ## main -* Add `use_helper` setter +* Add `use_helper` API *Reegan Viljoen* From c2b5a95a9137734c685658ed04627dc4ed3aafe3 Mon Sep 17 00:00:00 2001 From: Cameron Dutro Date: Fri, 3 Nov 2023 11:16:59 -0700 Subject: [PATCH 33/33] Update helpers.md --- docs/guide/helpers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/helpers.md b/docs/guide/helpers.md index 454e673e0..172c3aea0 100644 --- a/docs/guide/helpers.md +++ b/docs/guide/helpers.md @@ -53,7 +53,7 @@ end ## UseHelpers setter -By default, ViewComponents do not have access to helper methods defined externally. The `use_helpers` method allows external helpers to be called from the component. +By default, ViewComponents don't have access to helper methods defined externally. The `use_helpers` method allows external helpers to be called from the component. To use the `use_helpers` method, include `ViewComponent::UseHelpers`. `UseHelpers` defines the helper on the component and is similar in use to using `delegate` on helpers.