fixed word-wrapping for audit-log emails
authorTony Cook <tony@develop-help.com>
Wed, 19 Mar 2014 03:56:43 +0000 (14:56 +1100)
committerTony Cook <tony@develop-help.com>
Wed, 19 Mar 2014 04:28:12 +0000 (15:28 +1100)
site/templates/admin/log/mail.tmpl
site/templates/preload.tmpl

index b0e78368cbd686074e9c6868da6bfb9dce6e4127..453a60cc026ea5809861a618097c56dc599ecbeb 100644 (file)
@@ -12,9 +12,13 @@ Level: <:= entry.level_name :>
 When: <:= bse.date("%H:%M %d/%m/%Y", entry.when_at) :>
 
 Message:
-<:= entry.msg.replace(/\S{60,}\s/, "$1\n", 1) :>
+<:  .call "word_wrap", text: entry.msg, prefix: "  ", noncontin: ">", contin: " ", escape1: " \\" :>
+<:.if entry.dump.defined and entry.dump.length :>
+Dump:
+<:  .call "word_wrap", text: entry.dump, prefix: "  ", noncontin: ">", contin: " ", escape1: " \\" :>
+<:.end if :>
 
-<:.set work = cfg.entry("mail audit log", "subject_" _ entry.facility _ "-"
+<:-.set work = cfg.entry("mail audit log", "subject_" _ entry.facility _ "-"
     _ entry.component _ "-" _ entry.module _ "-" _ entry.function) -:>
 <:.if work -:>
   <:.if work =~ /\{\w+\}/ -:>
@@ -40,4 +44,5 @@ Message:
   <:.else -:>
      <:% set_subject(work) -:>
   <:.end if -:>
-<:.end if:>
\ No newline at end of file
+<:.end if:>
+
index fd53362658087f5947f83ffcb226d23e734f45f7..5e5d3afe28d7f3fde5edca4dff4f490b858833db 100644 (file)
@@ -398,4 +398,41 @@ parameters:
 
 <:.end define -:>
 
+<:.define word_wrap; text: @undef, prefix:"", noncontin: "", contin:"", escape1: "", escape2: "", width: 70 -:>
+<:# Word wrap "text" at width columns, following settings:
+width - word wrap width (default 70)
+prefix - prefix to add to all lines
+noncontin - prefix to additionally add to first line of each paragraph
+contin - prefix to additionally add to lines that have been wrapped
+escape1 - suffix to add to lines wrapped on a non-word
+escape2 - suffix to add to lines wrapped on a word boundary
+-:>
+<:.set re = "^.{1," _ width _ "}\\s+" -:>
+<:.set paras = text.split(/\n/) -:>
+<:.for para in paras -:>
+<:  .set work = para -:>
+<:  .set first = 1 -:>
+<:  .while work.length -:>
+<:    .if !first -:>
+<:      .set work = work.replace(/^\s+/, "") -:>
+<:    .end if -:>
+<:    .if work.length < 70 -:>
+<:      .set line = work -:>
+<:      .set work = "" -:>
+<:    .else -:>
+<:      .set m = work.match(re) -:>
+<:      .if m -:>
+<:        .set line = work.substring(0, m.length).replace(/\s+$/, "") _ escape2 -:>
+<:        .set work = work.substring(m.length) -:>
+<:      .else -:>
+<:        .set line = work.substring(0, width) _ escape1 -:>
+<:        .set work = work.substring(width) -:>
+<:      .end if -:>
+<:    .end if -:>
+<:= prefix _ (first ? noncontin : contin) _ line.replace(/\s+$/, "") |raw:>
+<:    .set first = 0 -:>
+<:  .end while -:>
+<:.end for -:>
+<:.end define -:>
+
 <:- include includes/custom/preload.tmpl optional -:>