您如何将这种多行失败转换为 HAML?

发布于 2025-01-08 20:32:20 字数 1440 浏览 0 评论 0原文

我无法完全理解这一点。

原始:

<%=
Shasta::CSV.generate do |csv|
  csv << ["Customer", "Job Name", "Payment Date", "Amount", "Notes"]

  for payment in @payments
    csv << [
      payment.customer.name,
      payment.jobs.map(&:name).join(" "),
      I18n.l(payment.created_at, :format => :short_date),
      number_to_currency(payment.amount),
      payment.notes
    ]
  end
end.html_safe
%>

HTML2HAML 将其转换为此,但失败

= Shasta::CSV.generate do |csv|                                        |
    csv << ["Customer", "Job Name", "Payment Date", "Amount", "Notes"] |
    for payment in @payments                                           |
      csv << [                                                         |
        payment.customer.name,                                         |
        payment.jobs.map(&:name).join(" "),                            |
        I18n.l(payment.created_at, :format => :short_date),            |
        number_to_currency(payment.amount),                            |
        payment.notes                                                  |
      ]                                                                |
    end                                                                |
  end.html_safe                                                        |

I can't quite wrap my mind around this.

Original:

<%=
Shasta::CSV.generate do |csv|
  csv << ["Customer", "Job Name", "Payment Date", "Amount", "Notes"]

  for payment in @payments
    csv << [
      payment.customer.name,
      payment.jobs.map(&:name).join(" "),
      I18n.l(payment.created_at, :format => :short_date),
      number_to_currency(payment.amount),
      payment.notes
    ]
  end
end.html_safe
%>

HTML2HAML Converted it to this, but it fails

= Shasta::CSV.generate do |csv|                                        |
    csv << ["Customer", "Job Name", "Payment Date", "Amount", "Notes"] |
    for payment in @payments                                           |
      csv << [                                                         |
        payment.customer.name,                                         |
        payment.jobs.map(&:name).join(" "),                            |
        I18n.l(payment.created_at, :format => :short_date),            |
        number_to_currency(payment.amount),                            |
        payment.notes                                                  |
      ]                                                                |
    end                                                                |
  end.html_safe                                                        |

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心病无药医 2025-01-15 20:32:20

这并不完全是您问题的答案,但编写多行 haml 语句很痛苦,这就是为什么您应该将其移至助手中。

= some_descriptive_method_name @ payments

def some_descriptive_method_name(payments)
  Shasta::CSV.generate do |csv|
    csv << ["Customer", "Job Name", "Payment Date", "Amount", "Notes"]

    payments.each do |payment|
      csv << [
        payment.customer.name,
        payment.jobs.map(&:name).join(" "),
        I18n.l(payment.created_at, :format => :short_date),
        number_to_currency(payment.amount),
        payment.notes
      ]
    end
  end.html_safe
end

This isn't exactly the answer to your question, but it's a pain to write multiple line haml statements which is why you should probably move it into a helper.

= some_descriptive_method_name @payments

def some_descriptive_method_name(payments)
  Shasta::CSV.generate do |csv|
    csv << ["Customer", "Job Name", "Payment Date", "Amount", "Notes"]

    payments.each do |payment|
      csv << [
        payment.customer.name,
        payment.jobs.map(&:name).join(" "),
        I18n.l(payment.created_at, :format => :short_date),
        number_to_currency(payment.amount),
        payment.notes
      ]
    end
  end.html_safe
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文