From: dsc Date: Wed, 7 Mar 2012 18:59:05 +0000 (-0800) Subject: Supports slug parsing and slug URLs. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=951a48762eec33c8d63f58fa6e35ccb92649083b;p=limn.git Supports slug parsing and slug URLs. --- diff --git a/lib/main.co b/lib/main.co index 70da9c1..1cf6af4 100644 --- a/lib/main.co +++ b/lib/main.co @@ -33,22 +33,18 @@ main = -> console.log 'StateChange!\n\n', String(root.location), '\n\n' - # If we got querystring args, apply them to the graph data = {} - if String(root.location).split '?' .1 + + # Process URL + loc = String root.location + + # If we got querystring args, apply them to the graph + if loc.split '?' .1 data = _.uncollapseObject _.fromKV that.replace('#', '%23') - - # # yarr, have to do options separately or everything goes to shit - # options = delete data.options - # graph.model.set data, {+silent} - # graph.chartOptions options, {+silent} - # # Flush all changes once the DOM settles - # _.delay do - # -> - # graph.change() - # # graph.scaffold.invoke 'change' - # 50 + # Extract slug from URL + if match = /\/graph\/(?!view)([^\/?]+)/i.exec loc + data.slug = match[1] vis = root.vis = new VisModel data graph = root.graph = new VisView do diff --git a/lib/server/server.co b/lib/server/server.co index b4cf71c..44c8d93 100755 --- a/lib/server/server.co +++ b/lib/server/server.co @@ -132,7 +132,7 @@ app.get '/graph/:slug/?', (req, res, next) -> # console.log ' slug: ', slug # console.log ' params:', req.params unless _.str.include slug, '.' - {pathname, search} = req.info + {pathname, search or ''} = req.info req.url = "#pathname/view#search" req.params.action = 'view' next() diff --git a/lib/vis/vis-model.co b/lib/vis/vis-model.co index c534e1d..380bfc0 100644 --- a/lib/vis/vis-model.co +++ b/lib/vis/vis-model.co @@ -89,8 +89,9 @@ VisModel = exports.VisModel = BaseModel.extend do # {{{ json - toKVPairs: -> + toKVPairs: (keepSlug=false) -> kvo = @toJSON() + delete kvo.slug unless keepSlug # console.group 'toKVPairs' # console.log '[IN]', JSON.stringify kvo opts = kvo.options = _.clone kvo.options @@ -105,6 +106,17 @@ VisModel = exports.VisModel = BaseModel.extend do # {{{ # console.groupEnd() _.collapseObject kvo + toKV: (keepSlug=false) -> + _.toKV @toKVPairs keepSlug + + + /** + * @returns {String} URL identifying this model. + */ + toURL: -> + slug = @get 'slug', '' + slug = "/#slug" if slug + "/graph#slug?#{@toKV(false)}" toString: -> "#{@ctorName}(id=#{@id})" diff --git a/lib/vis/vis-view.co b/lib/vis/vis-view.co index 6b13eba..8e3e86c 100644 --- a/lib/vis/vis-view.co +++ b/lib/vis/vis-view.co @@ -68,7 +68,7 @@ VisView = exports.VisView = BaseView.extend do # {{{ @scaffold.collection.reset that if o.graph_spec @scaffold.on 'change', (scaffold, value, key, field) ~> - console.log "scaffold.change!", key, value, field + # console.log "scaffold.change!", key, value @model.setOption key, value, {+silent} #unless field.isDefault() options = @model.get 'options', {}