Permalink
Browse files

Cleaned up the Meta Data handling

- Removed useless `Document::initialize` and `Document::getMeta`
- Updated `File::getMeta` to create meta if it doesn't exist yet
- Added `Base::setDefaults`, `File::setMeta`, and
`File::setMetaDefaults`
  • Loading branch information...
balupton committed Dec 4, 2012
1 parent 22a7512 commit 8eb8fdc4ef929325e21b3479398c9a0a94662898
Showing with 20 additions and 15 deletions.
  1. +6 −0 src/lib/base.coffee
  2. +0 −12 src/lib/models/document.coffee
  3. +14 −3 src/lib/models/file.coffee
View
@@ -22,6 +22,12 @@ _.extend(Events::, Backbone.Events)
class Model extends Backbone.Model
log: log
emit: emit
setDefaults: (defaults) ->
set = {}
for own key,value of defaults
set[key] = value if @get('key') is @defaults?[key]
@set(set)
return @
# Collection
class Collection extends Backbone.Collection
@@ -77,18 +77,6 @@ class DocumentModel extends FileModel
# ---------------------------------
# Functions
# Initialize
initialize: (attrs,opts) ->
# Prepare
{@layouts,meta} = opts
# Forward
super
# Get Meta
getMeta: ->
return @meta
# To JSON
toJSON: ->
data = super
View
@@ -176,10 +176,8 @@ class FileModel extends Model
@set(defaults)
# Meta
@meta = new Model()
if meta
@meta.set(meta)
@set(meta)
@setMeta(meta)
# Super
super
@@ -208,8 +206,21 @@ class FileModel extends Model
# Get Meta
getMeta: ->
@meta = new Model() if @meta is null
return @meta
# Set Meta
setMeta: (attrs) ->
@getMeta().set(attrs)
@set(attrs)
return @
# Set Meta Defaults
setMetaDefaults: (defaults) ->
@getMeta().setDefaults(defaults)
@setDefaults(defaults)
return @
# Is Text?
isText: ->
return @get('encoding') isnt 'binary'

0 comments on commit 8eb8fdc

Please sign in to comment.