Przeglądaj źródła

remove option to change interpolate tags

Evan You 12 lat temu
rodzic
commit
b2c4882fda
6 zmienionych plików z 8 dodań i 91 usunięć
  1. 2 6
      src/config.js
  2. 0 2
      src/main.js
  3. 2 1
      src/observer.js
  4. 2 26
      src/text-parser.js
  5. 1 22
      test/unit/specs/api.js
  6. 1 34
      test/unit/specs/text-parser.js

+ 2 - 6
src/config.js

@@ -1,10 +1,6 @@
 module.exports = {
 
     prefix      : 'sd',
-    debug       : false,
-
-    interpolateTags : {
-        open  : '{{',
-        close : '}}'
-    }
+    debug       : false
+    
 }

+ 0 - 2
src/main.js

@@ -2,7 +2,6 @@ var config      = require('./config'),
     ViewModel   = require('./viewmodel'),
     directives  = require('./directives'),
     filters     = require('./filters'),
-    textParser  = require('./text-parser'),
     utils       = require('./utils')
 
 /*
@@ -11,7 +10,6 @@ var config      = require('./config'),
 ViewModel.config = function (opts) {
     if (opts) {
         utils.extend(config, opts)
-        textParser.buildRegex()
     }
 }
 

+ 2 - 1
src/observer.js

@@ -1,3 +1,5 @@
+/* jshint proto:true */
+
 var Emitter  = require('./emitter'),
     utils    = require('./utils'),
     typeOf   = utils.typeOf,
@@ -74,7 +76,6 @@ function watchObject (obj, path, observer) {
 function watchArray (arr, path, observer) {
     def(arr, '__observer__', observer)
     observer.path = path
-    /* jshint proto:true */
     if (hasProto) {
         arr.__proto__ = ArrayProxy
     } else {

+ 2 - 26
src/text-parser.js

@@ -1,22 +1,4 @@
-var config     = require('./config'),
-    ESCAPE_RE  = /[-.*+?^${}()|[\]\/\\]/g,
-    BINDING_RE = build()
-
-/*
- *  Build interpolate tag regex from config settings
- */
-function build () {
-    var open = escapeRegex(config.interpolateTags.open),
-        close = escapeRegex(config.interpolateTags.close)
-    return new RegExp(open + '(.+?)' + close)
-}
-
-/*
- *  Escapes a string so that it can be used to construct RegExp
- */
-function escapeRegex (val) {
-    return val.replace(ESCAPE_RE, '\\$&')
-}
+var BINDING_RE = /\{\{(.+?)\}\}/
 
 module.exports = {
 
@@ -36,12 +18,6 @@ module.exports = {
         } while (true)
         if (text.length) tokens.push(text)
         return tokens
-    },
-
-    /*
-     *  External build
-     */
-    buildRegex: function () {
-        BINDING_RE = build()
     }
+    
 }

+ 1 - 22
test/unit/specs/api.js

@@ -15,30 +15,9 @@ describe('UNIT: API', function () {
             assert.strictEqual($('#' + testId + ' span'), testId)
         })
 
-        it('should work when changing interpolate tags', function () {
-            var testId = 'config-2'
-            // IE treats <% ... %> as a tag... wtf
-            Seed.config({
-                interpolateTags: {
-                    open: '(%',
-                    close: '%)'
-                }
-            })
-            mock(testId, '(% test %)')
-            new Seed({
-                el: '#' + testId,
-                scope: { test: testId }
-            })
-            assert.strictEqual($('#' + testId), testId)
-        })
-
         after(function () {
             Seed.config({
-                prefix: 'sd',
-                interpolateTags: {
-                    open: '{{',
-                    close: '}}'
-                }
+                prefix: 'sd'
             })
         })
 

+ 1 - 34
test/unit/specs/text-parser.js

@@ -1,5 +1,4 @@
-var TextParser = require('seed/src/text-parser'),
-    config = require('seed/src/config')
+var TextParser = require('seed/src/text-parser')
 
 describe('UNIT: TextNode Parser', function () {
 
@@ -51,36 +50,4 @@ describe('UNIT: TextNode Parser', function () {
 
     })
 
-    describe('.buildRegex()', function () {
-
-        before(function () {
-            config.interpolateTags = {
-                open: '<%',
-                close: '%>'
-            }
-            TextParser.buildRegex()
-        })
-        
-        it('should update the interpolate tags and work', function () {
-            var tokens = TextParser.parse('hello <%a%>! <% bcd %><%d.e.f%> <%a + (b || c) ? d : e%>')
-            assert.strictEqual(tokens.length, 7)
-            assert.strictEqual(typeof tokens[0], 'string')
-            assert.strictEqual(typeof tokens[2], 'string')
-            assert.strictEqual(typeof tokens[5], 'string')
-            assert.strictEqual(tokens[1].key, 'a')
-            assert.strictEqual(tokens[3].key, 'bcd')
-            assert.strictEqual(tokens[4].key, 'd.e.f')
-            assert.strictEqual(tokens[6].key, 'a + (b || c) ? d : e')
-        })
-
-        after(function () {
-            config.interpolateTags = {
-                open: '{{',
-                close: '}}'
-            }
-            TextParser.buildRegex()
-        })
-
-    })
-
 })