[PATCH 1 of 6 V2] hgweb: add format javascript function

Alexander Plavin alexander at plav.in
Sat Aug 17 17:28:56 CDT 2013


# HG changeset patch
# User Alexander Plavin <alexander at plav.in>
# Date 1376046093 -14400
#      Fri Aug 09 15:01:33 2013 +0400
# Node ID 9a094911541a650e3b3e84eef5d3ed46a24cb74e
# Parent  ae42151fc56ecc420f3fac291110a81476609b22
hgweb: add format javascript function

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

diff -r ae42151fc56e -r 9a094911541a mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Sat Aug 17 15:33:25 2013 +0400
+++ b/mercurial/templates/static/mercurial.js	Fri Aug 09 15:01:33 2013 +0400
@@ -298,3 +298,9 @@
 
     setLinewrap(!getLinewrap());
 }
+
+function format(str, replacements) {
+    return str.replace(/%(\w+)%/g, function(match, p1) {
+        return String(replacements[p1]);
+    });
+}


More information about the Mercurial-devel mailing list