Splits out models and views from graph.co
authordsc <dsc@less.ly>
Mon, 27 Feb 2012 17:18:31 +0000 (09:18 -0800)
committerdsc <dsc@less.ly>
Mon, 27 Feb 2012 17:18:31 +0000 (09:18 -0800)
lib/graph/index.co [new file with mode: 0644]
lib/graph/model.co [new file with mode: 0644]
lib/graph/view.co [moved from lib/graph.co with 70% similarity]
lib/main.co
www/modules.yaml

diff --git a/lib/graph/index.co b/lib/graph/index.co
new file mode 100644 (file)
index 0000000..881b673
--- /dev/null
@@ -0,0 +1,3 @@
+models = require 'kraken/graph/model'
+views  = require 'kraken/graph/view'
+exports import models import views
diff --git a/lib/graph/model.co b/lib/graph/model.co
new file mode 100644 (file)
index 0000000..125fc4d
--- /dev/null
@@ -0,0 +1,107 @@
+_ = require 'kraken/underscore'
+{ Field, FieldList, BaseView, FieldView, Scaffold
+} = 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 ...
+        
+        # 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 ...
+        for k, v in o
+            o[k] = '' if v!?
+        o
+    
+# }}}
+
+
+GraphOptionList = exports.GraphOptionList = FieldList.extend do # {{{
+    ctorName   : 'GraphOptionList'
+    model      : GraphOption
+    categories : {}
+    
+    
+    initialize : ->
+        FieldList::initialize ...
+        @categories  = {}
+    
+    
+# }}}
+
+
similarity index 70%
rename from lib/graph.co
rename to lib/graph/view.co
index e393110..31653f2 100644 (file)
 _ = require 'kraken/underscore'
 { Field, FieldList, BaseView, FieldView, Scaffold
 } = require 'kraken/scaffold'
+{   GraphOption, GraphOptionList, TagSet,
+} = require 'kraken/graph/model'
 
 
 
-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 ...
-        
-        # 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 ...
-        for k, v in o
-            o[k] = '' if v!?
-        o
-    
-# }}}
-
-
-GraphOptionList = exports.GraphOptionList = FieldList.extend do # {{{
-    ctorName   : 'GraphOptionList'
-    model      : GraphOption
-    categories : {}
-    
-    
-    initialize : ->
-        FieldList::initialize ...
-        @categories  = {}
-    
-    
-# }}}
-
-
 /**
  * The view for a single configurable option.
  */
index ce96a23..7d6f33b 100644 (file)
@@ -1,7 +1,7 @@
 {_, op} = require 'kraken/util'
 {   Field, FieldList, BaseView, FieldView, Scaffold
 }       = require 'kraken/scaffold'
-{   GraphView, GraphModel,
+{   GraphView, GraphModel, TagSet,
     GraphOption, GraphOptionList, GraphOptionView,
     GraphOptionsScaffold,
 }       = require 'kraken/graph'
index 8de244f..1e0b1b7 100644 (file)
@@ -42,7 +42,11 @@ all:
                 - model
                 - view
                 - index
-            - graph
+            - graph:
+                - model
+                - view
+                - index
+            
 
 # -   suffix: .js
 #     paths: