• R/O
  • SSH

micro-format: コミット

string substitution and template library


コミットメタ情報

リビジョン900200da272152ddcc5b657b3e6ee416295772f8 (tree)
日時2019-08-07 17:04:03
作者frostbane <frostbane@prog...>
コミッターfrostbane

ログメッセージ

merge feature/opener

変更サマリ

差分

diff -r 21bf5af5cdf3 -r 900200da2721 .hgignore
--- a/.hgignore Thu Apr 05 19:12:31 2018 +0900
+++ b/.hgignore Wed Aug 07 17:04:03 2019 +0900
@@ -4,3 +4,5 @@
44 bin/*
55 doc/*
66 node_modules/*
7+syntax: glob
8+.idea/*
diff -r 21bf5af5cdf3 -r 900200da2721 src/microformat.js
--- a/src/microformat.js Thu Apr 05 19:12:31 2018 +0900
+++ b/src/microformat.js Wed Aug 07 17:04:03 2019 +0900
@@ -1,3 +1,21 @@
1+/* jshint
2+forin: false,
3+nonew: false,
4+proto: true,
5+maxlen: 180
6+ */
7+
8+/* global
9+root,
10+window,
11+Promise,
12+$,
13+$$,
14+exports,
15+module,
16+define
17+ */
18+
119 /*!
220 .. ┌ -: .
321 ([]▄▄├]▄▄▄¿┐`,
@@ -29,7 +47,7 @@
2947 ⌐ ,⌐
3048
3149
32- string format 0.2.1
50+ string format 0.2.2
3351 Copyright 2015, 2016, 2017 Frostbane Ac
3452 2015.04.24
3553
@@ -123,6 +141,11 @@
123141 return result;
124142 };
125143
144+ var escapeExpression = function(string) {
145+ // $& means the whole matched string
146+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
147+ };
148+
126149 /**
127150 *
128151 * @param {Object} settings
@@ -747,7 +770,7 @@
747770 var padIn,
748771 padOut,
749772 //filterExp = " *\\|?[a-zA-Z_\\| 0-9]*";
750- filterExp = "(?=[: \\|]? *[:| |\\|]?[^}]*) *[:| |\\|]?[^}]*";
773+ filterExp = "(?=[: \\|]? *[:| |\\|]?[^(" + closer + ")]*) *[:| |\\|]?[^(" + closer + ")]*";
751774
752775 if(
753776 (/^-?[\d]+(?:e-?\d+)?$/)
@@ -1214,7 +1237,15 @@
12141237 // useExplicitArrays = value === true;
12151238 //});
12161239
1217- format.VERSION = "0.2.1";
1240+ format.setOpener = function(left){
1241+ opener = escapeExpression(left);
1242+ };
1243+
1244+ format.setCloser = function(right){
1245+ closer = escapeExpression(right);
1246+ };
1247+
1248+ format.VERSION = "0.2.2";
12181249
12191250 return format;
12201251
diff -r 21bf5af5cdf3 -r 900200da2721 test/microformat.test.js
--- a/test/microformat.test.js Thu Apr 05 19:12:31 2018 +0900
+++ b/test/microformat.test.js Wed Aug 07 17:04:03 2019 +0900
@@ -298,6 +298,40 @@
298298
299299 },
300300
301+ testChangeOpenerParentheesis: function(){
302+ format.setOpener("((");
303+ format.setCloser("))");
304+
305+ var formatString = "{{ who }} is {{ what }} (( who )) is (( what )).";
306+
307+ var param = {
308+ who :"MR. BIG",
309+ what :"small",
310+ };
311+
312+ var expected = "{{ who }} is {{ what }} " + param.who + " is " + param.what + ".",
313+ actual = format(formatString, param);
314+
315+ assertEqual(expected, actual);
316+ },
317+
318+ testChangeOpenerBracket: function(){
319+ format.setOpener("[[");
320+ format.setCloser("]]");
321+
322+ var formatString = "{{ who }} is {{ what }} [[ who | toUpperCase ]] is [[ what | toLowerCase ]].";
323+
324+ var param = {
325+ who :"mr. big",
326+ what :"SMALL",
327+ };
328+
329+ var expected = "{{ who }} is {{ what }} " + param.who.toUpperCase() + " is " + param.what.toLowerCase() + ".",
330+ actual = format(formatString, param);
331+
332+ assertEqual(expected, actual);
333+ },
334+
301335 testAdditionalFilter :function(){
302336 var myCondFilter = function(s){
303337 var f = parseFloat(s);
@@ -337,6 +371,11 @@
337371 format.resetFilters();
338372 },
339373
374+ tearDown: function(){
375+ format.setOpener("{{");
376+ format.setCloser("}}");
377+ },
378+
340379 shutDown :function(){
341380 result.log();
342381 },
旧リポジトリブラウザで表示