Replies: 2 comments 4 replies
-
Hey @mhenrixon, Phlex 2 will have a feature to help creating your own helper adapters. For now, here's how you can do it manually. If you have a helper that provides a value — perhaps a URL or a string of text to display, you can define a method that delegates to the def current_url(...)
helpers.current_url(...)
end Since you're in a Rails environment, you could use Rails delegate :current_url, to: :helpers Now, if you have a helper that returns HTML to output, you’ll need to do things a little differently. I’ll give you an example with the def toggle_trigger_tag(*args, **kwargs, &block)
output = helpers.toggle_trigger_tag(*args, **kwargs) { capture(&block) }
if ActiveSupport::SafeBuffer === output
unsafe_raw(output)
end
end In the first line, we define a method that takes any number of positional arguments as In line two, we call the original helper (via the This is very important because the original helper expects the passed block to return a string, since the original helper is designed to work with ERB. This line takes care of converting from Phlex mode (where everything is buffered) to ERB mode (where everything is a passed as a value). Finally, we save it to a variable called Now, we could render this output directly with Hope that makes sense. When Phlex 2 comes out, you should just be able to do something like register_output_helper :toggle_trigger_tag |
Beta Was this translation helpful? Give feedback.
-
Thanks for this discussion! I noticed # frozen_string_literal: true
# Mixing this into ApplicationComponent to provide access to helpers that are
# provided by gems
# Until Phlex 2 comes out (see https://github.com/orgs/phlex-ruby/discussions/651 )
module UpstreamHelpers
extend Phlex::Rails::HelperMacros
# Helpers that return things
delegate :current_user, :user_signed_in?, :title, to: :helpers
# Helpers that output HTML
register_output_helper :display_meta_tags
end To get the helpers from the meta-tags and devise gems that I use. I just mixed that module into my |
Beta Was this translation helpful? Give feedback.
-
I am using @hopsoft's turbo_boost-elements for building reactive websites and found it doesn't work with phlex-rails that I would love to use.
It looks something like this:
Here are a few ideas of what can be wrong:
toggle_trigger_tag renders: current_partial_path
This seems to rely on actionview.toggle_target_tag settings_tag do
, which I believe stores the block as a callback for later. It doesn't render the block.Now, that's fine, phlex is still new but I'd love to stick to one thing so how can I contribute fixes here?
The main problem, apart from the discussion about action text, is in the blocks, and I need to wrap this functionality somehow to avoid it being rendered directly.
WDYT?
Beta Was this translation helpful? Give feedback.
All reactions