Skip to content

Commit

Permalink
v2.1.2. Improvement.
Browse files Browse the repository at this point in the history
- v2.1.2 December 5, 2012
	- Better error reporting
	- We now parse less files with the `filename` option set to the file's
`fullPath` (before we didn't send this at all)
	- Added `parseOptions` and `compileOptions` to configuration
  • Loading branch information
balupton committed Dec 5, 2012
1 parent 3561c92 commit 772b462
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log

test/out/
test/render-out/
out/
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## History

- v2.1.2 December 5, 2012
- Better error reporting
- We now parse less files with the `filename` option set to the file's `fullPath` (before we didn't send this at all)
- Added `parseOptions` and `compileOptions` to configuration

- v2.1.1 August 10, 2012
- Re-added markdown files to npm distribution as they are required for the npm website

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "docpad-plugin-less",
"version": "2.1.1",
"version": "2.1.2",
"description": "Adds support for the LESS CSS pre-processor to DocPad",
"homepage": "http://docpad.org/plugin/less",
"keywords": [
"docpad",
"docpad-plugin",
"less",
"less.js",
"lesscss",
"css",
"styles",
Expand Down Expand Up @@ -34,7 +35,7 @@
"less": "1.3.x"
},
"devDependencies": {
"coffee-script": "1.3.x"
"coffee-script": "1.4.x"
},
"main": "./out/less.plugin.js",
"scripts": {
Expand Down
34 changes: 27 additions & 7 deletions src/less.plugin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ module.exports = (BasePlugin) ->
# Plugin config
config:
compress: true
parseOptions: null
compileOptions: null
environments:
development:
compress: false

# Render some content
render: (opts,next) ->
# Prepare
config = @config
{inExtension,outExtension,templateData,file} = opts

# Check extensions
Expand All @@ -26,15 +29,32 @@ module.exports = (BasePlugin) ->
# Prepare
srcPath = file.get('fullPath')
dirPath = path.dirname(srcPath)
options =
parseOptions =
paths: [dirPath]
compress: @config.compress
filename: file.get('fullPath')

# Compile
new (less.Parser)(options).parse opts.content, (err, tree) ->
return next err if err
opts.content = tree.toCSS(compress: options.compress)
next()
# Extend Parser Options
parseOptions[key] = value for own key,value of config.parseOptions if config.parseOptions

# Parse
new (less.Parser)(parseOptions).parse opts.content, (err,tree) ->
# Check
if err
err = new Error(less.formatError(err,parseOptions))
return next(err)

# Prepare
compileOptions =
compress: config.compress

# Extend Compile Options
compileOptions[key] = value for own key,value of config.compileOptions if config.compileOptions

# Compile
opts.content = tree.toCSS(compileOptions)

# Done
return next()

# Some other extension
else
Expand Down

0 comments on commit 772b462

Please sign in to comment.