From 9ec690a065b6a0b7c4c6e7df9652b39611ccb9ba Mon Sep 17 00:00:00 2001 From: Joel Drapper Date: Sat, 16 Mar 2024 16:05:28 +0000 Subject: [PATCH] Extract `a` helpers --- lib/phlex/rails/helpers.rb | 80 +++---------------- .../rails/helpers/action_cable_meta_tag.rb | 11 +++ lib/phlex/rails/helpers/action_name.rb | 10 +++ lib/phlex/rails/helpers/asset_path.rb | 15 ++++ lib/phlex/rails/helpers/asset_url.rb | 8 ++ lib/phlex/rails/helpers/audio_path.rb | 8 ++ lib/phlex/rails/helpers/audio_tag.rb | 9 +++ lib/phlex/rails/helpers/audio_url.rb | 8 ++ .../rails/helpers/auto_discovery_link_tag.rb | 9 +++ 9 files changed, 87 insertions(+), 71 deletions(-) create mode 100644 lib/phlex/rails/helpers/action_cable_meta_tag.rb create mode 100644 lib/phlex/rails/helpers/action_name.rb create mode 100644 lib/phlex/rails/helpers/asset_path.rb create mode 100644 lib/phlex/rails/helpers/asset_url.rb create mode 100644 lib/phlex/rails/helpers/audio_path.rb create mode 100644 lib/phlex/rails/helpers/audio_tag.rb create mode 100644 lib/phlex/rails/helpers/audio_url.rb create mode 100644 lib/phlex/rails/helpers/auto_discovery_link_tag.rb diff --git a/lib/phlex/rails/helpers.rb b/lib/phlex/rails/helpers.rb index d0faa9b7..7f7dc3c3 100644 --- a/lib/phlex/rails/helpers.rb +++ b/lib/phlex/rails/helpers.rb @@ -1,80 +1,18 @@ # frozen_string_literal: true module Phlex::Rails::Helpers - autoload :Tag, "phlex/rails/helpers/tag" + autoload :ActionCableMetaTag, "phlex/rails/helpers/action_cable_meta_tag" + autoload :ActionName, "phlex/rails/helpers/action_name" + autoload :AssetPath, "phlex/rails/helpers/asset_path" + autoload :AssetURL, "phlex/rails/helpers/asset_url" + autoload :AudioPath, "phlex/rails/helpers/audio_path" + autoload :AudioTag, "phlex/rails/helpers/audio_tag" + autoload :AudioURL, "phlex/rails/helpers/audio_url" + autoload :AutoDiscoveryLinkTag, "phlex/rails/helpers/auto_discovery_link_tag" autoload :Routes, "phlex/rails/helpers/routes" + autoload :Tag, "phlex/rails/helpers/tag" autoload :TurboStream, "phlex/rails/helpers/turbo_stream" - module ActionCableMetaTag - extend Phlex::Rails::HelperMacros - - # @!method action_cable_meta_tag - # Outputs an "action-cable-url" meta tag with the value of the URL specified in your configuration. Ensure this is above your JavaScript tag: - # @see https://api.rubyonrails.org/classes/ActionCable/Helpers/ActionCableHelper.html#method-i-action_cable_meta_tag - # @return [nil] - define_output_helper :action_cable_meta_tag - end - - module ActionName - extend Phlex::Rails::HelperMacros - - # @!method action_name - # @return [String] the name of the controller action, e.g. "index" - # @see https://api.rubyonrails.org/classes/AbstractController/Base.html#method-i-action_name - define_value_helper :action_name - end - - module AssetPath - extend Phlex::Rails::HelperMacros - - # @!method asset_path(source, host: nil, protocol: nil, type: nil, skip_pipeline: nil, extname: nil) - # @param source [String] - # @param host [String] - # @param protocol [String] e.g. "https" - # @param type [Symbol] e.g. :javascript - # @param skip_pipeline [bool] - # @param extname [String] e.g. ".js" - # @see https://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-asset_path - define_value_helper :asset_path - end - - module AssetURL - extend Phlex::Rails::HelperMacros - - # @!method asset_url(...) - define_value_helper :asset_url - end - - module AudioPath - extend Phlex::Rails::HelperMacros - - # @!method audio_path(...) - define_value_helper :audio_path - end - - module AudioTag - extend Phlex::Rails::HelperMacros - - # @!method audio_tag(...) - # @return [nil] - define_output_helper :audio_tag - end - - module AudioURL - extend Phlex::Rails::HelperMacros - - # @!method audio_url(...) - define_value_helper :audio_url - end - - module AutoDiscoveryLinkTag - extend Phlex::Rails::HelperMacros - - # @!method auto_discovery_link_tag(...) - # @return [nil] - define_output_helper :auto_discovery_link_tag - end - module BuildTagValues extend Phlex::Rails::HelperMacros diff --git a/lib/phlex/rails/helpers/action_cable_meta_tag.rb b/lib/phlex/rails/helpers/action_cable_meta_tag.rb new file mode 100644 index 00000000..545b99d9 --- /dev/null +++ b/lib/phlex/rails/helpers/action_cable_meta_tag.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Phlex::Rails::Helpers::ActionCableMetaTag + extend Phlex::Rails::HelperMacros + + # @!method action_cable_meta_tag + # Outputs an "action-cable-url" meta tag with the value of the URL specified in your configuration. Ensure this is above your JavaScript tag: + # @see https://api.rubyonrails.org/classes/ActionCable/Helpers/ActionCableHelper.html#method-i-action_cable_meta_tag + # @return [nil] + define_output_helper :action_cable_meta_tag +end diff --git a/lib/phlex/rails/helpers/action_name.rb b/lib/phlex/rails/helpers/action_name.rb new file mode 100644 index 00000000..9b7a5719 --- /dev/null +++ b/lib/phlex/rails/helpers/action_name.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Phlex::Rails::Helpers::ActionName + extend Phlex::Rails::HelperMacros + + # @!method action_name + # @return [String] the name of the controller action, e.g. "index" + # @see https://api.rubyonrails.org/classes/AbstractController/Base.html#method-i-action_name + define_value_helper :action_name +end diff --git a/lib/phlex/rails/helpers/asset_path.rb b/lib/phlex/rails/helpers/asset_path.rb new file mode 100644 index 00000000..abdfc11a --- /dev/null +++ b/lib/phlex/rails/helpers/asset_path.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Phlex::Rails::Helpers::AssetPath + extend Phlex::Rails::HelperMacros + + # @!method asset_path(source, host: nil, protocol: nil, type: nil, skip_pipeline: nil, extname: nil) + # @param source [String] + # @param host [String] + # @param protocol [String] e.g. "https" + # @param type [Symbol] e.g. :javascript + # @param skip_pipeline [bool] + # @param extname [String] e.g. ".js" + # @see https://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html#method-i-asset_path + define_value_helper :asset_path +end diff --git a/lib/phlex/rails/helpers/asset_url.rb b/lib/phlex/rails/helpers/asset_url.rb new file mode 100644 index 00000000..f8d70214 --- /dev/null +++ b/lib/phlex/rails/helpers/asset_url.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Phlex::Rails::Helpers::AssetURL + extend Phlex::Rails::HelperMacros + + # @!method asset_url(...) + define_value_helper :asset_url +end diff --git a/lib/phlex/rails/helpers/audio_path.rb b/lib/phlex/rails/helpers/audio_path.rb new file mode 100644 index 00000000..300e7dca --- /dev/null +++ b/lib/phlex/rails/helpers/audio_path.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Phlex::Rails::Helpers::AudioPath + extend Phlex::Rails::HelperMacros + + # @!method audio_path(...) + define_value_helper :audio_path +end diff --git a/lib/phlex/rails/helpers/audio_tag.rb b/lib/phlex/rails/helpers/audio_tag.rb new file mode 100644 index 00000000..66f3e45e --- /dev/null +++ b/lib/phlex/rails/helpers/audio_tag.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Phlex::Rails::Helpers::AudioTag + extend Phlex::Rails::HelperMacros + + # @!method audio_tag(...) + # @return [nil] + define_output_helper :audio_tag +end diff --git a/lib/phlex/rails/helpers/audio_url.rb b/lib/phlex/rails/helpers/audio_url.rb new file mode 100644 index 00000000..5705449b --- /dev/null +++ b/lib/phlex/rails/helpers/audio_url.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Phlex::Rails::Helpers::AudioURL + extend Phlex::Rails::HelperMacros + + # @!method audio_url(...) + define_value_helper :audio_url +end diff --git a/lib/phlex/rails/helpers/auto_discovery_link_tag.rb b/lib/phlex/rails/helpers/auto_discovery_link_tag.rb new file mode 100644 index 00000000..e11de405 --- /dev/null +++ b/lib/phlex/rails/helpers/auto_discovery_link_tag.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Phlex::Rails::Helpers::AutoDiscoveryLinkTag + extend Phlex::Rails::HelperMacros + + # @!method auto_discovery_link_tag(...) + # @return [nil] + define_output_helper :auto_discovery_link_tag +end