Patchwork [07,of,20] hgweb: add format javascript function

login
register
mail settings
Submitter Alexander Plavin
Date Aug. 9, 2013, 6:57 p.m.
Message ID <f112e78a72dab869d57c.1376074652@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2112/
State Superseded
Commit 5bdc179e58c13d7d37e2c77af4904c1ef4edf0ef
Headers show

Comments

Alexander Plavin - Aug. 9, 2013, 6:57 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1376046093 -14400
#      Fri Aug 09 15:01:33 2013 +0400
# Node ID f112e78a72dab869d57cad83ab40ece62163d517
# Parent  8bd7e833e3be398d1932bb51b3bfa462531414b2
hgweb: add format javascript function

It replaces placeholders like '%key%' with replacement values given.

Patch

diff -r 8bd7e833e3be -r f112e78a72da mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Fri Aug 09 14:54:43 2013 +0400
+++ b/mercurial/templates/static/mercurial.js	Fri Aug 09 15:01:33 2013 +0400
@@ -293,3 +293,9 @@ 
 
     setLinewrap(!getLinewrap());
 }
+
+function format(str, replacements) {
+    return str.replace(/%(\w+)%/g, function(match, p1) {
+        return String(replacements[p1]);
+    });
+}