Moves Tag crap to graph
authordsc <dsc@less.ly>
Sun, 26 Feb 2012 11:25:35 +0000 (03:25 -0800)
committerdsc <dsc@less.ly>
Sun, 26 Feb 2012 11:25:35 +0000 (03:25 -0800)
lib/graph.co
lib/scaffold/model.co

index 5f24b30..e393110 100644 (file)
@@ -3,14 +3,84 @@ _ = require 'kraken/underscore'
 } = require 'kraken/scaffold'
 
 
+
+class exports.TagSet extends Array
+    tags : {}
+    
+    (values=[]) ->
+        @tags = {}
+        @add values if values?.length
+    
+    has: (tag) ->
+        @tags[tag]?
+    
+    get: (tag) ->
+        return -1 unless tag
+        unless @tags[tag]?
+            @tags[tag] = @length
+            @push tag
+        @tags[tag]
+    
+    update: (tags) ->
+        is_single = typeof tags is 'string'
+        tags      = [tags] if is_single
+        indices   = ( for tag of tags then @get tag )
+        if is_single then indices[0] else indices
+    
+    toString: -> "Tags(length=#{@length}, values=[\"#{@join '", "'}\"])"
+
+
+KNOWN_TAGS = exports.KNOWN_TAGS = new TagSet()
+
+
 /**
  * Field with graph-option-specific handling for validation, parsing, tags, etc.
  */
 GraphOption = exports.GraphOption = Field.extend do # {{{
     ctorName : 'GraphOption'
-    # initialize : ->
-    #     # console.log "#this.initialize!"
-    #     Field::initialize ...
+    
+    initialize : ->
+        # console.log "#this.initialize!"
+        Field::initialize ...
+        
+        # Notify Tag indexer of category when created, to ensure all category-tags
+        # get indices with colors :P
+        KNOWN_TAGS.update @getCategory()
+    
+    
+    # Wrapper to ensure @set('tags') is called, as tags.push()
+    # will not trigger the 'changed:tags' event.
+    addTag: (tag) ->
+        return this unless tag
+        tags = @get('tags', [])
+        tags.push tag
+        @set 'tags', tags
+        this
+    
+    # Wrapper to ensure @set('tags') is called, as tags.push()
+    # will not trigger the 'changed:tags' event.
+    removeTag: (tag) ->
+        return this unless tag
+        tags = @get('tags', [])
+        _.remove tags, tag
+        @set 'tags', tags
+        this
+    
+    # Keep tag list up to date
+    onTagUpdate: ->
+        KNOWN_TAGS.update @get 'tags'
+        this
+    
+    getTagIndex: (tag) ->
+        KNOWN_TAGS.get tag
+    
+    # A field's category is its first tag.
+    getCategory: ->
+        @get('tags', [])[0]
+    
+    getCategoryIndex: ->
+        @getTagIndex @getCategory()
+    
     
     toJSON: ->
         o = Field::toJSON ...
index c9a08d1..412acfd 100644 (file)
@@ -6,34 +6,6 @@ Hash = require 'hashish'
 
 ### Scaffold Models
 
-class exports.TagSet extends Array
-    tags : {}
-    
-    (values=[]) ->
-        @tags = {}
-        @add values if values?.length
-    
-    has: (tag) ->
-        @tags[tag]?
-    
-    get: (tag) ->
-        return -1 unless tag
-        unless @tags[tag]?
-            @tags[tag] = @length
-            @push tag
-        @tags[tag]
-    
-    update: (tags) ->
-        is_single = typeof tags is 'string'
-        tags      = [tags] if is_single
-        indices   = ( for tag of tags then @get tag )
-        if is_single then indices[0] else indices
-    
-    toString: -> "Tags(length=#{@length}, values=[\"#{@join '", "'}\"])"
-
-
-KNOWN_TAGS = exports.KNOWN_TAGS = new TagSet()
-
 Field = exports.Field = Backbone.Model.extend do # {{{
     ctorName    : 'Field'
     idAttribute : 'name'
@@ -41,13 +13,8 @@ Field = exports.Field = Backbone.Model.extend do # {{{
     
     initialize: ->
         @set 'value', @get('default'), {+silent} if not @has 'value'
-        
         # console.log "#this.initialize!"
         @on 'all', (evt) ~> console.log "#this.trigger(#evt)"
-        
-        # Notify Tag indexer of category when created, to ensure all category-tags
-        # get indices with colors :P
-        KNOWN_TAGS.update @getCategory()
     
     # Model defaults
     defaults: ->
@@ -61,39 +28,6 @@ Field = exports.Field = Backbone.Model.extend do # {{{
             examples : []
         }
     
-    # Wrapper to ensure @set('tags') is called, as tags.push()
-    # will not trigger the 'changed:tags' event.
-    addTag: (tag) ->
-        return this unless tag
-        tags = @get('tags', [])
-        tags.push tag
-        @set 'tags', tags
-        this
-    
-    # Wrapper to ensure @set('tags') is called, as tags.push()
-    # will not trigger the 'changed:tags' event.
-    removeTag: (tag) ->
-        return this unless tag
-        tags = @get('tags', [])
-        _.remove tags, tag
-        @set 'tags', tags
-        this
-    
-    # Keep tag list up to date
-    onTagUpdate: ->
-        KNOWN_TAGS.update @get 'tags'
-        this
-    
-    getTagIndex: (tag) ->
-        KNOWN_TAGS.get tag
-    
-    # A field's category is its first tag.
-    getCategory: ->
-        @get('tags', [])[0]
-    
-    getCategoryIndex: ->
-        @getTagIndex @getCategory()
-    
     
     
     getParser: (type) ->