Skip to content

Commit

Permalink
Added stylesheet collection that sets referencesOthers to true. Renam…
Browse files Browse the repository at this point in the history
…ed rendered properties to out properties and moved them to the File model
  • Loading branch information
balupton committed Aug 9, 2012
1 parent 3840937 commit 4412d51
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 40 deletions.
9 changes: 6 additions & 3 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
## History

- v6.5.0 August 3, 2012
- v6.5.0 Unreleased, 2012
- Can now specify a custom configuration file vis the command line using `-c, --config <configPath>`
- Can now specify a custom outPath via the command line using `-o, --out <outPath>`
- Can now set template data via `req.templateData`
- Fixed `Document::writeSource`
- The `serverExtend` event will now also emit the `express` dependency if used
- When using the `docpad-server` executable, you can now customise the action via the `DOCPAD_SERVER_ACTION` environment variable
- No longer attempts to install plugins dependencies every time, this is outside the scope of DocPad and in the standard use cases already handled via npm
- No longer accepts `npmPath`, `gitPath`, and `nodePath` as configuration options, instead these should be environment variables at `NPM_PATH`, `GIT_PATH`, and `NODE_PATH` respectively (without the underscore is also acceptable)
- Fixed `require('docpad').createInstance` (was accidentally dropped in v6.2.0)
- Removed markdown files from `.npmignore` as they are now required for the new npm website listing
- Added new `stylesheet` collection that contains any stylesheet file (including pre-processors) and sets their `referenceOthers` property to `true`
- Possible breaking changes:
- Can now set template data via `req.templateData`
- No longer accepts `npmPath`, `gitPath`, and `nodePath` as configuration options, instead these should be environment variables at `NPM_PATH`, `GIT_PATH`, and `NODE_PATH` respectively (without the underscore is also acceptable)
- Renamed `extensionRendered` to `outExtension`, `filenameRendered` to `outFilename`, and `contentTypeRendered` to `outContentType` and moved them from the Document model to the File model

- v6.4.1 July 19, 2012
- Added new `source` attribute to the file model, as the `content` attribute on the document model is actually the `body` not the original content like it is in the file model
Expand Down
19 changes: 18 additions & 1 deletion src/lib/docpad.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1026,17 +1026,34 @@ class DocPad extends EventEmitterEnhanced
$or:
isDocument: true
isFile: true
outPath: $endsWith: '.html'
outExtension: 'html'
})
.on('add', (model) ->
docpad.log('debug', "Adding html file: #{model.attributes.fullPath}")
)
stylesheetCollection = database.createLiveChildCollection()
.setQuery('isStylesheet', {
$or:
isDocument: true
isFile: true
outExtension: $in: [
'css',
'scss', 'sass',
'styl', 'stylus'
'less'
]
})
.on('add', (model) ->
docpad.log('debug', "Adding stylesheet file: #{model.attributes.fullPath}")
model.attributescd .referencesOthers = true
)

# Apply collections
@setCollection('documents', documentsCollection)
@setCollection('files', filesCollection)
@setCollection('layouts', layoutsCollection)
@setCollection('html', htmlCollection)
@setCollection('stylesheets', stylesheetCollection)

# Blocks
metaBlock = new MetaCollection()
Expand Down
47 changes: 21 additions & 26 deletions src/lib/models/document.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,13 @@ class DocumentModel extends FileModel
defaults:

# ---------------------------------
# Automaticly set variables
# Special variables

# The final extension used for our rendered file
# outExtension
# The final extension used for our file
# Takes into accounts layouts
# "layout.html", "post.md.eco" -> "html"
extensionRendered: null

# The file's name with the rendered extension
filenameRendered: null

# The MIME content-type for the out document
contentTypeRendered: null
# already defined in file.coffee

# Whether or not we reference other doucments
referencesOthers: false
Expand Down Expand Up @@ -284,10 +279,10 @@ class DocumentModel extends FileModel
# Extract
extensions = @get('extensions')

# Extension REndered
# Extension Rendered
if extensions? and extensions.length
extensionRendered = extensions[0]
@set({extensionRendered})
outExtension = extensions[0]
@set({outExtension})

