2012-02-18 12 views
3

我想在文本邮件的表,所以我写了一些助手:预防的ActionMailer脱光重复空格平原消息

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 

然后在视图我写这样的:

<%= cell 'Test', 10 %> 

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

| Test | 
+----------+ 

正如你看到的,空间, Test之前重复。我的问题是如何避免的ActionMailer(或别的什么毁了我美丽的表)从这样做。

梅勒代码:

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 
+0

时间破解打开的ActionMailer源代码 – 2012-02-25 10:56:49

回答

1

我发现的bug。它是由Premailer我在HTML部分使用内联CSS引起的。

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