 module.exports = class Slugifiable
 
-  {dash} = require 'bongo'
+  {dash, daisy} = require 'bongo'
 
   slugify =(str)->
     slug = str

  @updateAllSlugs = (options, callback)->
    [callback, options] = [options, callback] unless callback
    options ?= {}
    selector = if options.force then {} else {slug: $exists: no}
    subclasses = @encapsulatedSubclasses ? [@]
    contentTypeQueue = subclasses.map (subclass)->->
      subclass.cursor selector, options, (err, cursor)->
        if err then contentTypeQueue.fin err
        else
          postQueue = []
          cursor.each (err, post)->
            if err then postQueue.fin err
            else if post?
              postQueue.push -> post.updateSlug (err, slug)->
                callback null, slug
                postQueue.fin()
            else
              dash postQueue, -> contentTypeQueue.fin()
    dash contentTypeQueue, callback

  updateSlug:(callback)->
    @createSlug (err, slug)=>
      if err then callback err
      else @update $set:{slug}, (err)->
        callback err, unless err then slug

  createSlug:(callback)-> 

      .replace(/[^a-z0-9-]+/g, "")  # remove all non-alphanumeric characters except the hyphen
      .replace(/[-]+/g, "-")        # replace multiple instances of the hyphen with a single instance
      .replace(/^-+|-+$/g, "")      # trim leading and trailing hyphens
      .substr 0, 256                # limit these to 256-chars (pre-suffix), for sanity

  generateUniqueSlug =(constructor, slug, i, callback)->
    candidate = "#{slug}#{i or ''}"