# Next
next()
Expand Down Expand Up @@ -318,36 +313,36 @@ class DocumentModel extends FileModel
basename = @get('basename')
relativeDirPath = @get('relativeDirPath')
extensions = @get('extensions')
extensionRendered = @get('extensionRendered')
outExtension = @get('outExtension')
url = meta.get('url')
name = meta.get('name')
outPath = meta.get('outPath')
filenameRendered = null
outFilename = null

# Use our eve's rendered extension if it exists
if eve?
extensionRendered = eve.get('extensionRendered')
outExtension = eve.get('outExtension')

# Figure out the rendered filename
if basename and extensionRendered
if basename[0] is '.' and extensionRendered is extensions[0]
filenameRendered = basename
if basename and outExtension
if basename[0] is '.' and outExtension is extensions[0]
outFilename = basename
else
filenameRendered = "#{basename}.#{extensionRendered}"
changes.filenameRendered = filenameRendered
outFilename = "#{basename}.#{outExtension}"
changes.outFilename = outFilename

# Figure out the rendered url
if filenameRendered
if outFilename
if relativeDirPath
relativeOutPath = "#{relativeDirPath}/#{filenameRendered}"
relativeOutPath = "#{relativeDirPath}/#{outFilename}"
else
relativeOutPath = "#{filenameRendered}"
relativeOutPath = "#{outFilename}"
changes.relativeOutPath = relativeOutPath
changes.url = url = "/#{relativeOutPath}" unless url

# Set name if it doesn't exist already
if !name and filenameRendered?
changes.name = name = filenameRendered
if !name and outFilename?
changes.name = name = outFilename

# Create the outPath if we have a outpute directory
if @outDirPath
Expand All @@ -360,7 +355,7 @@ class DocumentModel extends FileModel

# Content Types
if outPath or fullPath
changes.contentTypeRendered = contentTypeRendered = mime.lookup(outPath or fullPath)
changes.outContentType = outContentType = mime.lookup(outPath or fullPath)

# Apply
@set(changes)
Expand Down
39 changes: 29 additions & 10 deletions src/lib/models/file.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class FileModel extends Model
# "hello.md.eco" -> "eco"
extension: null

# The extension used for our output file
outExtension: null

# The file's extensions as an array
# "hello.md.eco" -> ["md","eco"]
extensions: null # Array
Expand All @@ -55,35 +58,43 @@ class FileModel extends Model
filename: null

# The full path of our source file, only necessary if called by @load
fullPath: null

# The full directory path of our source file
fullDirPath: null
# @TODO: rename to `path` in next major breaking version
path: null

# The output path of our file
outPath: null

# The full directory path of our source file
# @TODO: rename to `dirPath` in next major breaking version
dirPath: null

# The output path of our file's directory
outDirPath: null

# The relative output path of our file
relativeOutPath: null

# The relative output path of our file's directory
relativeOutDirPath: null
# The file's name with the rendered extension
outFilename: null

# The relative path of our source file (with extensions)
relativePath: null

# The relative output path of our file
relativeOutPath: null

# The relative directory path of our source file
relativeDirPath: null

# The relative output path of our file's directory
relativeOutDirPath: null

# The relative base of our source file (no extension)
relativeBase: null

# The MIME content-type for the source document
# The MIME content-type for the source file
contentType: null

# The MIME content-type for the out file
outContentType: null

# The date object for when this document was created
ctime: null

Expand All @@ -108,8 +119,13 @@ class FileModel extends Model
# User set variables

# The title for this document
# Useful for page headings
title: null

# The name for this document, defaults to the filename
# Useful for navigation listings
name: null

# The date object for this document, defaults to mtime
date: null

Expand Down Expand Up @@ -402,6 +418,7 @@ class FileModel extends Model
# Filename
if fullPath
changes.filename = filename = pathUtil.basename(fullPath)
changes.outFilename = filename

# Basename, extensions, extension
if filename
Expand All @@ -423,11 +440,13 @@ class FileModel extends Model
else
extension = null
changes.extension = extension
changes.outExtension = extension

# fullDirPath, contentType
if fullPath
changes.fullDirPath = fullDirPath = pathUtil.dirname(fullPath) or ''
changes.contentType = contentType = mime.lookup(fullPath)
changes.outContentType = contentType

# relativeDirPath, relativeBase
if relativePath
Expand Down

0 comments on commit 4412d51

Please sign in to comment.