what are the requirements for the view_template method - to_str is not used #896
Replies: 6 comments 5 replies
|
OK, some context from looking at the code. It seems that a few pieces of code contribute to this behavior: Code like it appears in a few places, but the gist is that if the return value is not Which returns There are some places where code like the first link does check if it gets I can see a few possible changes, but this is my first time looking at this code, so I have no idea if any of this makes sense:
|
|
I need to get back to a laptop to read your question fully but the short answer is that Phlex doesn't call The Alternatively, you could make your |
|
Okay, back on a laptop. Since you’re talking about an Safe valueYou can create a Phlex::SGML::SafeValue.new("my safe string")There’s a shortcut to do this from inside a Phlex component using the safe("my safe string")
Safe Object Interface
class MySafeHTMLString
include Phlex::SGML::SafeObject
def initialize(value)
@value = value
end
def to_s
@value
end
endThis module is how |
|
Sorry, I think I made the question slightly confusing based on my class - this isn't a question about HTML escaping or raw HTML (how Phlex does that is clear from the docs 👍). It's more what I think is a bug around type handling of Bug - Phlex renders nothing on unsupported return type from
|
|
As I use the library more, there could be more places to call That said, I don't want to scope creep this discussion :) |
|
A way around this that @joeldrapper may have mentioned in Discord is to include That said, I can see Phlex maybe wanting to have a private class for understanding what is safe and a different API for users. A few thoughts:
|
Uh oh!
There was an error while loading. Please reload this page.
Hi, first time using Phlex. I'm trying to use it to replace a custom-created view layer. Part of the custom view layer is a class called
HTMLSafeString, which wraps a string and thus indicates its contents don't need to be escaped. It implements bothto_sandto_str. I realize in a Phlex-powered app, this class isn't needed, but it's still being used as a try out Phlex and transition.In my Phlex component, I am doing something like this:
In this case
tis a method I created that returns anHTMLSafeString. For the sake of the question, let's assume that this object'sto_strmethod returns theString"The message that t returns".When I call
call, Phlex returns<div><span></span></div>If I change my code to do
t("messages.#{item.key}").to_s, Phlex returns<div><span>The message that t returns</span></div>(which is the desired output).These leads to a few questions:
view_template? ObviouslyStringis, and presumably whatever Phlex's DSL methods return.to_stris how one indicates an object can be used as a string - should Phlex call this?All reactions