Patchwork [1,of,5] hgweb: add format javascript function

login
register
mail settings
Submitter Alexander Plavin
Date Sept. 18, 2013, 6:33 p.m.
Message ID <1a20a7cc2b08c3b720ac.1379529195@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2520/
State Accepted
Commit 5bdc179e58c13d7d37e2c77af4904c1ef4edf0ef
Headers show

Comments

Alexander Plavin - Sept. 18, 2013, 6:33 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1378459857 -14400
#      Fri Sep 06 13:30:57 2013 +0400
# Node ID 1a20a7cc2b08c3b720ac02df815905e01276a90a
# Parent  17e983fb2af3e26e989d31129d8bbc31e4423210
hgweb: add format javascript function

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

Patch

diff -r 17e983fb2af3 -r 1a20a7cc2b08 mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Fri Sep 06 13:30:57 2013 +0400
+++ b/mercurial/templates/static/mercurial.js	Fri Sep 06 13:30:57 2013 +0400
@@ -298,3 +298,9 @@ 
 
     setLinewrap(!getLinewrap());
 }
+
+function format(str, replacements) {
+    return str.replace(/%(\w+)%/g, function(match, p1) {
+        return String(replacements[p1]);
+    });
+}