-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partials support? #53
Comments
I don't know. For sure. What I think is happening is that maildown is actually not limited to just emails. So what it's doing is rendering the I'm not sure though, can you give me an example app that reproduces the problem https://www.codetriage.com/example_apps. No guarantees I can fix it but reproducing the issue is the first step. |
I'm not an expert, but solved this same issue in app views by forcing the rendered partials to be html safe like so.
The fact that maildown is not limited to just emails is awesome by the way. I use it all over my app! Makes longer translatable texts so much nicer than using a yaml language file. |
I believe the problem is the following: In https://github.com/codetriage/maildown/blob/a71449c3f1b18a74c63c64ddb529cc732791f444/lib/maildown/handlers/markdown.rb#L39 Maildown uses <%= render(partial: 'foo', locals: {"_no_cache_#{@current_template.format || ''}" => true}).html_safe %> The class PartialRenderer
alias :original_find_partial :find_partial
def find_partial(*args)
template = original_find_partial(*args)
template.instance_variable_set('@format', formats.first)
template
end
end This is of course completely horrible, and I hope there is a better solution, but it works for me. |
Is this still an issue? If so can you give me an example app that shows the problem? https://www.codetriage.com/example_app |
This no longer works in Rails 6.1, the method name was changed to |
Hey! This is still a problem for sure. Simply include any partial with a |
I'm glad you could reproduce it. Can you give me an example app that shows the problem? https://www.codetriage.com/example_app I generally won't work on something if I can't have a verified reproduction. Which is why I've asked for one. Alternatively, I'll take a look at a patch with a test if you've got a fix lined up. |
It's been awhile, closing for now. Please provide an example app and I'm happy to re-open. |
FYI, seeing the same thing. Using |
NOTE: THIS IS INCORRECT. For the record, @mkamensky's fork of this fixes it perfectly so anybody that needs this should use this in their Gemfile until this gets fixed in the main repo: gem "maildown", github: "mkamensky/maildown" @schneems It's not an example app but @mkamensky's fork shows exactly what is not working and how to fix it. Should be able to include this in this main repo. I tried looking at it myself for a bit but not sure of the intricacies. |
Nevermind, I take it back. @mkamensky's fork doesn't fix it like I thought. But it does permit a strange workaround that might shed some light on what's going wrong and how to fix it. So, with the @mkamensky's fork, I found that doing the following worked: <% if formats.first == :text %>
<%= render( partial: "my_partial", locals: nil ).html_safe %>
<% else %>
<%= render( partial: "my_partial", locals: { your: "mom" } ).html_safe %>
<% end %> What you choose to put in the Doesn't work<% if formats.first == :text %>
<%= render( partial: "my_partial", formats: formats ).html_safe %>
<% else %>
<%= render( partial: "my_partial" ).html_safe %>
<% end %>
<% if formats.first == :text %>
<%= render( partial: "my_partial", locals: { your: "mom" } ).html_safe %>
<% else %>
<%= render( partial: "my_partial", locals: { your: "dad" } ).html_safe %>
<% end %>
<% if formats.first == :text %>
<%= render( partial: "my_partial", locals: { your: "mom", my: "dad" } ).html_safe %>
<% else %>
<%= render( partial: "my_partial", locals: { your: "dad", my: "mom" } ).html_safe %>
<% end %> Works<% if formats.first == :text %>
<%= render( partial: "my_partial", locals: { your: "mom" } ).html_safe %>
<% else %>
<%= render( partial: "my_partial", locals: nil ).html_safe %>
<% end %>
<% if formats.first == :text %>
<%= render( partial: "my_partial", locals: { your: "mom" } ).html_safe %>
<% else %>
<%= render( partial: "my_partial", locals: { mom: "your" } ).html_safe %>
<% end %>
<% if formats.first == :text %>
<%= render( partial: "my_partial", locals: { your: "mom" } ).html_safe %>
<% else %>
<%= render( partial: "my_partial", locals: { your: "dad", my: "mom" } ).html_safe %>
<% end %> Based on this, it seems like some kind of caching issue where having different keys in the I also did some debugging and added a @schneems Hopefully this is enough information to maybe look into or at the very least re-open this Issue. If you do that, that'll let me know you'll take a look at it if I get an Example App / test reproducing the issue. For now, the workaround is to use @mkamensky's fork and then ensure your
|
Yes, that's what I was trying to say in my original comment. I believe my suggestion for the locals works better than various family members since it ends up being unique per partial and format |
Right on. I didn't get that the keys of the And for the record, the family member examples was just to illustrate that the keys had to be unique for the template to be re-rendered with a new format, not just the value of the keys. We ended up using: <%= render( "my_partial", { formats.first => true } ).html_safe %> But we're not passing any locals for our markdown mailer partials so the chance of Still, I'd love to actually solve this properly and get it working without passing any unique |
Hi @schneems, I finally got around to creating a simple example app that re-creates the issue of markdown ( https://github.com/joshuapinter/maildown_partials_issue I've included the repro instructions in the README but here they are as well:
I did this in Rails 6 and Ruby 3 because that's what I had handy. I hope this is enough to re-open this Issue and take another look. I've spent a few hours trying to figure it out myself and digging into how Rails renders partials but it's a bit over my head. Let me know if you need anything from my side or if you want me to do some testing. Rendering emails in markdown is incredible and I feel like this is the missing piece to make it truly clean, DRY and beautiful. Thanks in advance! |
Awesome sauce, thanks a ton! I opened a new issue to put my thoughts into this. Also I'm going to try fishing for some hacktober commits but this project is a bit unwieldy. I honestly have to re-learn how it works every time I touch it. |
New issue is #69 |
Awesome. Like I said, I got pretty deep into it but after a few hours, I just couldn't get too much progress so I figured my time was better spent creating the example app instead. I'll follow along on the new Issue and if there's something I can dig into for you, let me know. We use this for work so I can justify some time spent here and there on it, if I'm given some direction. |
When I try render partials with maildown, the rendered partial show as text not html.
In specific, I want add footer with markdown format in mailer layout.
app/views/layouts/mailer.html.erb
and, this is footer
app/views/mailer/shared/_footer.en.md.erb
The result is:
Any Idea?
The text was updated successfully, but these errors were encountered: