From ca2873824d3fab222fc0d5d8b27b15ac0ed26f4a Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Wed, 28 Nov 2012 11:48:34 +1100 Subject: [PATCH] v6.13.3. Bugfix. Improvement. - v6.13.3 November 28, 2012 - Reduced the extension not rendering warning to a notice - Fixed the `include` template helper - `DocPad::getFileAtPath` now does fuzzy finding - `FilesCollection::fuzzyFindOne` now also fuzzy matches against the url and accepts `sorting` and `paging` arguments --- History.md | 6 ++++++ package.json | 2 +- src/lib/collections/files.coffee | 34 ++++++++++++++++++-------------- src/lib/docpad.coffee | 5 ++--- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/History.md b/History.md index 6d1a803d..fd29fff9 100755 --- a/History.md +++ b/History.md @@ -1,5 +1,11 @@ ## History +- v6.13.3 November 28, 2012 + - Reduced the extension not rendering warning to a notice + - Fixed the `include` template helper + - `DocPad::getFileAtPath` now does fuzzy finding + - `FilesCollection::fuzzyFindOne` now also fuzzy matches against the url and accepts `sorting` and `paging` arguments + - v6.13.2 November 27, 2012 - Reduced the extension not rendering error to a warning diff --git a/package.json b/package.json index ae4bbaa2..8f63a4e7 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docpad", - "version": "6.13.2", + "version": "6.13.3", "description": "DocPad is a language agnostic document management system. This means you write your website as documents, in whatever language you wish, and DocPad will handle the compiling, templates and layouts for you. For static documents it will generate static files, for dynamic documents it'll re-render them on each request. You can utilise DocPad by itself, or use it as a module your own custom system. It's pretty cool, and well worth checking out. We love it.", "homepage": "https://github.com/bevry/docpad", "installUrl": "http://docpad.org/install", diff --git a/src/lib/collections/files.coffee b/src/lib/collections/files.coffee index 4fca0d37..d200a18b 100644 --- a/src/lib/collections/files.coffee +++ b/src/lib/collections/files.coffee @@ -17,21 +17,25 @@ class FilesCollection extends QueryCollection # Fuzzy Find One # Useful for layout searching - fuzzyFindOne: (data) -> - file = @findOne(id: data) - return file if file - - file = @findOne(relativePath: data) - return file if file - - file = @findOne(relativeBase: data) - return file if file - - file = @findOne(relativePath: $startsWith: data) - return file if file - - file = @findOne(fullPath: $startsWith: data) - return file + fuzzyFindOne: (data,sorting,paging) -> + # Prepare + queries = [ + {id: data} + {relativePath: data} + {relativeBase: data} + {url: data} + {relativePath: $startsWith: data} + {fullPath: $startsWith: data} + {url: $startsWith: data} + ] + + # Try the queries + for query in queries + file = @findOne(query,sorting,paging) + return file if file + + # Didn't find a file + return null # Export module.exports = FilesCollection diff --git a/src/lib/docpad.coffee b/src/lib/docpad.coffee index 1355ac7b..74ef8d61 100755 --- a/src/lib/docpad.coffee +++ b/src/lib/docpad.coffee @@ -300,8 +300,7 @@ class DocPad extends EventEmitterEnhanced # Get another file's model based on a relative path getFileAtPath: (path,sorting,paging) -> - query = $or: [{relativePath: path}, {fullPath: path}] - result = @getDatabase().findOne(query,sorting,paging) + result = @getDatabase().fuzzyFindOne(path,sorting,paging) return result @@ -397,6 +396,7 @@ class DocPad extends EventEmitterEnhanced # Prepare userTemplateData or= {} docpad = @ + locale = @getLocale() # Set the initial docpad template data @initialTemplateData ?= @@ -474,7 +474,6 @@ class DocPad extends EventEmitterEnhanced if result return result.get('contentRendered') or result.get('content') else - locale = @getLocale() err = new Error(util.format(locale.includeFailed, subRelativePath)) throw err