首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止ActionMailer去掉普通邮件中的重复空格

防止ActionMailer去掉普通邮件中的重复空格
EN

Stack Overflow用户
提问于 2012-02-19 00:42:55
回答 1查看 361关注 0票数 3

我正在尝试建立一个文本邮件表格,所以我写了一些帮助程序:

代码语言:javascript
复制
module MailerHelper
  def field_width(text, width)
    ' ' * (width - text.length) + text
  end

  def cell(text, width)
    output = '| ' + field_width(text, width-2) + " |\n"
    output << '+-' + '-'*(width-2) + '-+'
  end
end

然后在视图中,我这样写它:

代码语言:javascript
复制
<%= cell 'Test', 10 %>

但我得到的(根据letter_opener)是:

代码语言:javascript
复制
| Test |
+----------+

正如你所看到的,在Test之前重复的空格。我的问题是如何防止ActionMailer (或任何其他破坏我漂亮的表的东西)这样做。

Mailer代码:

代码语言:javascript
复制
  def remind(client, invoices)
    @client = client
    @company = @client.company
    @invoices  = invoices.to_a

    days_left = @invoices.first.pay_date - Date.today
    message = @client.group.messages.find_by_period days_left.to_i

    raise 'No messages for this invoices.' if message.nil?

    @template = message.template || if days_left < 0
      t 'message.before'
    elsif days_left > 0
      t 'message.after'
    else
      t 'message.today'
    end

    @text = liquid_parse @template
    @html = markdown_parse @text

    mail(:to => @client.email, :subject => t('message.title'))
  end

  private
    def markdown_parse(text)
      markdown = Redcarpet::Markdown.new Redcarpet::Render::HTML,
        :autolink => true, :space_after_headers => true
      markdown.render text
    end

    def liquid_parse(text)
      renderer = Liquid::Template.parse text
      renderer.render 'company' => @company, 'invoice' => @invoice, 'client' => @client
    end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-25 20:17:44

我找到虫子了。它是由Premailer引起的,我用它来内联HTML部件中的CSS。

代码语言:javascript
复制
class InlineCSSInterceptor
  def self.delivering_email(message)
    #message.text_part.body = Premailer.new(message.text_part.body.to_s, with_html_string: true).to_plain_text # this is line causing the problem.
    message.html_part.body = Premailer.new(message.html_part.body.to_s, with_html_string: true).to_inline_css
  end
end

Mailer.register_interceptor InlineCSSInterceptor
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9343021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档