فهرست منبع

sourceURLs for dev, reverse value

Evan You 13 سال پیش
والد
کامیت
f6d6bba70d
5فایلهای تغییر یافته به همراه36 افزوده شده و 9 حذف شده
  1. 16 1
      Gruntfile.js
  2. 2 1
      package.json
  3. 8 0
      src/directive-parser.js
  4. 4 0
      src/filters.js
  5. 6 7
      src/seed.js

+ 16 - 1
Gruntfile.js

@@ -6,6 +6,8 @@ module.exports = function( grunt ) {
             build: {
                 output: './dist/',
                 name: 'seed',
+                dev: true,
+                sourceUrls: true,
                 styles: false,
                 scripts: true,
                 verbose: true
@@ -31,6 +33,18 @@ module.exports = function( grunt ) {
             }
         },
 
+        uglify: {
+            build: {
+                options: {
+                    compress: true,
+                    mangle: true
+                },
+                files: {
+                    'dist/seed.min.js': 'dist/seed.js'
+                }
+            }
+        },
+
         watch: {
             options: {
                 livereload: true
@@ -45,9 +59,10 @@ module.exports = function( grunt ) {
 
     grunt.loadNpmTasks( 'grunt-contrib-watch' )
     grunt.loadNpmTasks( 'grunt-contrib-jshint' )
+    grunt.loadNpmTasks( 'grunt-contrib-uglify' )
     grunt.loadNpmTasks( 'grunt-component-build' )
     grunt.loadNpmTasks( 'grunt-mocha' )
     grunt.registerTask( 'test', ['mocha'] )
-    grunt.registerTask( 'default', ['jshint', 'component_build', 'mocha'] )
+    grunt.registerTask( 'default', ['jshint', 'component_build', 'uglify'] )
     
 }

+ 2 - 1
package.json

@@ -7,6 +7,7 @@
     "grunt-component-build": "~0.3.0",
     "grunt-contrib-jshint": "~0.6.0",
     "grunt-mocha": "~0.4.0",
-    "chai": "~1.7.2"
+    "chai": "~1.7.2",
+    "grunt-contrib-uglify": "~0.2.2"
   }
 }

+ 8 - 0
src/directive-parser.js

@@ -7,6 +7,7 @@ var KEY_RE          = /^[^\|<]+/,
     FILTERS_RE      = /\|[^\|<]+/g,
     FILTER_TOKEN_RE = /[^\s']+|'[^']+'/g,
     DEPS_RE         = /<[^<\|]+/g,
+    INVERSE_RE      = /^!/
     NESTING_RE      = /^\^+/
 
 // parse a key, extract argument and nesting/root info
@@ -23,6 +24,11 @@ function parseKey (rawKey) {
         ? argMatch[1].trim()
         : null
 
+    res.inverse = INVERSE_RE.test(res.key)
+    if (res.inverse) {
+        res.key = res.key.slice(1)
+    }
+
     var nesting = res.key.match(NESTING_RE)
     res.nesting = nesting
         ? nesting[0].length
@@ -96,6 +102,7 @@ function Directive (directiveName, expression) {
 Directive.prototype.refresh = function () {
     if (this.value) {
         var value = this.value.call(this.seed.scope)
+        if (this.inverse) value = !value
         this._update(
             this.filters
             ? this.applyFilters(value)
@@ -115,6 +122,7 @@ Directive.prototype.update = function (value) {
     if (typeof value === 'function' && !this.fn) {
         value = value()
     }
+    if (this.inverse) value = !value
     this._update(
         this.filters
         ? this.applyFilters(value)

+ 4 - 0
src/filters.js

@@ -19,6 +19,10 @@ module.exports = {
         return value.toString().toUpperCase()
     },
 
+    lowercase: function (value) {
+        return value.toString().toLowerCase()
+    },
+
     currency: function (value, args) {
         if (!value) return value
         var sign = (args && args[0]) || '$',

+ 6 - 7
src/seed.js

@@ -83,13 +83,12 @@ Seed.prototype._compileNode = function (node, root) {
 
         } else if (ctrlExp && !root) { // nested controllers
 
-            var id = node.id,
-                seed = new Seed(node, {
-                    child: true,
-                    parentSeed: seed
-                })
-            if (id) {
-                seed['$' + id] = seed
+            var child = new Seed(node, {
+                child: true,
+                parentSeed: seed
+            })
+            if (node.id) {
+                seed['$' + node.id] = child
             }
 
         } else { // normal node