Mange / roadie

Making HTML emails comfortable for the Ruby rockstars

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Absolute urls for <a> tags

kandadaboggu opened this issue · comments

A section of my email comes from a field stored in the database. The <a> tags in this text have relative urls. Same database is shared across multiple instances and each server is supposed to serve the correct absolute URL.

The roadie gem doesn't perform the href absolute URL conversion for <a> tags.
Is there a way to enable this feature?

Ideally, I am looking for a way to register a custom adjuster for the email HTML.

config.roadie.custom_adjuster = lambda{ |document|      
  document.css("user-comments a").each do |link|
    link['href'] = ensure_absolute_url(link['href']) if img['href']
  end
}

Sorry, that's not possible at the moment.

May I ask why it isn't easier to just write the correct URLs directly to the template? It would waste less clock cycles as well. :-)

I'm a bit undecided about the future of URL rewriting. It's error prone and should not be necessary much longer since Rails can handle that pretty well by itself.

I will consider it if you can make a good case for the feature, of course.

I am listing a product catalog entry in the email. I use absolute URL for <a> tags that I control. A section of the email shows the product description and this section has links to other resources in the site. The product description is generated by an off-line tool and it is meant to be shared across various product lines. Hence we keep the links in this text relative. So far it worked well as we were displaying the text within the context of a domain.

Recently, we started sending emails with the product information. The links in the description fail because they are relative. I was about to write a custom url handler for this section, and I decided to use nokogiri for parsing the fragment. I noticed that the roadie gem also uses nokogiri. I would save lot of cycles if I can have access to the nokogiri document before email text is generated.

It will be a good generic feature to allow users to add custom processing hooks to the HTML document.

That's a good reason for the new feature.

Feel free to open a pull request if you want it soon, because I have some larger changes in the pipe which I intend on finishing before jumping on this.

Please review my pull request #54.

I have named the converter configuration property as custom_converter. May be there is a better name for it.

This is now released in v2.4.0.